feat: 【ele】配置管理新增批量删除
parent
c874f754b8
commit
79011799dc
|
@ -54,6 +54,11 @@ export function deleteConfig(id: number) {
|
||||||
return requestClient.delete(`/infra/config/delete?id=${id}`);
|
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) {
|
export function exportConfig(params: any) {
|
||||||
return requestClient.download('/infra/config/export', {
|
return requestClient.download('/infra/config/export', {
|
||||||
|
|
|
@ -126,6 +126,7 @@ export function useGridColumns<T = InfraConfigApi.Config>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '参数主键',
|
title: '参数主键',
|
||||||
|
|
|
@ -5,14 +5,20 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { InfraConfigApi } from '#/api/infra/config';
|
import type { InfraConfigApi } from '#/api/infra/config';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus } from '@vben/icons';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
||||||
|
|
||||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteConfig, exportConfig, getConfigPage } from '#/api/infra/config';
|
import {
|
||||||
|
deleteConfig,
|
||||||
|
deleteConfigList,
|
||||||
|
exportConfig,
|
||||||
|
getConfigPage,
|
||||||
|
} from '#/api/infra/config';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
@ -52,15 +58,39 @@ async function onDelete(row: InfraConfigApi.Config) {
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteConfig(row.id as number);
|
await deleteConfig(row.id as number);
|
||||||
// TODO @puhui999:close 是不是放在 finally 里面更好?
|
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
} finally {
|
||||||
loadingInstance.close();
|
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<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: InfraConfigApi.Config[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
/** 表格操作按钮的回调函数 */
|
||||||
function onActionClick({
|
function onActionClick({
|
||||||
code,
|
code,
|
||||||
|
@ -105,6 +135,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<InfraConfigApi.Config>,
|
} as VxeTableGridOptions<InfraConfigApi.Config>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -113,23 +147,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="onRefresh" />
|
||||||
<Grid table-title="参数列表">
|
<Grid table-title="参数列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['infra:config:create']"
|
label: $t('ui.actionTitle.create', ['参数']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['参数']) }}
|
auth: ['infra:config:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
<ElButton
|
},
|
||||||
type="primary"
|
{
|
||||||
class="ml-2"
|
label: $t('ui.actionTitle.export'),
|
||||||
@click="onExport"
|
type: 'primary',
|
||||||
v-access:code="['infra:config:export']"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
>
|
auth: ['infra:config:export'],
|
||||||
<Download class="size-5" />
|
onClick: onExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</ElButton>
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:config:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue