config-table.vue
6.93 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<filter-table ref="tableRef" :loading="loading" :on-query="onQuery" :hide-page="true">
<template #tool>
<icon-button v-permission="['operation-broker-push-config-create']" type="primary" icon="plus" label="新增" @click="onCreate" />
<div style="color: rgba(44, 44, 44, 0.5); margin-right: 10px">
名单外的经纪人,如果Ta的歌手达成合作,对应到分类:
<span style="color: #1d2129">{{ identifierOptions.find((item) => item.value === defaultIdentifier.content)?.label || '无' }}</span>
</div>
<a-link
v-permission="['operation-broker-push-config-relation']"
:hoverable="false"
style="text-decoration: underline"
@click="onSetting"
>设置关联
</a-link>
</template>
<filter-table-column title="分类" data-index="identifier" :width="80" />
<filter-table-column title="等级通知(标题)" data-index="level_title" :width="160" />
<filter-table-column title="等级通知(内容)" data-index="level_intro" :width="240" />
<filter-table-column title="合作通知(标题)" data-index="match_title" :width="160" />
<filter-table-column title="合作通知(内容)" data-index="match_intro" :width="240" />
<user-table-column title="创建人" data-index="user_id" user="user" show-href :width="140" />
<space-table-column
v-if="
usePermission().checkPermission([
'operation-broker-push-config-show',
'operation-broker-push-config-edit',
'operation-broker-push-config-delete',
])
"
title="操作"
:width="120"
>
<template #default="{ record }">
<a-link v-permission="['operation-broker-push-config-show']" class="link-hover" :hoverable="false" @click="onView(record)">
查看
</a-link>
<a-link v-permission="['operation-broker-push-config-edit']" class="link-hover" :hoverable="false" @click="onUpdate(record)">
编辑
</a-link>
<a-link v-permission="['operation-broker-push-config-delete']" class="link-hover" :hoverable="false" @click="onDelete(record)">
删除
</a-link>
</template>
</space-table-column>
</filter-table>
</template>
<script setup lang="ts">
import { AnyObject } from '@/types/global';
import { createFormVNode, createModalVNode, createSelectionFormItemVNode } from '@/utils/createVNode';
import { computed, createVNode, h, onMounted, ref } from 'vue';
import ConfigForm from '@/views/operation/broker/components/config-form.vue';
import { usePushConfigApi } from '@/http/broker';
import useLoading from '@/hooks/loading';
import UserTableColumn from '@/components/filter/user-table-column.vue';
import SpaceTableColumn from '@/components/filter/space-table-column.vue';
import { TableData } from '@arco-design/web-vue';
import { clone } from 'lodash';
import useConfigApi from '@/http/config';
import { SystemConfig } from '@/types/system-config';
import { promiseToBoolean } from '@/utils';
import usePermission from '@/hooks/permission';
const { get, create, update, destroy } = usePushConfigApi;
const { loading, setLoading } = useLoading(false);
const tableRef = ref();
const defaultIdentifier = ref<Pick<SystemConfig, 'id' | 'content'>>({ id: 0, content: '' });
const onQuery = async (params: AnyObject) => {
setLoading(true);
return get({ ...params, fetchType: 'all', setWith: ['user:id,nick_name,identity'], sortBy: 'id', sortType: 'desc' }).finally(() =>
setLoading(false)
);
};
onMounted(async () => {
tableRef.value?.onPageChange();
defaultIdentifier.value = (await useConfigApi.getOne({ identifier: 'g65owmrgKSUhxV2afndUg', parent_id: 0 })) || { id: 0, content: '' };
});
const identifierOptions = computed(() => {
return [{ value: '', label: '无' }].concat(
tableRef.value?.getList()?.map((item: { id: number; identifier: string }) => {
return { value: item.identifier, label: item.identifier };
})
);
});
const onSetting = () => {
const formValue = ref(clone(defaultIdentifier.value.content));
createModalVNode(
() =>
createFormVNode({ model: formValue, autoLabelWidth: true }, [
createSelectionFormItemVNode(
formValue,
identifierOptions.value,
{ label: '关联分类', style: { marginBottom: '8px' } },
{ fallbackOption: false, placeholder: '请选择' }
),
h(
'div',
{ style: { color: 'rgba(44, 44, 44, 0.5)' } },
'注意:此处设置名单外的经纪人用户,如果Ta的歌手合作后,经纪人是否收到 [合作通知],如需要收到合作通知,根据哪种分类进行推送'
),
]),
{
title: '其他关联设置',
titleAlign: 'center',
onBeforeOk: () => promiseToBoolean(useConfigApi.update(defaultIdentifier.value.id, { content: formValue.value })),
onOk: () => (defaultIdentifier.value.content = formValue.value),
}
);
};
const onView = (record: TableData) => {
createModalVNode(() => h(ConfigForm, { initValue: record, disabled: true }), {
title: '查看',
titleAlign: 'center',
width: '640px',
hideCancel: true,
okText: '我知道了',
});
};
const onCreate = () => {
const formRef = ref<InstanceType<typeof ConfigForm>>();
createModalVNode(() => createVNode(ConfigForm, { ref: formRef, submit: (val: AnyObject) => create(val) }), {
title: '新增',
titleAlign: 'center',
width: '640px',
onBeforeOk: () => promiseToBoolean(formRef.value?.onSubmit()),
onOk: () => tableRef.value?.onFetch(),
});
};
const onUpdate = (record: TableData) => {
const formRef = ref<InstanceType<typeof ConfigForm>>();
createModalVNode(
() => createVNode(ConfigForm, { initValue: record, ref: formRef, submit: (val: AnyObject) => update(record.id, val) }),
{
title: '编辑',
titleAlign: 'center',
width: '640px',
onBeforeOk: () => promiseToBoolean(formRef.value?.onSubmit()),
onOk: () => {
if (defaultIdentifier.value?.content === record.identifier) {
const content = formRef.value?.getIdentifier();
useConfigApi.update(defaultIdentifier.value.id, { content });
defaultIdentifier.value.content = content ?? '';
}
tableRef.value?.onFetch();
},
}
);
};
const onDelete = (record: TableData) =>
createModalVNode(`删除推送模版配置:${record.identifier}`, {
title: '删除操作',
onBeforeOk: () => promiseToBoolean(destroy(record.id)),
onOk: () => {
if (defaultIdentifier.value?.content === record.identifier) {
useConfigApi.update(defaultIdentifier.value.id, { content: '' });
defaultIdentifier.value.content = '';
}
tableRef.value?.onFetch();
},
});
</script>
<style scoped lang="less"></style>