reactor:【system 系统管理】dict 在 element-plus 和 antd 保持一致

pull/210/head
YunaiV 2025-09-06 00:20:05 +08:00
parent e81a759e0d
commit 84e32a0884
9 changed files with 186 additions and 179 deletions

View File

@ -41,6 +41,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,

View File

@ -33,7 +33,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full', class: 'w-full',
}, },
formItemClass: 'col-span-2', formItemClass: 'col-span-2',
labelWidth: 80, labelWidth: 90,
}, },
layout: 'horizontal', layout: 'horizontal',
schema: useDataFormSchema(), schema: useDataFormSchema(),
@ -65,27 +65,21 @@ const [Modal, modalApi] = useVbenModal({
return; return;
} }
// //
const data = modalApi.getData< const data = modalApi.getData<SystemDictDataApi.DictData>();
SystemDictDataApi.DictData | { dictType?: string } if (!data || !data.id) {
>(); // dictType
await formApi.setValues(data);
// ID return;
if (data && 'id' in data && data.id) { }
modalApi.lock(); modalApi.lock();
try { try {
formData.value = await getDictData(data.id); formData.value = await getDictData(data.id);
// values // values
if (formData.value) { if (formData.value) {
await formApi.setValues(formData.value); await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
} }
} else if (data && 'dictType' in data && data.dictType) { } finally {
// dictType modalApi.unlock();
await formApi.setValues({
dictType: data.dictType,
});
} }
}, },
}); });

View File

@ -4,7 +4,7 @@ import type { SystemDictDataApi } from '#/api/system/dict/data';
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { confirm, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message, Tag } from 'ant-design-vue'; import { message, Tag } from 'ant-design-vue';
@ -58,14 +58,28 @@ function handleEdit(row: SystemDictDataApi.DictData) {
async function handleDelete(row: SystemDictDataApi.DictData) { async function handleDelete(row: SystemDictDataApi.DictData) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.label]), content: $t('ui.actionMessage.deleting', [row.label]),
key: 'action_key_msg', duration: 0,
}); });
try { try {
await deleteDictData(row.id as number); await deleteDictData(row.id);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.label]));
content: $t('ui.actionMessage.deleteSuccess', [row.label]), onRefresh();
key: 'action_key_msg', } finally {
}); hideLoading();
}
}
/** 批量删除字典数据 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
});
try {
await deleteDictDataList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh(); onRefresh();
} finally { } finally {
hideLoading(); hideLoading();
@ -81,23 +95,6 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 批量删除字典数据 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteDictDataList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useDataGridFormSchema(), schema: useDataGridFormSchema(),
@ -167,11 +164,11 @@ watch(
onClick: handleExport, onClick: handleExport,
}, },
{ {
label: '批量删除', label: $t('ui.actionTitle.deleteBatch'),
type: 'primary', type: 'primary',
danger: true, danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:dict:delete'], auth: ['system:dict:delete'],
onClick: handleDeleteBatch, onClick: handleDeleteBatch,
}, },

View File

@ -7,7 +7,7 @@ import type { SystemDictTypeApi } from '#/api/system/dict/type';
import { ref } from 'vue'; import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { confirm, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@ -48,7 +48,7 @@ function handleCreate() {
} }
/** 编辑字典类型 */ /** 编辑字典类型 */
function handleEdit(row: any) { function handleEdit(row: SystemDictTypeApi.DictType) {
typeFormModalApi.setData(row).open(); typeFormModalApi.setData(row).open();
} }
@ -56,14 +56,28 @@ function handleEdit(row: any) {
async function handleDelete(row: SystemDictTypeApi.DictType) { async function handleDelete(row: SystemDictTypeApi.DictType) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]), content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg', duration: 0,
}); });
try { try {
await deleteDictType(row.id as number); await deleteDictType(row.id);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]), onRefresh();
key: 'action_key_msg', } finally {
}); hideLoading();
}
}
/** 批量删除字典类型 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteDictTypeList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh(); onRefresh();
} finally { } finally {
hideLoading(); hideLoading();
@ -79,32 +93,6 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 批量删除字典类型 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteDictTypeList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
/** 表格事件 */
const gridEvents: VxeGridListeners<SystemDictTypeApi.DictType> = {
cellClick: ({ row }) => {
emit('select', row.type);
},
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
};
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useTypeGridFormSchema(), schema: useTypeGridFormSchema(),
@ -112,6 +100,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: { gridOptions: {
columns: useTypeGridColumns(), columns: useTypeGridColumns(),
height: 'auto', height: 'auto',
keepSource: true,
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
@ -133,14 +122,19 @@ 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>
<template> <template>
<div class="h-full"> <div class="h-full">
<TypeFormModal @success="onRefresh" /> <TypeFormModal @success="onRefresh" />
<Grid table-title=""> <Grid table-title="">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@ -160,11 +154,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleExport, onClick: handleExport,
}, },
{ {
label: '批量删除', label: $t('ui.actionTitle.deleteBatch'),
type: 'primary', type: 'primary',
danger: true, danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:dict:delete'], auth: ['system:dict:delete'],
onClick: handleDeleteBatch, onClick: handleDeleteBatch,
}, },

