Переглянути джерело

chore: 字典组件匹配失败时原文显示

喵你个旺呀 1 рік тому
батько
коміт
1e3943a865
1 змінених файлів з 13 додано та 8 видалено
  1. 13 8
      Web/src/components/table/dictLabel.vue

+ 13 - 8
Web/src/components/table/dictLabel.vue

@@ -1,5 +1,6 @@
 <template>
-	<el-Tag :type="state.tagType">{{ state.label }}</el-Tag>
+	<el-Tag v-if="state.dict" :type="state.dict.tagType ?? 'primary'">{{ state.dict[props.propLabel] ?? props.defaultValue }}</el-Tag>
+  <span v-else>{{ props.value }}</span>
 </template>
 
 <script lang="ts" setup>
@@ -23,9 +24,16 @@ const props = defineProps({
 	},
 });
 
+const tagTypeMap = {
+  "success": 1,
+  "warning": 1,
+  "info": 1,
+  "primary": 1,
+  "danger": 1
+} as any;
+
 const state = reactive({
-	label: props.defaultValue as string,
-	tagType: "primary" as "success" | "warning" | "info" | "primary" | "danger"
+  dict: null as any,
 });
 
 onMounted(() => {
@@ -38,10 +46,7 @@ watch(
 );
 
 const setDictValue = (value: any) => {
-  const dict = useUserInfo().dictList[props.code]?.find((x: any) => x[props.propValue] == value);
-  if (dict) {
-    state.label = dict[props.propLabel] || props.defaultValue;
-    state.tagType = dict.tagType ?? "primary";
-  }
+  state.dict = useUserInfo().dictList[props.code]?.find((x: any) => x[props.propValue] == value);
+  if (state.dict != null && !tagTypeMap[state.dict.tagType]) state.dict.tagType = "primary";
 }
 </script>