globalMixins.js 861 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { getDict } from '@/api/toConsult.js'
  2. import dayjs from 'dayjs'
  3. import Dicts from '../utils/dicts'
  4. export default {
  5. data() {
  6. return {
  7. //字典['dict_type']
  8. dicts:[]
  9. }
  10. },
  11. created() {
  12. /** 组件中设置dictType,即可获取相应的value*/
  13. if(this.dicts && this.dicts.length > 0){
  14. this.dicts.forEach(item=>{
  15. this.getDictHandler(item,(res)=>{
  16. this[item] = res
  17. })
  18. })
  19. }
  20. },
  21. computed:{
  22. },
  23. methods: {
  24. //时间范围模板:2020-01-01~2020-01-02
  25. rangDate(start,end,a){
  26. if(!start || !end) return '暂无';
  27. !a && (a = '~')
  28. return `${start}${a}${end}`;
  29. },
  30. //根据字典类型获取字典值
  31. getDictHandler(dictType,callBack) {
  32. getDict( dictType ).then(res => {
  33. let { data } = res
  34. callBack(data)
  35. })
  36. },
  37. }
  38. }