list.vue
4.41 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
<template>
<div>
<BasicTable @register="registerTable">
<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>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '发布',
icon: 'ant-design:node-expand-outlined',
onClick: handlePublish.bind(null, record),
ifShow: () => {
return record.state === 0;
},
},
{
label: '取消发布',
icon: 'ant-design:node-collapse-outlined',
onClick: handleCancelPublish.bind(null, 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 { nextTick, h } 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,
} from '/@/api/bigscreen/center/bigscreenCenter';
import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
import { Popconfirm, Modal } from 'ant-design-vue';
import { JsonPreview } from '/@/components/CodeEditor';
import { useMessage } from '/@/hooks/web/useMessage';
const [registerTable, { reload, setProps }] = 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 { createMessage } = useMessage();
const handleSuccess = () => reload();
const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
deleteBigViewInterface,
handleSuccess,
setProps
);
nextTick(() => {
setProps(selectionOptions);
});
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 (record) => {
await getPublish(record.id);
createMessage.success(`发布成功`);
handleSuccess();
};
const handleCancelPublish = async (record) => {
await getCancelPublish(record.id);
createMessage.success(`取消发布成功`);
handleSuccess();
};
</script>