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

pull/144/head
puhui999 2025-06-15 17:52:03 +08:00
parent 0cc83967ed
commit 2939c2e4f5
2 changed files with 56 additions and 2 deletions

View File

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

View File

@ -2,14 +2,17 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemSmsChannelApi } from '#/api/system/sms/channel'; import type { SystemSmsChannelApi } from '#/api/system/sms/channel';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui'; 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 { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
deleteSmsChannel, deleteSmsChannel,
deleteSmsChannelList,
exportSmsChannel, exportSmsChannel,
getSmsChannelPage, getSmsChannelPage,
} from '#/api/system/sms/channel'; } from '#/api/system/sms/channel';
@ -62,6 +65,39 @@ async function handleDelete(row: SystemSmsChannelApi.SmsChannel) {
} }
} }
// ID
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemSmsChannelApi.SmsChannel[];
}) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 批量删除处理 */
async function handleDeleteBatch() {
if (checkedIds.value.length === 0) {
message.warning('请至少选择一条数据');
return;
}
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', ['短信渠道']),
key: 'action_key_msg',
});
try {
await deleteSmsChannelList(checkedIds.value);
message.success({
content: $t('ui.actionMessage.deleteSuccess', ['短信渠道']),
key: 'action_key_msg',
});
checkedIds.value = [];
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
@ -83,12 +119,20 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: { code: 'query' }, refresh: { code: 'query' },
search: true, search: true,
}, },
checkboxConfig: {
checkField: 'checked',
},
} as VxeTableGridOptions<SystemSmsChannelApi.SmsChannel>, } as VxeTableGridOptions<SystemSmsChannelApi.SmsChannel>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
}); });
</script> </script>
@ -117,6 +161,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['system:sms-channel:export'], auth: ['system:sms-channel:export'],
onClick: handleExport, onClick: handleExport,
}, },
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:sms-channel:delete'],
onClick: handleDeleteBatch,
},
]" ]"
/> />
</template> </template>
@ -137,7 +190,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
auth: ['system:sms-channel:delete'], auth: ['system:sms-channel:delete'],
popConfirm: { popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]), title: $t('ui.actionMessage.deleteConfirm', [row.signature]),
confirm: handleDelete.bind(null, row), confirm: handleDelete.bind(null, row),
}, },
}, },