移动系统liao
3 天以前 a737f5caf67b75abec3e89296c4321ea6d31bd9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
    <el-Tag v-if="state.dict" :type="state.dict.tagType ?? 'primary'" :style="state.dict.styleSetting" :class="state.dict.classSetting">{{ state.dict[props.propLabel] ?? props.defaultValue }}</el-Tag>
  <span v-else>{{ props.value }}</span>
</template>
 
<script lang="ts" setup>
import { useUserInfo } from '/@/stores/userInfo';
import { reactive, onMounted, watch } from 'vue';
 
const props = defineProps({
    code: String,
    value: null,
    propLabel: {
        type: String,
        default: 'label',
    },
    propValue: {
        type: String,
        default: 'value',
    },
    defaultValue: {
        type: String,
        default: '-',
    },
});
 
const tagTypeMap = {
  "success": 1,
  "warning": 1,
  "info": 1,
  "primary": 1,
  "danger": 1
} as any;
 
const state = reactive({
  dict: null as any,
});
 
onMounted(() => {
  console.warn('DictLabel组件将在不久后移除,请使用新组件:https://gitee.com/zuohuaijun/Admin.NET/pulls/1559');
  setDictValue(props.value);
});
 
watch(
    () => props.value,
    (newValue) => setDictValue(newValue)
);
 
const setDictValue = (value: any) => {
  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>