diff --git a/apps/web-ele/src/api/infra/config/index.ts b/apps/web-ele/src/api/infra/config/index.ts index 3911e01c7..521e957a2 100644 --- a/apps/web-ele/src/api/infra/config/index.ts +++ b/apps/web-ele/src/api/infra/config/index.ts @@ -54,6 +54,11 @@ export function deleteConfig(id: number) { return requestClient.delete(`/infra/config/delete?id=${id}`); } +/** 批量删除参数 */ +export function deleteConfigList(ids: number[]) { + return requestClient.delete(`/infra/config/delete-list?ids=${ids.join(',')}`); +} + /** 导出参数 */ export function exportConfig(params: any) { return requestClient.download('/infra/config/export', { diff --git a/apps/web-ele/src/views/infra/config/data.ts b/apps/web-ele/src/views/infra/config/data.ts index 1a79bc3b2..72afcb9d0 100644 --- a/apps/web-ele/src/views/infra/config/data.ts +++ b/apps/web-ele/src/views/infra/config/data.ts @@ -126,6 +126,7 @@ export function useGridColumns( onActionClick: OnActionClickFn, ): VxeTableGridOptions['columns'] { return [ + { type: 'checkbox', width: 40 }, { field: 'id', title: '参数主键', diff --git a/apps/web-ele/src/views/infra/config/index.vue b/apps/web-ele/src/views/infra/config/index.vue index 0c9d66772..e765f2bae 100644 --- a/apps/web-ele/src/views/infra/config/index.vue +++ b/apps/web-ele/src/views/infra/config/index.vue @@ -5,14 +5,20 @@ import type { } from '#/adapter/vxe-table'; import type { InfraConfigApi } from '#/api/infra/config'; +import { ref } from 'vue'; + import { Page, useVbenModal } from '@vben/common-ui'; -import { Download, Plus } from '@vben/icons'; -import { downloadFileFromBlobPart } from '@vben/utils'; +import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; -import { ElButton, ElLoading, ElMessage } from 'element-plus'; +import { ElLoading, ElMessage } from 'element-plus'; -import { useVbenVxeGrid } from '#/adapter/vxe-table'; -import { deleteConfig, exportConfig, getConfigPage } from '#/api/infra/config'; +import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; +import { + deleteConfig, + deleteConfigList, + exportConfig, + getConfigPage, +} from '#/api/infra/config'; import { $t } from '#/locales'; import { useGridColumns, useGridFormSchema } from './data'; @@ -52,15 +58,39 @@ async function onDelete(row: InfraConfigApi.Config) { }); try { await deleteConfig(row.id as number); - // TODO @puhui999:close 是不是放在 finally 里面更好? loadingInstance.close(); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name])); onRefresh(); - } catch { + } finally { loadingInstance.close(); } } +/** 批量删除参数 */ +async function onDeleteBatch() { + const loadingInstance = ElLoading.service({ + text: $t('ui.actionMessage.deleting'), + fullscreen: true, + }); + try { + await deleteConfigList(checkedIds.value); + loadingInstance.close(); + ElMessage.success($t('ui.actionMessage.deleteSuccess')); + onRefresh(); + } finally { + loadingInstance.close(); + } +} + +const checkedIds = ref([]); +function handleRowCheckboxChange({ + records, +}: { + records: InfraConfigApi.Config[]; +}) { + checkedIds.value = records.map((item) => item.id as number); +} + /** 表格操作按钮的回调函数 */ function onActionClick({ code, @@ -105,6 +135,10 @@ const [Grid, gridApi] = useVbenVxeGrid({ search: true, }, } as VxeTableGridOptions, + gridEvents: { + checkboxAll: handleRowCheckboxChange, + checkboxChange: handleRowCheckboxChange, + }, }); @@ -113,23 +147,32 @@ const [Grid, gridApi] = useVbenVxeGrid({