From 5355993a2a82a2ad2453a43b8735a130015b00ac Mon Sep 17 00:00:00 2001 From: Leo <98382335+gaoziman@users.noreply.github.com> Date: Sat, 27 Sep 2025 01:05:05 +0800 Subject: [PATCH] feat(dict): enforce dictionary driven state on dictionary pages --- src/views/system/dict/data.vue | 32 +++++++++++++++++--------------- src/views/system/dict/index.vue | 22 +++++++++++++++------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/views/system/dict/data.vue b/src/views/system/dict/data.vue index fb8c943..cc56e3f 100644 --- a/src/views/system/dict/data.vue +++ b/src/views/system/dict/data.vue @@ -327,7 +327,8 @@ import { NButton, NIcon, NInputNumber, NPopconfirm, NSpace, NSwitch, NTag } from import CoiDialog from '@/components/common/CoiDialog.vue' import CoiEmpty from '@/components/common/CoiEmpty.vue' import CoiPagination from '@/components/common/CoiPagination.vue' -import { usePermission } from '@/hooks/usePermission' +import { useDict, usePermission } from '@/hooks' +import { useDictStore } from '@/store' import { coiMsgBox, coiMsgError, coiMsgSuccess, coiMsgWarning } from '@/utils/coi' import { addDictData, @@ -374,6 +375,9 @@ const currentDictType = ref(null) const dictTypeOptions = ref<{ label: string, value: string }[]>([]) const isFromTypeClick = ref(false) +const dictStore = useDictStore() +const { getSelectOptions, getDictLabel } = useDict(['sys_switch_status', 'sys_tag_type']) + // 搜索表单数据 const searchForm = reactive({ dictType: '', @@ -414,18 +418,8 @@ function handlePageSizeChange(pageSize: number) { } // 状态选项 -const statusOptions = [ - { label: '正常', value: DictStatus.NORMAL }, - { label: '停用', value: DictStatus.DISABLED }, -] - -// 标签类型选项 -const tagOptions = [ - { label: 'primary', value: DictTag.PRIMARY }, - { label: 'success', value: DictTag.SUCCESS }, - { label: 'info', value: DictTag.INFO }, - { label: 'warning', value: DictTag.WARNING }, -] +const statusOptions = computed(() => getSelectOptions('sys_switch_status')) +const tagOptions = computed(() => getSelectOptions('sys_tag_type')) // 表单验证规则 const rules: FormRules = { @@ -550,7 +544,7 @@ const columns: DataTableColumns = [ negativeText: '取消', positiveText: '确定', }, { - default: () => `确定要${row.dictStatus === DictStatus.NORMAL ? '停用' : '启用'}字典数据「${row.dictLabel}」吗?`, + default: () => `确定要将字典数据「${row.dictLabel}」状态切换为「${getDictLabel('sys_switch_status', row.dictStatus === DictStatus.NORMAL ? '1' : '0')}」吗?`, trigger: () => h(NSwitch, { value: row.dictStatus === DictStatus.NORMAL, size: 'small', @@ -822,6 +816,7 @@ async function handleDelete(row: DictDataVo) { if (isSuccess) { coiMsgSuccess('删除成功') + dictStore.invalidate(row.dictType) getTableData() } else { @@ -849,6 +844,8 @@ async function handleBatchDelete() { coiMsgSuccess('批量删除成功') checkedRowKeys.value = [] selectedRows.value = [] + if (searchForm.dictType) + dictStore.invalidate(searchForm.dictType) getTableData() } else { @@ -868,7 +865,9 @@ async function handleStatusChange(row: DictDataVo) { const { isSuccess } = await updateDictDataStatus(row.dictId, newStatus) if (isSuccess) { - coiMsgSuccess('状态修改成功') + const statusLabel = getDictLabel('sys_switch_status', newStatus, newStatus === DictStatus.NORMAL ? '启用' : '停用') + coiMsgSuccess(`状态已更新为「${statusLabel}」`) + dictStore.invalidate(row.dictType) getTableData() } else { @@ -888,6 +887,7 @@ async function handleSyncCache() { if (isSuccess) { coiMsgSuccess('缓存同步成功') + dictStore.invalidate() } else { coiMsgError('缓存同步失败') @@ -936,6 +936,8 @@ async function handleSubmit() { if (isSuccess) { coiMsgSuccess(isEdit.value ? '修改成功' : '新增成功') formDialogRef.value?.coiClose() + if (submitData.dictType) + dictStore.invalidate(submitData.dictType) getTableData() } else { diff --git a/src/views/system/dict/index.vue b/src/views/system/dict/index.vue index 6d7dd3a..bc83a2c 100644 --- a/src/views/system/dict/index.vue +++ b/src/views/system/dict/index.vue @@ -251,7 +251,8 @@ import { NButton, NIcon, NPopconfirm, NSpace, NSwitch } from 'naive-ui' import CoiDialog from '@/components/common/CoiDialog.vue' import CoiEmpty from '@/components/common/CoiEmpty.vue' import CoiPagination from '@/components/common/CoiPagination.vue' -import { usePermission } from '@/hooks/usePermission' +import { useDict, usePermission } from '@/hooks' +import { useDictStore } from '@/store' import { coiMsgBox, coiMsgError, coiMsgSuccess, coiMsgWarning } from '@/utils/coi' import { addDictType, @@ -276,6 +277,7 @@ import IconParkOutlineEdit from '~icons/icon-park-outline/edit' // 路由和权限验证 const router = useRouter() const { hasPermission } = usePermission() +const { getSelectOptions, getDictLabel } = useDict(['sys_switch_status']) // 响应式数据 const loading = ref(false) @@ -287,6 +289,7 @@ const formRef = ref() const formDialogRef = ref() const isEdit = ref(false) const modalTitle = ref('') +const dictStore = useDictStore() // 搜索表单数据 const searchForm = reactive({ @@ -324,10 +327,7 @@ function handlePageSizeChange(pageSize: number) { } // 状态选项 -const statusOptions = [ - { label: '正常', value: DictStatus.NORMAL }, - { label: '停用', value: DictStatus.DISABLED }, -] +const statusOptions = computed(() => getSelectOptions('sys_switch_status')) // 表单验证规则 const rules: FormRules = { @@ -411,10 +411,12 @@ const columns: DataTableColumns = [ negativeText: '取消', positiveText: '确定', }, { - default: () => `确定要${row.dictStatus === DictStatus.NORMAL ? '停用' : '启用'}字典类型「${row.dictName}」吗?`, + default: () => `确定要将字典类型「${row.dictName}」状态切换为「${getDictLabel('sys_switch_status', row.dictStatus === DictStatus.NORMAL ? '1' : '0')}」吗?`, trigger: () => h(NSwitch, { value: row.dictStatus === DictStatus.NORMAL, size: 'small', + checkedChildren: getDictLabel('sys_switch_status', '0', '启用'), + uncheckedChildren: getDictLabel('sys_switch_status', '1', '停用'), }), }), ]) @@ -595,6 +597,7 @@ async function handleDelete(row: DictTypeVo) { if (isSuccess) { coiMsgSuccess('删除成功') + dictStore.invalidate() getTableData() } else { @@ -622,6 +625,7 @@ async function handleBatchDelete() { coiMsgSuccess('批量删除成功') checkedRowKeys.value = [] selectedRows.value = [] + dictStore.invalidate() getTableData() } else { @@ -641,7 +645,9 @@ async function handleStatusChange(row: DictTypeVo) { const { isSuccess } = await updateDictTypeStatus(row.dictId, newStatus) if (isSuccess) { - coiMsgSuccess('状态修改成功') + const statusLabel = getDictLabel('sys_switch_status', newStatus, newStatus === DictStatus.NORMAL ? '启用' : '停用') + coiMsgSuccess(`状态已更新为「${statusLabel}」`) + dictStore.invalidate() getTableData() } else { @@ -661,6 +667,7 @@ async function handleSyncCache() { if (isSuccess) { coiMsgSuccess('缓存同步成功') + dictStore.invalidate() } else { coiMsgError('缓存同步失败') @@ -704,6 +711,7 @@ async function handleSubmit() { if (isSuccess) { coiMsgSuccess(isEdit.value ? '修改成功' : '新增成功') formDialogRef.value?.coiClose() + dictStore.invalidate() getTableData() } else {