| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | import { getDict } from '@/api/toConsult.js'import dayjs from 'dayjs'import Dicts from '../utils/dicts'export default {  data() {    return {      //字典['dict_type']      dicts:[]    }  },  created() {    /** 组件中设置dictType,即可获取相应的value*/    if(this.dicts && this.dicts.length > 0){      this.dicts.forEach(item=>{        this.getDictHandler(item,(res)=>{          this[item] = res        })      })    }  },  computed:{  },  methods: {    //时间范围模板:2020-01-01~2020-01-02    rangDate(start,end,a){      if(!start || !end) return '暂无';      !a && (a = '~')      return  `${start}${a}${end}`;    },    //根据字典类型获取字典值    getDictHandler(dictType,callBack) {      getDict( dictType ).then(res => {        let { code, data, msg } = res        if (code == 200) {            callBack(data)        }      })    },    //根据字典类型获取字典值,返回字典label    getDicts(s,dict){      console.log(this[dict],dict);      //判断内存中是否有该字典,没有就去获取      if( !this[dict]){        getDict( dict ).then(res => {          let { code, data } = res;          if (code == 200) {            this[dict] = data;            //return  this[dict].find(v=> s == v.dictValue).dictLabel;          }        })      }else {        return  this[dict].find(v=> s == v.dictValue).dictLabel;      }    },  }}
 |