jinlin
2023-11-03 35435e8b1995e6775c82b86652381e07e3faff54
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
<template>
  <el-tag :color="tagColor"  v-if="$store.getters.getDictLabel(dict, value)!=null" :type="tagType" :size="size" :effect="effect" :hit="hit">{{$store.getters.getDictLabel(dict, value)}}
  </el-tag>
</template>
<script>
  export default {
    name: 'ZtDictTag',
    props: {
      dict: { // 字典类型
        type: String,
        required: true
      },
      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: ''
      }
    },
    mounted() {
      this.init()
    },
    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 = 'info'
          }
        }
      }
    }
  }
</script>