| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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()
- // this.dicts.forEach(item=>{
- // this.getDictHandler(item,(res)=>{
- // this[item] = res
- // })
- // })
- }
- },
- methods: {
- ...mapActions(['setDict']),
- setDicts(){
- this.dicts.forEach(item=>{
- this.setDict(item)
- })
- },
- /** 获取字典值
- * 组件页面中需要设置:mapGetters(['dictionary']']),
- * */
- getDictItem(key){
- let item = this.dictionary?.find((v)=>{
- return v.key === key
- })
- return item?.value
- },
- //时间范围模板: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)
- })
- },
- }
- }
|