feat: 【ele】字典管理新增批量删除
parent
842404d5b9
commit
79c451d256
|
|
@ -48,6 +48,13 @@ export function deleteDictData(id: number) {
|
||||||
return requestClient.delete(`/system/dict-data/delete?id=${id}`);
|
return requestClient.delete(`/system/dict-data/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量删除字典数据
|
||||||
|
export function deleteDictDataList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/system/dict-data/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 导出字典类型数据
|
// 导出字典类型数据
|
||||||
export function exportDictData(params: any) {
|
export function exportDictData(params: any) {
|
||||||
return requestClient.download('/system/dict-data/export', { params });
|
return requestClient.download('/system/dict-data/export', { params });
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,13 @@ export function deleteDictType(id: number) {
|
||||||
return requestClient.delete(`/system/dict-type/delete?id=${id}`);
|
return requestClient.delete(`/system/dict-type/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量删除字典
|
||||||
|
export function deleteDictTypeList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/system/dict-type/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 导出字典类型
|
// 导出字典类型
|
||||||
export function exportDictType(params: any) {
|
export function exportDictType(params: any) {
|
||||||
return requestClient.download('/system/dict-type/export', { params });
|
return requestClient.download('/system/dict-type/export', { params });
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ export function useTypeGridColumns<T = SystemDictTypeApi.DictType>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '字典编号',
|
title: '字典编号',
|
||||||
|
|
@ -314,6 +315,7 @@ export function useDataGridColumns<T = SystemDictDataApi.DictData>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '字典编码',
|
title: '字典编码',
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,17 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { SystemDictDataApi } from '#/api/system/dict/data';
|
import type { SystemDictDataApi } from '#/api/system/dict/data';
|
||||||
|
|
||||||
import { watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { 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 {
|
import {
|
||||||
deleteDictData,
|
deleteDictData,
|
||||||
|
deleteDictDataList,
|
||||||
exportDictData,
|
exportDictData,
|
||||||
getDictDataPage,
|
getDictDataPage,
|
||||||
} from '#/api/system/dict/data';
|
} from '#/api/system/dict/data';
|
||||||
|
|
@ -67,13 +67,35 @@ async function onDelete(row: any) {
|
||||||
await deleteDictData(row.id);
|
await deleteDictData(row.id);
|
||||||
ElMessage.success($t('common.operationSuccess'));
|
ElMessage.success($t('common.operationSuccess'));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
|
||||||
// 异常处理
|
|
||||||
} finally {
|
} finally {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除字典数据 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
fullscreen: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDictDataList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: SystemDictDataApi.DictData[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮回调 */
|
/** 表格操作按钮回调 */
|
||||||
function onActionClick({ code, row }: OnActionClickParams) {
|
function onActionClick({ code, row }: OnActionClickParams) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
@ -116,6 +138,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<SystemDictDataApi.DictData>,
|
} as VxeTableGridOptions<SystemDictDataApi.DictData>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 监听 dictType 变化,重新查询 */
|
/** 监听 dictType 变化,重新查询 */
|
||||||
|
|
@ -135,23 +161,32 @@ watch(
|
||||||
|
|
||||||
<Grid table-title="字典数据列表">
|
<Grid table-title="字典数据列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['system:dict:create']"
|
label: $t('ui.actionTitle.create', ['字典数据']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="mr-2 size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['字典数据']) }}
|
auth: ['system:dict:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
<ElButton
|
},
|
||||||
type="primary"
|
{
|
||||||
class="ml-2"
|
label: $t('ui.actionTitle.export'),
|
||||||
@click="onExport"
|
type: 'primary',
|
||||||
v-access:code="['system:dict:export']"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
>
|
auth: ['system:dict:export'],
|
||||||
<Download class="mr-2 size-5" />
|
onClick: onExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</ElButton>
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['system:dict:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type {
|
import type {
|
||||||
OnActionClickParams,
|
OnActionClickParams,
|
||||||
VxeGridListeners,
|
|
||||||
VxeTableGridOptions,
|
VxeTableGridOptions,
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { SystemDictTypeApi } from '#/api/system/dict/type';
|
import type { SystemDictTypeApi } from '#/api/system/dict/type';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { 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 {
|
import {
|
||||||
deleteDictType,
|
deleteDictType,
|
||||||
|
deleteDictTypeList,
|
||||||
exportDictType,
|
exportDictType,
|
||||||
getDictTypePage,
|
getDictTypePage,
|
||||||
} from '#/api/system/dict/type';
|
} from '#/api/system/dict/type';
|
||||||
|
|
@ -61,13 +62,35 @@ async function onDelete(row: SystemDictTypeApi.DictType) {
|
||||||
await deleteDictType(row.id as number);
|
await deleteDictType(row.id as number);
|
||||||
ElMessage.success($t('common.operationSuccess'));
|
ElMessage.success($t('common.operationSuccess'));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
|
||||||
// 异常处理
|
|
||||||
} finally {
|
} finally {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除字典类型 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
fullscreen: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDictTypeList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: SystemDictTypeApi.DictType[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮回调 */
|
/** 表格操作按钮回调 */
|
||||||
function onActionClick({
|
function onActionClick({
|
||||||
code,
|
code,
|
||||||
|
|
@ -85,13 +108,6 @@ function onActionClick({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 表格事件 */
|
|
||||||
const gridEvents: VxeGridListeners<SystemDictTypeApi.DictType> = {
|
|
||||||
cellClick: ({ row }) => {
|
|
||||||
emit('select', row.type);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useTypeGridFormSchema(),
|
schema: useTypeGridFormSchema(),
|
||||||
|
|
@ -120,7 +136,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<SystemDictTypeApi.DictType>,
|
} as VxeTableGridOptions<SystemDictTypeApi.DictType>,
|
||||||
gridEvents,
|
gridEvents: {
|
||||||
|
cellClick: ({ row }: { row: SystemDictTypeApi.DictType }) => {
|
||||||
|
emit('select', row.type);
|
||||||
|
},
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -130,23 +152,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
|
||||||
<Grid table-title="字典类型列表">
|
<Grid table-title="字典类型列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['system:dict:create']"
|
label: $t('ui.actionTitle.create', ['字典类型']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="mr-2 size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['字典类型']) }}
|
auth: ['system:dict:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
<ElButton
|
},
|
||||||
type="primary"
|
{
|
||||||
class="ml-2"
|
label: $t('ui.actionTitle.export'),
|
||||||
@click="onExport"
|
type: 'primary',
|
||||||
v-access:code="['system:dict:export']"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
>
|
auth: ['system:dict:export'],
|
||||||
<Download class="mr-2 size-5" />
|
onClick: onExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</ElButton>
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['system:dict:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue