wente
2024-06-07 4bff52e938ae2c260fe54d32ef680908868bb27e
web/packages/components/zt-dict-tag/src/zt-dict-tag.vue
@@ -1,5 +1,5 @@
<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 :color="tagColor" :type="tagType" :size="size" :effect="effect" :hit="hit">{{dictLabel}}
  </el-tag>
</template>
<script>
@@ -9,6 +9,12 @@
      dict: { // 字典类型
        type: String,
        required: true
      },
      additional: {// 添加的
        type: Array,
        default: function () {
          return []
        }
      },
      value: [String, Number, Boolean],
      typeS: String,
@@ -33,11 +39,24 @@
      return {
        tagType: 'primary',
        tagColor: '',
        colorArr:['primary','success','info','warning','danger']
        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() {
@@ -61,8 +80,8 @@
        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]
          } else {
            this.tagType = this.colorArr[this.value % 5]
          }
        }
      }