role-assign-drawer.vue
1.91 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
<script setup lang="ts">
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { useRoute } from 'vue-router';
import { useVbenDrawer } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { roleSelectAll, roleUnallocatedList } from '#/api/system/role';
import { columns, querySchema } from './data';
const emit = defineEmits<{ reload: [] }>();
const [BasicDrawer, drawerApi] = useVbenDrawer({
onConfirm: handleSubmit,
onCancel: handleReset,
destroyOnClose: true,
});
const route = useRoute();
const roleId = route.params.roleId as string;
const formOptions: VbenFormProps = {
commonConfig: {
labelWidth: 80,
},
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
trigger: 'row',
},
columns: columns?.filter((item) => item.field !== 'action'),
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await roleUnallocatedList(roleId, {
SkipCount: page.currentPage,
MaxResultCount: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
async function handleSubmit() {
const records = tableApi.grid.getCheckboxRecords();
const userIds = records.map((item) => item.id);
if (userIds.length > 0) {
await roleSelectAll(roleId, userIds);
}
handleReset();
emit('reload');
}
function handleReset() {
drawerApi.close();
}
</script>
<template>
<BasicDrawer class="w-[800px]" title="选择用户">
<BasicTable />
</BasicDrawer>
</template>