jinlin
2024-06-06 8c834663344b1cc9c2ca569e6911900edd407f73
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
  <el-tag :color="tagColor" :type="tagType" :size="size" :effect="effect" :hit="hit">{{dictLabel}}
  </el-tag>
</template>
<script>
  export default {
    name: 'ZtDictTag',
    props: {
      dict: { // 字典类型
        type: String,
        required: true
      },
      additional: {// 添加的
        type: Array,
        default: function () {
          return []
        }
      },
      value: [String, Number, Boolean],
      typeS: String,
      typeI: String,
      typeW: String,
      typeD: String,
      typeColor: Object,
      size: {
        type: String,
        default: 'small'
      },
      effect: {
        type: String,
        default: 'light'
      },
      hit: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        tagType: 'primary',
        tagColor: '',
        colorArr: ['primary', 'success', 'info', 'warning', 'danger']
      }
    },
    mounted() {
      this.init()
    },
    computed: {
      dictLabel() {
        let result = this.$store.getters.getDictLabel(this.dict, this.value)
        if ("" + result == "" + this.value) {
          for (let item of this.additional) {
            if (item.dictValue == "" + this.value) {
              result = item.dictLabel
            }
          }
        }
        return result
      }
    },
    methods: {
      async init() {
        let value = this.value + ''
 
        if (this.typeS && this.typeS.split(',').indexOf(value) >= 0) {
          this.tagType = 'success'
        }
        if (this.typeI && this.typeI.split(',').indexOf(value) >= 0) {
          this.tagType = 'info'
        }
        if (this.typeW && this.typeW.split(',').indexOf(value) >= 0) {
          this.tagType = 'warning'
        }
        if (this.typeD && this.typeD.split(',').indexOf(value) >= 0) {
          this.tagType = 'danger'
        }
        if (this.typeColor && this.typeColor[value]) {
          this.tagColor = this.typeColor[value]
        }
        if (!this.typeS && !this.typeI && !this.typeW && !this.typeD && !this.typeColor) { // 没有指定颜色
          if (this.value === false || this.value === 0 || this.value === '0' || this.value === 'false') {
            this.tagType = 'primary'
          } else {
            this.tagType = this.colorArr[this.value % 5]
          }
        }
      }
    }
  }
</script>