import { getDict } from '@/api/toConsult.js' import dayjs from 'dayjs' import Dicts from '../utils/dicts' import {mapActions} from 'vuex' export default { data() { return { } }, created() { /** 组件中设置dicts数组,会将字典存储在vuex中*/ if(this.dicts && this.dicts.length > 0){ this.setDicts() } }, methods: { ...mapActions(['setDict']), setDicts(){ this.dicts.forEach(item=>{ this.setDict(item) }) }, /** 获取字典值 * key: String 字典类型 * 组件页面中需要设置:mapGetters(['dictionary']']), * */ getDictItem(key){ let item = this.dictionary.find((v)=>{ return v.key === key }) console.log(item,'item') return item?.value }, //查询字典具体类型的中的某一项 getDictLabel(key,dictType){ let item = this.dictionary?.find((v)=>{ return v.key === dictType }) let dictLabel = item?.value?.find(v=>{ if( v.dictValue == key){ return v?.dictLabel } }) return dictLabel?.dictLabel }, //时间范围模板: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 { data } = res callBack(data) }) }, } }