out-form-content.vue
4.01 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
<script setup lang="ts">
import FilterTable from '@/components/filter/table.vue';
import FilterTableColumn from '@/components/filter/table-column.vue';
import EnumTableColumn from '@/components/filter/enum-table-column.vue';
import { Space, Link, Message, Modal, Form, FormItem, Select } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import { AnyObject } from '@/types/global';
import { computed, createVNode, onMounted, ref } from 'vue';
import useUserApi from '@/api/user';
import { User } from '@/types/user';
import useActivityApi from '@/api/activity';
const props = defineProps<{ projectKey: number; hasPermission: boolean; user: User }>();
const { loading, setLoading } = useLoading(false);
// eslint-disable-next-line import/no-named-as-default-member
const { statusOption, updateManage, deleteManage } = useActivityApi;
const permissionOption = [
{ label: '查看试唱', value: 'view' },
{ label: '查看报价', value: 'price' },
{ label: '回复结果', value: 'audit' },
];
const tableRef = ref();
const onQuery = async (params: AnyObject) => {
setLoading(true);
return useUserApi.manageSongs(props.user.id, { project_id: props.projectKey, ...params }).finally(() => setLoading(false));
};
onMounted(() => tableRef.value?.onPageChange(1));
const label = computed(() => `${props.user.nick_name} 管理歌曲共:${tableRef.value?.getCount()} 首`);
const formatPermission = (permission: any[]) =>
permission
.map((item) => `[${permissionOption.find((option) => option.value === item)?.label}]` || '')
.filter((item) => item.length !== 0)
.join('');
const onUpdate = (record: any) => {
const formValue = ref<string[]>(record?.permission || ['view']);
Modal.open({
title: '修改',
titleAlign: 'center',
content: () =>
createVNode(Form, { layout: 'vertical', model: {} }, () =>
createVNode(FormItem, { label: '设置用户权限', rowClass: 'mb-0' }, () =>
createVNode(Select, {
'multiple': true,
'options': permissionOption,
'modelValue': formValue.value,
'onUpdate:modelValue': (val?: string[]) => {
if (!val?.includes('view')) {
val?.unshift('view');
}
formValue.value = val || [];
},
})
)
),
onBeforeOk: (done) =>
updateManage(record.id, { permission: formValue.value })
.then(() => {
Message.success('更新成功');
tableRef.value?.onFetch();
done(true);
})
.catch(() => done(false)),
});
};
const onDelete = (record: any) => {
Modal.open({
title: '删除操作',
content: `确认取消用户:${props.user?.nick_name} 的外部管理员身份`,
closable: false,
onBeforeOk: (done) =>
deleteManage(record.id)
.then(() => {
Message.success('删除成功');
tableRef.value?.onFetch();
done(true);
})
.catch(() => done(false)),
});
};
</script>
<template>
<div style="margin-bottom: 10px">{{ label }}</div>
<FilterTable ref="tableRef" :loading="loading" :on-query="onQuery">
<FilterTableColumn title="厂牌名称" data-index="project.name" :width="120" />
<FilterTableColumn title="歌曲名称" data-index="activity_name" :width="160" />
<FilterTableColumn title="权限" data-index="permission" :width="240">
<template #default="{ record }">{{ formatPermission(record.permission || []) }}</template>
</FilterTableColumn>
<EnumTableColumn title="状态" data-index="activity_status" :width="100" :option="statusOption" />
<FilterTableColumn v-if="hasPermission" title="操作" :width="120">
<template #default="{ record }">
<Space>
<Link class="link-hover" :hoverable="false" @click="onUpdate(record)">修改</Link>
<Link class="link-hover" :hoverable="false" @click="onDelete(record)">取消管理</Link>
</Space>
</template>
</FilterTableColumn>
</FilterTable>
</template>
<style scoped lang="less"></style>