View File

@ -41,6 +41,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,

View File

@ -292,9 +292,7 @@ export function useDataGridFormSchema(): VbenFormSchema[] {
]; ];
} }
/** /** 字典数据表格列 */
*
*/
export function useDataGridColumns(): VxeTableGridOptions['columns'] { export function useDataGridColumns(): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },

View File

@ -33,7 +33,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full', class: 'w-full',
}, },
formItemClass: 'col-span-2', formItemClass: 'col-span-2',
labelWidth: 80, labelWidth: 90,
}, },
layout: 'horizontal', layout: 'horizontal',
schema: useDataFormSchema(), schema: useDataFormSchema(),
@ -65,27 +65,21 @@ const [Modal, modalApi] = useVbenModal({
return; return;
} }
// //
const data = modalApi.getData< const data = modalApi.getData<SystemDictDataApi.DictData>();
SystemDictDataApi.DictData | { dictType?: string } if (!data || !data.id) {
>(); // dictType
await formApi.setValues(data);
// ID return;
if (data && 'id' in data && data.id) { }
modalApi.lock(); modalApi.lock();
try { try {
formData.value = await getDictData(data.id); formData.value = await getDictData(data.id);
// values // values
if (formData.value) { if (formData.value) {
await formApi.setValues(formData.value); await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
} }
} else if (data && 'dictType' in data && data.dictType) { } finally {
// dictType modalApi.unlock();
await formApi.setValues({
dictType: data.dictType,
});
} }
}, },
}); });

View File

@ -1,8 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { SystemDictDataApi } from '#/api/system/dict/data'; import type { SystemDictDataApi } from '#/api/system/dict/data';
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
@ -42,29 +39,29 @@ function onRefresh() {
} }
/** 导出表格 */ /** 导出表格 */
async function onExport() { async function handleExport() {
const data = await exportDictData(await gridApi.formApi.getValues()); const data = await exportDictData(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '字典数据.xls', source: data }); downloadFileFromBlobPart({ fileName: '字典数据.xls', source: data });
} }
/** 创建字典数据 */ /** 创建字典数据 */
function onCreate() { function handleCreate() {
dataFormModalApi.setData({ dictType: props.dictType }).open(); dataFormModalApi.setData({ dictType: props.dictType }).open();
} }
/** 编辑字典数据 */ /** 编辑字典数据 */
function onEdit(row: any) { function handleEdit(row: SystemDictDataApi.DictData) {
dataFormModalApi.setData(row).open(); dataFormModalApi.setData(row).open();
} }
/** 删除字典数据 */ /** 删除字典数据 */
async function onDelete(row: any) { async function handleDelete(row: SystemDictDataApi.DictData) {
const loadingInstance = ElLoading.service({ const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]), text: $t('ui.actionMessage.deleting', [row.label]),
}); });
try { try {
await deleteDictData(row.id); await deleteDictData(row.id);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name])); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.label]));
onRefresh(); onRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
@ -72,12 +69,19 @@ async function onDelete(row: any) {
} }
/** 批量删除字典数据 */ /** 批量删除字典数据 */
async function onDeleteBatch() { async function handleDeleteBatch() {
await confirm('确定要批量删除该字典数据吗?'); await confirm($t('ui.actionMessage.deleteBatchConfirm'));
await deleteDictDataList(checkedIds.value); const loadingInstance = ElLoading.service({
checkedIds.value = []; text: $t('ui.actionMessage.deletingBatch'),
ElMessage.success($t('ui.actionMessage.deleteSuccess')); });
onRefresh(); try {
await deleteDictDataList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
loadingInstance.close();
}
} }
const checkedIds = ref<number[]>([]); const checkedIds = ref<number[]>([]);
@ -89,26 +93,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 表格操作按钮回调 */
function onActionClick({ code, row }: OnActionClickParams) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useDataGridFormSchema(), schema: useDataGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useDataGridColumns(onActionClick), columns: useDataGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@ -125,6 +115,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@ -161,14 +152,14 @@ watch(
type: 'primary', type: 'primary',
icon: ACTION_ICON.ADD, icon: ACTION_ICON.ADD,
auth: ['system:dict:create'], auth: ['system:dict:create'],
onClick: onCreate, onClick: handleCreate,
}, },
{ {
label: $t('ui.actionTitle.export'), label: $t('ui.actionTitle.export'),
type: 'primary', type: 'primary',
icon: ACTION_ICON.DOWNLOAD, icon: ACTION_ICON.DOWNLOAD,
auth: ['system:dict:export'], auth: ['system:dict:export'],
onClick: onExport, onClick: handleExport,
}, },
{ {
label: $t('ui.actionTitle.deleteBatch'), label: $t('ui.actionTitle.deleteBatch'),
@ -176,7 +167,32 @@ watch(
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds), disabled: isEmpty(checkedIds),
auth: ['system:dict:delete'], auth: ['system:dict:delete'],
onClick: onDeleteBatch, onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['system:dict:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:dict:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.label]),
confirm: handleDelete.bind(null, row),
},
}, },
]" ]"
/> />

