From 255708beeccf08df33ab6b2a57750a0cd477a475 Mon Sep 17 00:00:00 2001 From: shizhong <124974919@qq.com> Date: Thu, 7 Mar 2024 12:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=20IDEA=20?= =?UTF-8?q?=E5=9C=A8=20`v-for=3D"dict=20in=20getIntDictOptions(...)"`=20?= =?UTF-8?q?=E6=97=B6=EF=BC=8C`el-option`=20=E7=9A=84=20`key`=20=E4=BC=9A?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dict.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 65d185b7..98ed9797 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -20,13 +20,20 @@ export interface DictDataType { cssClass: string } +export interface NumberDictDataType extends DictDataType { + value: number +} + export const getDictOptions = (dictType: string) => { return dictStore.getDictByType(dictType) || [] } -export const getIntDictOptions = (dictType: string): DictDataType[] => { - const dictOption: DictDataType[] = [] +export const getIntDictOptions = (dictType: string): NumberDictDataType[] => { + // 获得通用的 DictDataType 列表 const dictOptions: DictDataType[] = getDictOptions(dictType) + // 转换成 number 类型的 NumberDictDataType 类型 + // why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时,el-option 的 key 会告警 + const dictOption: NumberDictDataType[] = [] dictOptions.forEach((dict: DictDataType) => { dictOption.push({ ...dict,