|
|
@@ -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>
|