From d6a78427d1d3a37fbaae07faa710437abe0925d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E6=B0=B8=E6=98=A5?= Date: Fri, 5 Dec 2025 09:50:25 +0800 Subject: [PATCH] =?UTF-8?q?feat-wip(components):=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E7=9B=B8=E5=85=B3=E9=A1=B5=E9=9D=A2=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/api/sys/core/dictionary.ts | 26 ++++ src/typings/api/sys/core.d.ts | 8 + .../modules/dictionary-operate-drawer.vue | 137 +++++++++++++++++- 3 files changed, 163 insertions(+), 8 deletions(-) diff --git a/src/service/api/sys/core/dictionary.ts b/src/service/api/sys/core/dictionary.ts index 63d463a2..ce861e0e 100644 --- a/src/service/api/sys/core/dictionary.ts +++ b/src/service/api/sys/core/dictionary.ts @@ -53,3 +53,29 @@ export function fetchTreeDictionaryItem(dictionaryId: string) { } }); } + +export function fetchDictionaryItemAdd(dictionaryOp: Api.Sys.Core.DictionaryItemOp) { + return request({ + url: '/dictionaryItem/insert', + method: 'post', + data: dictionaryOp + }); +} + +export function fetchDictionaryItemEdit(dictionaryOp: Api.Sys.Core.DictionaryItemOp) { + return request({ + url: '/dictionaryItem/update', + method: 'post', + data: dictionaryOp + }); +} + +export function fetchDictionaryItemDelete(id: string) { + return request({ + url: '/dictionaryItem/delete', + method: 'post', + data: { + id + } + }); +} diff --git a/src/typings/api/sys/core.d.ts b/src/typings/api/sys/core.d.ts index 4f8d9c80..5251fee4 100644 --- a/src/typings/api/sys/core.d.ts +++ b/src/typings/api/sys/core.d.ts @@ -35,6 +35,14 @@ declare namespace Api { updateTime: string | null; children: DictionaryItem[]; } + interface DictionaryItemOp { + id: string | null; + dictionaryId: string; + name: string; + code: string; + sort: number; + description: string | null; + } } } } diff --git a/src/views/sys/core/dictionary/modules/dictionary-operate-drawer.vue b/src/views/sys/core/dictionary/modules/dictionary-operate-drawer.vue index 566ba844..8ffce02c 100644 --- a/src/views/sys/core/dictionary/modules/dictionary-operate-drawer.vue +++ b/src/views/sys/core/dictionary/modules/dictionary-operate-drawer.vue @@ -3,7 +3,14 @@ import { computed, ref, watch } from 'vue'; import type { DataTableColumns } from 'naive-ui'; import { jsonClone } from '@sa/utils'; import { dictionaryTypeOptions } from '@/constants/sys/core/dictionary'; -import { fetchDictionaryAdd, fetchDictionaryEdit, fetchTreeDictionaryItem } from '@/service/api'; +import { + fetchDictionaryAdd, + fetchDictionaryEdit, + fetchDictionaryItemAdd, + fetchDictionaryItemDelete, + fetchDictionaryItemEdit, + fetchTreeDictionaryItem +} from '@/service/api'; import { useFormRules, useNaiveForm } from '@/hooks/common/form'; import { $t } from '@/locales'; import DictionaryItem = Api.Sys.Core.DictionaryItem; @@ -50,8 +57,32 @@ interface Model { children: Api.Sys.Core.DictionaryItem[]; } +interface ChildrenOperateModel { + id: string | null; + name: string; + code: string; + sort: number; + description: string | null; +} + const model = ref(createDefaultModel()); +const childrenOperateModel = ref(createDefaultModel2()); + +const childrenModelVisible = ref(false); +const childrenTitle = ref(''); +const childrenModelOperateType = ref(''); + +function showChildrenModel(operateType: NaiveUI.TableOperateType, row: DictionaryItem | null = null) { + childrenModelOperateType.value = operateType; + childrenTitle.value = operateType === 'edit' ? $t('common.edit') : $t('common.add'); + childrenModelVisible.value = true; + childrenOperateModel.value = createDefaultModel2(); + if (row) { + Object.assign(childrenOperateModel.value, jsonClone(row)); + } +} + const childrenColumns: DataTableColumns = [ { key: 'name', @@ -76,14 +107,14 @@ const childrenColumns: DataTableColumns = [ title: $t('common.operate'), align: 'center', width: 80, - render: _ => { + render: (row, index) => { if (model.value.type === 'tree') { return (
{$t('common.children')} - + showChildrenModel('edit', row)}> {$t('common.edit')} @@ -94,12 +125,19 @@ const childrenColumns: DataTableColumns = [ } return (
- + showChildrenModel('edit', row)}> {$t('common.edit')} - - {$t('common.delete')} - + handleChildrenDelete(row, index)}> + {{ + default: () => $t('common.confirmDelete'), + trigger: () => ( + + {$t('common.delete')} + + ) + }} +
); } @@ -116,6 +154,16 @@ function createDefaultModel(): Model { }; } +function createDefaultModel2(): ChildrenOperateModel { + return { + id: null, + name: '', + code: '', + sort: 0, + description: null + }; +} + type RuleKey = 'name' | 'code' | 'type'; const rules: Record = { @@ -143,6 +191,40 @@ function handleInitChildrenModel() { }); } +function handleChildrenSubmit() { + const apiParams: Api.Sys.Core.DictionaryItemOp = { + dictionaryId: props.rowData?.id || '', + ...childrenOperateModel.value + }; + if (childrenModelOperateType.value === 'edit') { + // 编辑 + fetchDictionaryItemEdit(apiParams).then(() => { + window.$message?.success($t('common.updateSuccess')); + childrenModelVisible.value = false; + handleInitChildrenModel(); + }); + } else { + // 新增 + fetchDictionaryItemAdd(apiParams).then(() => { + window.$message?.success($t('common.updateSuccess')); + childrenModelVisible.value = false; + handleInitChildrenModel(); + }); + } +} + +function handleChildrenDelete(row: DictionaryItem, index: number) { + if (row.id) { + // 执行删除 + fetchDictionaryItemDelete(row.id).then(() => { + window.$message?.success($t('common.deleteSuccess')); + handleInitChildrenModel(); + }); + } else { + model.value.children = model.value.children.splice(index); + } +} + function closeDrawer() { visible.value = false; } @@ -204,10 +286,49 @@ watch(visible, () => { + + + + + + + + + + + + + + + +