wwf
20 小时以前 e1b028d486713eaf55aaf35fbf334aa568059c0d
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
54
55
56
<template>
  <el-tag
    :round="round"
    :style="cssClass"
  >
    <el-text :style="{ color: cssClass.color }">
      {{ text }}
    </el-text>
  </el-tag>
</template>
<script>
import dictClassJson from '@/assets/json/dictClass.json'
export default {
  data() {
    return {
      list: []
    }
  },
  props: {
    valueKey: [String, Number],
    dictType: String,
    round: {
      type: Boolean,
      default: true
    }
  },
  created() {
    this.initList()
  },
  computed: {
    dictObj: function() {
      return this.list.find(ele => ele.value == this.valueKey) || {}
    },
    text: function() {
      return this.dictObj?.label || ''
    },
    cssClass: function() {
      let str = {}
      if (this.dictObj.colorType) {
        return dictClassJson[this.dictObj.colorType] || {}
      }
      try {
        str = JSON.parse(this.dictObj?.cssClass)
      } catch(error) {
        console.log()
      }
      return str
    }
  },
  methods: {
    initList() {
      this.list = this.$getDictData(this.dictType)
    }
  }
</script>