feat: 【antd】新增批量删除操作

This commit is contained in:
puhui999
2025-06-15 17:02:10 +08:00
parent 34f41790c2
commit 0cc83967ed
45 changed files with 997 additions and 297 deletions

View File

@@ -113,6 +113,7 @@ export function useGridColumns(
getLeaderName?: (userId: number) => string | undefined,
): VxeTableGridOptions<SystemDeptApi.Dept>['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'name',
title: '部门名称',

View File

@@ -6,11 +6,12 @@ import type { SystemUserApi } from '#/api/system/user';
import { onMounted, ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteDept, getDeptList } from '#/api/system/dept';
import { deleteDept, deleteDeptList, getDeptList } from '#/api/system/dept';
import { getSimpleUserList } from '#/api/system/user';
import { $t } from '#/locales';
@@ -60,14 +61,37 @@ function handleEdit(row: SystemDeptApi.Dept) {
async function handleDelete(row: SystemDeptApi.Dept) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
duration: 0,
key: 'action_process_msg',
});
try {
await deleteDept(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemDeptApi.Dept[];
}) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 批量删除部门 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteDeptList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
@@ -78,31 +102,33 @@ const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useGridColumns(getLeaderName),
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_params) => {
query: async () => {
return await getDeptList();
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
treeConfig: {
parentField: 'parentId',
rowField: 'id',
transform: true,
rowField: 'id',
parentField: 'parentId',
expandAll: true,
reserve: true,
accordion: false,
},
} as VxeTableGridOptions,
} as VxeTableGridOptions<SystemDeptApi.Dept>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
/** 初始化 */
@@ -130,6 +156,15 @@ onMounted(async () => {
type: 'primary',
onClick: toggleExpand,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:dept:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>