办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
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
<!-- eslint-disable eqeqeq -->
<script setup lang="ts">
import type { DictData } from '#/api/system/dict/dict-data-model';
 
import { computed } from 'vue';
 
import { Tag } from 'ant-design-vue';
 
import { tagTypes } from './data';
 
interface Props {
  dicts: DictData[]; // dict数组
  value: number | string; // value
}
 
const props = withDefaults(defineProps<Props>(), {
  dicts: undefined,
});
 
const color = computed<string>(() => {
  const current = props.dicts.find((item) => item.dictValue == props.value);
  const listClass = current?.listClass ?? '';
  // 是否为默认的颜色
  const isDefault = Reflect.has(tagTypes, listClass);
  // 判断是默认还是自定义颜色
  if (isDefault) {
    // 这里做了antd - element-plus的兼容
    return tagTypes[listClass]!.color;
  }
  return listClass;
});
 
const cssClass = computed<string>(() => {
  const current = props.dicts.find((item) => item.dictValue == props.value);
  return current?.cssClass ?? '';
});
 
const label = computed<number | string>(() => {
  const current = props.dicts.find((item) => item.dictValue == props.value);
  return current?.dictLabel ?? 'unknown';
});
 
const tagComponent = computed(() => (color.value ? Tag : 'div'));
</script>
 
<template>
  <div>
    <component :is="tagComponent" :class="cssClass" :color="color">
      {{ label }}
    </component>
  </div>
</template>