Просмотр исходного кода

!1465 增强字典组件功能
Merge pull request !1465 from 喵你个汪/jasondom-next

zuohuaijun 1 год назад
Родитель
Сommit
8f5e0f79c8
1 измененных файлов с 31 добавлено и 8 удалено
  1. 31 8
      Web/src/components/table/dictLabel.vue

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

@@ -1,17 +1,40 @@
 <template>
-	<ElTag :type="dict?.tagType ?? ''">{{ dict?.name ?? defaultValue ?? '-' }}</ElTag>
+	<el-Tag :type="state.tagType ?? ''">{{ state.label }}</el-Tag>
 </template>
 
 <script lang="ts" setup>
 import { useUserInfo } from '/@/stores/userInfo';
-import { reactive } from 'vue';
+import { reactive, onMounted } from 'vue';
 import { ElTag } from 'element-plus';
 
-const props = defineProps<{
-	code: string;
-	value: any;
-	defaultValue: string
-}>();
+const props = defineProps({
+	code: String,
+	value: Object,
+	propLabel: {
+		type: String,
+		default: 'name'
+	},
+	propValue: {
+		type: String,
+		default: 'value'
+	},
+	defaultValue: {
+		type: String,
+		default: '-'
+	},
+});
 
-const dict = reactive(useUserInfo().getDictLabelByVal(props.code, props.value + ""));
+const state = reactive({
+  label: '' as string,
+	tagType: '' as string
+});
+
+onMounted(() => {
+	const dictList = useUserInfo().getDictDatasByCode(props.code);
+	const dict = dictList?.find(x => x[props.propValue] == props.value + "") ?? {};
+	if (dict) {
+		state.label = dict[props.propLabel] || props.defaultValue;
+		state.tagType = dict.tagType;
+	}
+})
 </script>