From d57f6838a3d1f2b64475befc0092a18351a5c4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E6=A0=A1=E4=BA=91?= <14135925+chenxilxy@user.noreply.gitee.com> Date: Mon, 15 Dec 2025 00:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=89=B9=E9=A1=B5=E9=9D=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Dict/DictLabel.vue | 38 +++++++--- src/components/Notification/ApprovalForm.vue | 59 ++++++++++++++++ src/components/Notification/index.vue | 69 ++++++++++++++----- .../NavBar/components/NavbarActions.vue | 2 - .../system/notice/components/MyNotice.vue | 63 ++++++++++------- 5 files changed, 180 insertions(+), 51 deletions(-) create mode 100644 src/components/Notification/ApprovalForm.vue diff --git a/src/components/Dict/DictLabel.vue b/src/components/Dict/DictLabel.vue index 61ab570..8391618 100644 --- a/src/components/Dict/DictLabel.vue +++ b/src/components/Dict/DictLabel.vue @@ -32,25 +32,47 @@ const getLabelAndTagByValue = async (dictCode: string, value: any) => { // 按需加载字典数据 await dictStore.loadDictItems(dictCode) // 从缓存中获取字典数据 - const dictItems = dictStore.getDictItems(dictCode) + const response: any = dictStore.getDictItems(dictCode) + + // 处理API响应格式 + let dictItems = [] + if (Array.isArray(response)) { + dictItems = response + } else if (response && typeof response === 'object' && Array.isArray(response.data)) { + dictItems = response.data + } else { + console.warn(`Dictionary items for code "${dictCode}" is not in expected format:`, response) + return { + label: '', + tagType: undefined + } + } + // 查找对应的字典项 - const dictItem = dictItems.find((item) => item.value == value) + const dictItem = dictItems.find((item: any) => item.value == value) return { label: dictItem?.label || '', tagType: dictItem?.tagType } } + /** * 更新 label 和 tagType */ const updateLabelAndTag = async () => { if (!props.code || props.modelValue === undefined) return - const { label: newLabel, tagType: newTagType } = await getLabelAndTagByValue( - props.code, - props.modelValue - ) - label.value = newLabel - tagType.value = newTagType as typeof tagType.value + try { + const { label: newLabel, tagType: newTagType } = await getLabelAndTagByValue( + props.code, + props.modelValue + ) + label.value = newLabel + tagType.value = newTagType as typeof tagType.value + } catch (error) { + console.error('Failed to update dict label:', error) + label.value = '' + tagType.value = undefined + } } // 初始化或code变化时更新标签和标签样式 diff --git a/src/components/Notification/ApprovalForm.vue b/src/components/Notification/ApprovalForm.vue new file mode 100644 index 0000000..3bc9985 --- /dev/null +++ b/src/components/Notification/ApprovalForm.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/components/Notification/index.vue b/src/components/Notification/index.vue index 3db62d7..ee5083e 100644 --- a/src/components/Notification/index.vue +++ b/src/components/Notification/index.vue @@ -10,19 +10,20 @@