list.vue
6.02 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
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
<div>
<BasicTable @register="registerTable" :row-selection="rowSelection">
<template #content="{ record }">
<a-button type="link" class="ml-2" @click="handleRecordContent(record)"> 查看 </a-button>
</template>
<template #toolbar>
<a-button type="primary" @click="handleCreateOrEdit(null)"> 新增公共接口 </a-button>
<Popconfirm
title="您确定要批量删除数据"
ok-text="确定"
cancel-text="取消"
@confirm="handleDeleteOrBatchDelete(null)"
>
<a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
</Popconfirm>
<Popconfirm
title="您确定要批量发布"
ok-text="确定"
cancel-text="取消"
@confirm="handleBatchPublish('batchPublish')"
>
<a-button color="error" :disabled="hasBatchPublish"> 批量发布 </a-button>
</Popconfirm>
<!-- <Popconfirm
title="您确定要批量取消发布"
ok-text="确定"
cancel-text="取消"
@confirm="handleBatchPublish('cancelBatchPublish')"
>
<a-button color="error" :disabled="hasBatchPublish"> 批量取消发布 </a-button>
</Popconfirm> -->
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '发布',
icon: 'ant-design:node-expand-outlined',
onClick: handlePublish.bind(null, 'publish', record),
ifShow: () => {
return record.state === 0;
},
},
{
label: '取消发布',
icon: 'ant-design:node-collapse-outlined',
onClick: handlePublish.bind(null, 'canelPublish', record),
ifShow: () => {
return record.state === 1;
},
},
{
label: '修改',
icon: 'clarity:note-edit-line',
onClick: handleCreateOrEdit.bind(null, record),
ifShow: () => {
return record.state === 0;
},
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
ifShow: () => {
return record.state === 0;
},
popConfirm: {
title: '是否确认删除',
confirm: handleDeleteOrBatchDelete.bind(null, record),
},
},
]"
/>
</template>
</BasicTable>
</div>
<PublicApiForm @register="registerDrawer" @success="handleSuccess" />
</template>
<script lang="ts" setup name="list">
import { h, ref } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useDrawer } from '/@/components/Drawer';
import { columns, searchFormSchema } from './config';
import { PublicApiForm } from './index';
import {
getDataViewInterfacePage,
deleteBigViewInterface,
getPublish,
getCancelPublish,
putPublishOrCancelPublish,
} from '/@/api/bigscreen/center/bigscreenCenter';
import { Popconfirm, Modal } from 'ant-design-vue';
import { JsonPreview } from '/@/components/CodeEditor';
import { useMessage } from '/@/hooks/web/useMessage';
const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
api: getDataViewInterfacePage,
columns,
showIndexColumn: false,
clickToRowSelect: false,
showTableSetting: true,
bordered: true,
formConfig: {
labelWidth: 120,
schemas: searchFormSchema,
},
useSearchForm: true,
actionColumn: {
width: 150,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
});
const [registerDrawer, { openDrawer }] = useDrawer();
const hasBatchPublish = ref(true);
const hasBatchDelete = ref(true);
const batchDeleteIds = ref([]);
const { createMessage } = useMessage();
const handleSuccess = () => {
reload();
setStatusIsTrue();
clearSelectedRowKeys();
};
const setStatusIsFalse = () => {
(hasBatchDelete.value = false), (hasBatchPublish.value = false);
};
const setStatusIsTrue = () => {
(hasBatchDelete.value = true), (hasBatchPublish.value = true);
};
const rowSelection = {
onChange: (_, selectedRows: any[]) => {
batchDeleteIds.value = selectedRows.map((it) => it.id) as never as any;
if (batchDeleteIds.value.length > 0) setStatusIsFalse();
else setStatusIsTrue();
},
getCheckboxProps: (record) => ({
disabled: record.state === 1,
}),
};
const handleCreateOrEdit = (record) => {
const isUpdate = record === null ? false : true;
const recordContent = record === null ? null : record;
openDrawer(true, {
isUpdate,
record: recordContent,
});
};
const handleRecordContent = (record) => {
Modal.info({
title: '接口内容',
width: 600,
content: h(JsonPreview, { data: JSON.parse(record.requestParams) }),
});
};
const handlePublish = async (type, record) => {
type === 'publish' ? await getPublish(record.id) : await getCancelPublish(record.id);
createMessage.success(`${type === 'publish' ? '发布' : '取消发布'}成功`);
handleSuccess();
};
const handleBatchPublish = async (type) => {
await putPublishOrCancelPublish(type, batchDeleteIds.value);
createMessage.success(`${type === 'batchPublish' ? '批量发布' : '批量取消发布'}成功`);
handleSuccess();
};
const handleDeleteOrBatchDelete = async (record) => {
const ids = record === null ? batchDeleteIds.value : [record.id];
await deleteBigViewInterface(ids);
createMessage.success(`${record === null ? '批量删除' : '删除'}成功`);
handleSuccess();
};
</script>