index.vue
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script setup lang="ts">
import { Input, Link, TableData, Message } from '@arco-design/web-vue';
import { onMounted, ref, computed, createVNode } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { AnyObject } from '@/types/global';
import useLoading from '@/hooks/loading';
import useProjectApi from '@/api/project';
import NumberTableColumn from '@/components/filter/number-table-column.vue';
import UserTableColumn from '@/components/filter/user-table-column.vue';
import SpaceTableColumn from '@/components/filter/space-table-column.vue';
import { createModalVNode } from '@/utils/createVNode';
import { Project } from '@/types/project';
import FormContent from '@/views/project/components/form-content.vue';
const { get, update, getExport } = useProjectApi;
const router = useRouter();
const filter = ref<AnyObject>({});
const tableRef = ref();
const { loading, setLoading } = useLoading(false);
const queryParams = computed(() => {
return {
...filter.value,
setWith: ['master:id,nick_name,identity'],
setWithCount: ['activity_up', 'activity_match', 'activity_send', 'manage', 'member'],
};
});
const onQuery = async (params?: AnyObject) => {
setLoading(true);
return get({ ...queryParams.value, ...params }).finally(() => setLoading(false));
};
const onSearch = () => tableRef.value?.onPageChange(1);
const onReset = () => {
filter.value = { name: '', masterName: '', status: '', isPromote: '', setSort: ['-id'] };
tableRef.value?.resetSort();
onSearch();
};
const onSort = (column: string, type: string) => {
filter.value.setSort = type ? [(type === 'desc' ? '-' : '') + column, '-id'] : ['-id'];
tableRef.value?.onFetch();
};
onMounted(() => onReset());
const onExport = () => getExport('厂牌', queryParams.value);
const onShow = (record: TableData) => router.push({ name: 'project-show', params: { id: record.id } });
const showRoute = computed(() => {
return useRoute().name === 'project-show';
});
const onUpdate = (row: TableData) => {
const formRef = ref();
const formValue = ref({ ...row });
createModalVNode(
() =>
createVNode(FormContent, {
'ref': formRef,
'model-value': formValue.value,
// eslint-disable-next-line no-return-assign
'onUpdate:model-value': (val: any) => (formValue.value = val),
'submit': (value: Omit<Project, 'id'>) => update(row.id, value),
}),
{
title: '厂牌编辑',
titleAlign: 'center',
onBeforeOk: (done) =>
formRef.value
?.onSubmit()
.then(({ name }: Project) => {
tableRef.value.onFetch();
Message.success(`更新厂牌:${name}`);
done(true);
})
.catch(() => done(false)),
}
);
};
</script>
<template>
<router-view v-if="showRoute" :key="$route.path" />
<PageView v-show="!showRoute" has-card has-bread>
<FilterSearch :model="filter" :loading="loading" :split="3" inline @search="onSearch" @reset="onReset">
<FilterSearchItem label="厂牌名称" field="name">
<Input v-model="filter.name" allow-clear placeholder="请输入" />
</FilterSearchItem>
<FilterSearchItem label="主理人" field="masterName">
<Input v-model="filter.masterName" allow-clear placeholder="请输入" />
</FilterSearchItem>
</FilterSearch>
<FilterTable ref="tableRef" :loading="loading" :on-query="onQuery" @row-sort="onSort">
<template #tool-right>
<ExportButton :on-download="onExport" />
</template>
<UserTableColumn title="名称" data-index="id" avatar-index="cover" nick-index="name" :width="260" show-avatar />
<UserTableColumn title="主理人" data-index="master_id" user="master" :width="160" dark-value="" />
<NumberTableColumn title="厂牌管理员人数" data-index="manage_count" :dark-value="0" :width="120" has-sort />
<NumberTableColumn title="厂牌成员人数" data-index="member_count" :dark-value="0" :width="120" has-sort />
<NumberTableColumn title="上架歌曲数" data-index="activity_up_count" :dark-value="0" :width="110" has-sort />
<NumberTableColumn title="已匹配歌曲数" data-index="activity_match_count" :dark-value="0" :width="110" has-sort />
<NumberTableColumn title="已发行歌曲数" data-index="activity_send_count" :dark-value="0" :width="110" has-sort />
<SpaceTableColumn title="操作" data-index="operation" :width="100">
<template #default="{ record }">
<Link class="link-hover" :hoverable="false" @click="onShow(record)">查看</Link>
<Link class="link-hover" :hoverable="false" @click="onUpdate(record)">编辑</Link>
</template>
</SpaceTableColumn>
</FilterTable>
</PageView>
</template>
<style scoped lang="less"></style>