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

Merge pull request !144 from puhui999/dev-new
This commit is contained in:
芋道源码
2025-06-16 01:06:02 +00:00
committed by Gitee
59 changed files with 997 additions and 36 deletions

View File

@@ -186,6 +186,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '角色编号',

View File

@@ -2,13 +2,20 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemRoleApi } from '#/api/system/role';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteRole, exportRole, getRolePage } from '#/api/system/role';
import {
deleteRole,
deleteRoleList,
exportRole,
getRolePage,
} from '#/api/system/role';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -71,6 +78,31 @@ async function handleDelete(row: SystemRoleApi.Role) {
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemRoleApi.Role[];
}) {
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 deleteRoleList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
/** 分配角色的数据权限 */
function handleAssignDataPermission(row: SystemRoleApi.Role) {
assignDataPermissionFormApi.setData(row).open();
@@ -93,7 +125,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
ajax: {
query: async ({ page }, formValues) => {
return await getRolePage({
page: page.currentPage,
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
@@ -102,12 +134,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<SystemRoleApi.Role>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@@ -142,6 +179,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['system:role:export'],
onClick: handleExport,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:role:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>