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
<template>
<div class="p-4">
<BasicTable @register="registerTable" :indexColumnProps="indexColumnProps">
<template #tableTitle>
<a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd" style="margin-right: 5px">新增</a-button>
<a-button type="primary" @click="openRecycleModal(true)" preIcon="ant-design:hdd-outlined"> 回收站</a-button>
</template>
<template #status="{ record, text }">
<a-tag color="pink" v-if="text == 0">禁用</a-tag>
<a-tag color="#87d068" v-if="text == 1">正常</a-tag>
</template>
<template #action="{ record }">
<TableAction :actions="getActions(record)" />
</template>
</BasicTable>
<RouteModal @register="registerDrawer" @success="reload" />
<!--回收站弹窗-->
<RouteRecycleBinModal @register="registerRecycleModal" @success="reload" />
</div>
</template>
<script lang="ts" name="monitor-route" setup>
import { ref } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { getRouteList, deleteRoute, copyRoute } from './route.api';
import { columns } from './route.data';
import RouteModal from './RouteModal.vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { useDrawer } from '/@/components/Drawer';
import { useListPage } from '/@/hooks/system/useListPage';
import RouteRecycleBinModal from './components/RouteRecycleBinModal.vue';
const { createMessage } = useMessage();
const [registerDrawer, { openDrawer }] = useDrawer();
const checkedKeys = ref<Array<string | number>>([]);
//回收站model
const [registerRecycleModal, { openModal: openRecycleModal }] = useModal();
// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
designScope: 'router-template',
tableProps: {
title: '路由列表',
api: getRouteList,
useSearchForm: false,
columns: columns,
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
/**
* 序号列配置
*/
const indexColumnProps = {
dataIndex: 'index',
width: '15px',
};
/**
* 操作列定义
* @param record
*/
function getActions(record) {
return [
{
label: '编辑',
onClick: handleEdit.bind(null, record),
},
{
label: '复制',
popConfirm: {
title: '是否确认复制',
confirm: handleCopy.bind(null, record),
},
},
{
label: '删除',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
];
}
/**
* 选择事件
*/
function onSelectChange(selectedRowKeys: (string | number)[]) {
checkedKeys.value = selectedRowKeys;
}
/**
* 新增事件
*/
function handleAdd() {
openDrawer(true, {
isUpdate: false,
});
}
/**
* 编辑事件
*/
function handleEdit(record) {
openDrawer(true, {
record,
isUpdate: true,
});
}
/**
* 复制
*/
async function handleCopy(record) {
await copyRoute({ id: record.id }, reload);
createMessage.success('复制成功');
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteRoute({ id: record.id }, reload);
}
</script>