Skip to content

Commit aecc9bb

Browse files
committed
🐛 修复 IDEA 在 v-for="dict in getIntDictOptions(...)" 时,el-optionkey 会告警的问题
1 parent 3d2d48b commit aecc9bb

37 files changed

+56
-49
lines changed

src/utils/dict.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ export interface DictDataType {
2020
cssClass: string
2121
}
2222

23+
export interface NumberDictDataType extends DictDataType {
24+
value: number
25+
}
26+
2327
export const getDictOptions = (dictType: string) => {
2428
return dictStore.getDictByType(dictType) || []
2529
}
2630

27-
export const getIntDictOptions = (dictType: string): DictDataType[] => {
28-
const dictOption: DictDataType[] = []
31+
export const getIntDictOptions = (dictType: string): NumberDictDataType[] => {
32+
// 获得通用的 DictDataType 列表
2933
const dictOptions: DictDataType[] = getDictOptions(dictType)
34+
// 转换成 number 类型的 NumberDictDataType 类型
35+
// why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时,el-option 的 key 会告警
36+
const dictOption: NumberDictDataType[] = []
3037
dictOptions.forEach((dict: DictDataType) => {
3138
dictOption.push({
3239
...dict,

src/views/infra/config/ConfigForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<el-radio-group v-model="formData.visible">
2424
<el-radio
2525
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
26-
:key="dict.value"
26+
:key="dict.value as string"
2727
:label="dict.value"
2828
>
2929
{{ dict.label }}

src/views/system/dept/DeptForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<el-select v-model="formData.status" clearable placeholder="请选择状态">
4545
<el-option
4646
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
47-
:key="dict.value as number"
47+
:key="dict.value"
4848
:label="dict.label"
4949
:value="dict.value"
5050
/>

src/views/system/dept/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
>
2626
<el-option
2727
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
28-
:key="dict.value as number"
28+
:key="dict.value"
2929
:label="dict.label"
3030
:value="dict.value"
3131
/>

src/views/system/dict/DictTypeForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<el-radio-group v-model="formData.status">
2222
<el-radio
2323
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
24-
:key="dict.value as number"
24+
:key="dict.value"
2525
:label="dict.value"
2626
>
2727
{{ dict.label }}

src/views/system/dict/data/DictDataForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<el-radio-group v-model="formData.status">
2828
<el-radio
2929
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
30-
:key="dict.value as number"
30+
:key="dict.value"
3131
:label="dict.value"
3232
>
3333
{{ dict.label }}

src/views/system/dict/data/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<el-select v-model="queryParams.status" placeholder="数据状态" clearable class="!w-240px">
3131
<el-option
3232
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
33-
:key="dict.value as number"
33+
:key="dict.value"
3434
:label="dict.label"
3535
:value="dict.value"
3636
/>

src/views/system/dict/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
>
3636
<el-option
3737
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
38-
:key="dict.value as number"
38+
:key="dict.value"
3939
:label="dict.label"
4040
:value="dict.value"
4141
/>

src/views/system/errorCode/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<el-select v-model="queryParams.type" placeholder="请选择错误码类型" clearable>
1515
<el-option
1616
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_ERROR_CODE_TYPE)"
17-
:key="dict.value as number"
17+
:key="dict.value"
1818
:label="dict.label"
1919
:value="dict.value"
2020
class="!w-240px"

src/views/system/menu/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
>
3030
<el-option
3131
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
32-
:key="dict.value as number"
32+
:key="dict.value"
3333
:label="dict.label"
3434
:value="dict.value"
3535
/>

0 commit comments

Comments
 (0)