UserRecycleBinModal.vue
4.9 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
<template>
<BasicModal v-bind="$attrs" @register="registerModal" title="用户回收站" :showOkBtn="false" width="1000px" destroyOnClose @fullScreen="handleFullScreen">
<BasicTable @register="registerTable" :rowSelection="rowSelection" :scroll="scroll">
<!--插槽:table标题-->
<template #tableTitle>
<a-dropdown v-if="checkedKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined"></Icon>
批量删除
</a-menu-item>
<a-menu-item key="1" @click="batchHandleRevert">
<Icon icon="ant-design:redo-outlined"></Icon>
批量还原
</a-menu-item>
</a-menu>
</template>
<a-button
>批量操作
<Icon icon="ant-design:down-outlined"></Icon>
</a-button>
</a-dropdown>
</template>
<!--操作栏-->
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction :actions="getTableAction(record)" />
</template>
</template>
</BasicTable>
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, toRaw, unref, watch } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { recycleColumns } from './user.data';
import { getRecycleBinList, putRecycleBin, deleteRecycleBin } from './user.api';
import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
// 声明Emits
const emit = defineEmits(['success', 'register']);
const checkedKeys = ref<Array<string | number>>([]);
const [registerModal] = useModalInner(() => {
checkedKeys.value = [];
});
const scroll = ref({ y: 0 });
//注册table数据
const [registerTable, { reload }] = useTable({
api: getRecycleBinList,
columns: recycleColumns,
rowKey: 'id',
striped: true,
useSearchForm: false,
showTableSetting: false,
clickToRowSelect: false,
bordered: true,
showIndexColumn: false,
pagination: true,
tableSetting: { fullScreen: true },
canResize: false,
actionColumn: {
width: 150,
title: '操作',
dataIndex: 'action',
// slots: { customRender: 'action' },
fixed: undefined,
},
});
// update-begin--author:liaozhiyang---date:20240704---for:【TV360X-1657】系统用户回收站弹窗分页展示在可视区内
const handleFullScreen = (maximize) => {
setTableHeight(maximize);
};
const setTableHeight = (maximize) => {
const clientHeight = document.documentElement.clientHeight;
scroll.value = {
y: clientHeight - (maximize ? 300 : 500),
};
};
setTableHeight(false);
watch(
checkedKeys,
(newValue, oldValue) => {
if (checkedKeys.value.length && oldValue.length == 0) {
scroll.value = {
y: scroll.value.y - 50,
};
} else if (checkedKeys.value.length == 0 && oldValue.length) {
scroll.value = {
y: scroll.value.y + 50,
};
}
},
{ deep: true }
);
// update-end--author:liaozhiyang---date:20240704---for:【TV360X-1657】系统用户回收站弹窗分页展示在可视区内
/**
* 选择列配置
*/
const rowSelection = {
type: 'checkbox',
columnWidth: 50,
selectedRowKeys: checkedKeys,
onChange: onSelectChange,
};
/**
* 选择事件
*/
function onSelectChange(selectedRowKeys: (string | number)[]) {
checkedKeys.value = selectedRowKeys;
}
/**
* 还原事件
*/
async function handleRevert(record) {
await putRecycleBin({ userIds: record.id }, reload);
emit('success');
}
/**
* 批量还原事件
*/
function batchHandleRevert() {
handleRevert({ id: toRaw(unref(checkedKeys)).join(',') });
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteRecycleBin({ userIds: record.id }, reload);
}
/**
* 批量删除事件
*/
function batchHandleDelete() {
createConfirm({
iconType: 'warning',
title: '删除',
content: '确定要永久删除吗?删除后将不可恢复!',
onOk: () => handleDelete({ id: toRaw(unref(checkedKeys)).join(',') }),
onCancel() {},
});
}
//获取操作栏事件
function getTableAction(record) {
return [
{
label: '取回',
icon: 'ant-design:redo-outlined',
popConfirm: {
title: '是否确认还原',
confirm: handleRevert.bind(null, record),
},
},
{
label: '彻底删除',
icon: 'ant-design:scissor-outlined',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
];
}
</script>