View File

@ -1,8 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams,
VxeTableGridOptions,
} 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 { ref } from 'vue';
@ -37,23 +34,23 @@ function onRefresh() {
} }
/** 导出表格 */ /** 导出表格 */
async function onExport() { async function handleExport() {
const data = await exportDictType(await gridApi.formApi.getValues()); const data = await exportDictType(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '字典类型.xls', source: data }); downloadFileFromBlobPart({ fileName: '字典类型.xls', source: data });
} }
/** 创建字典类型 */ /** 创建字典类型 */
function onCreate() { function handleCreate() {
typeFormModalApi.setData(null).open(); typeFormModalApi.setData(null).open();
} }
/** 编辑字典类型 */ /** 编辑字典类型 */
function onEdit(row: any) { function handleEdit(row: SystemDictTypeApi.DictType) {
typeFormModalApi.setData(row).open(); typeFormModalApi.setData(row).open();
} }
/** 删除字典类型 */ /** 删除字典类型 */
async function onDelete(row: SystemDictTypeApi.DictType) { async function handleDelete(row: SystemDictTypeApi.DictType) {
const loadingInstance = ElLoading.service({ const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]), text: $t('ui.actionMessage.deleting', [row.name]),
}); });
@ -67,12 +64,19 @@ async function onDelete(row: SystemDictTypeApi.DictType) {
} }
/** 批量删除字典类型 */ /** 批量删除字典类型 */
async function onDeleteBatch() { async function handleDeleteBatch() {
await confirm('确定要批量删除该字典类型吗?'); await confirm($t('ui.actionMessage.deleteBatchConfirm'));
await deleteDictTypeList(checkedIds.value); const loadingInstance = ElLoading.service({
checkedIds.value = []; text: $t('ui.actionMessage.deletingBatch'),
ElMessage.success($t('ui.actionMessage.deleteSuccess')); });
onRefresh(); try {
await deleteDictTypeList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
loadingInstance.close();
}
} }
const checkedIds = ref<number[]>([]); const checkedIds = ref<number[]>([]);
@ -84,29 +88,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 表格操作按钮回调 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemDictTypeApi.DictType>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useTypeGridFormSchema(), schema: useTypeGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useTypeGridColumns(onActionClick), columns: useTypeGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@ -123,6 +110,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isCurrent: true, isCurrent: true,
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@ -142,7 +130,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<div class="h-full"> <div class="h-full">
<TypeFormModal @success="onRefresh" /> <TypeFormModal @success="onRefresh" />
<Grid table-title=""> <Grid table-title="">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@ -152,14 +139,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary', type: 'primary',
icon: ACTION_ICON.ADD, icon: ACTION_ICON.ADD,
auth: ['system:dict:create'], auth: ['system:dict:create'],
onClick: onCreate, onClick: handleCreate,
}, },
{ {
label: $t('ui.actionTitle.export'), label: $t('ui.actionTitle.export'),
type: 'primary', type: 'primary',
icon: ACTION_ICON.DOWNLOAD, icon: ACTION_ICON.DOWNLOAD,
auth: ['system:dict:export'], auth: ['system:dict:export'],
onClick: onExport, onClick: handleExport,
}, },
{ {
label: $t('ui.actionTitle.deleteBatch'), label: $t('ui.actionTitle.deleteBatch'),
@ -167,7 +154,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds), disabled: isEmpty(checkedIds),
auth: ['system:dict:delete'], auth: ['system:dict:delete'],
onClick: onDeleteBatch, onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['system:dict:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:dict:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
}, },
]" ]"
/> />