From a9082d8b6fecc16ae45d968c850fd7d7beee0f68 Mon Sep 17 00:00:00 2001 From: AhJindeg Date: Wed, 29 May 2024 15:18:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9E=20Add=20StringDictDataType?= =?UTF-8?q?=20type=20by=20imitating=20getIntDictOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dict.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/dict.ts b/src/utils/dict.ts index ab6e2923..9400208a 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -24,6 +24,10 @@ export interface NumberDictDataType extends DictDataType { value: number } +export interface StringDictDataType extends DictDataType { + value: string +} + export const getDictOptions = (dictType: string) => { return dictStore.getDictByType(dictType) || [] } @@ -44,8 +48,11 @@ export const getIntDictOptions = (dictType: string): NumberDictDataType[] => { } export const getStrDictOptions = (dictType: string) => { - const dictOption: DictDataType[] = [] + // 获得通用的 DictDataType 列表 const dictOptions: DictDataType[] = getDictOptions(dictType) + // 转换成 string 类型的 StringDictDataType 类型 + // why 需要特殊转换:避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时,el-option 的 key 会告警 + const dictOption: StringDictDataType[] = [] dictOptions.forEach((dict: DictDataType) => { dictOption.push({ ...dict,