globalMixins.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { getDict } from '@/api/toConsult.js'
  2. import dayjs from 'dayjs'
  3. export default {
  4. data() {
  5. return {
  6. //字典['dict_type']
  7. dicts:[]
  8. }
  9. },
  10. created() {
  11. /** 组件中设置dictType,即可获取相应的value*/
  12. if(this.dicts && this.dicts.length > 0){
  13. this.dicts.forEach(item=>{
  14. this.getDictHandler(item,(res)=>{
  15. this[item] = res
  16. })
  17. })
  18. }
  19. },
  20. computed:{
  21. },
  22. methods: {
  23. //根据字典类型获取字典值
  24. getDictHandler(dictType,callBack) {
  25. getDict( dictType ).then(res => {
  26. let { code, data, msg } = res
  27. if (code == 200) {
  28. callBack(data)
  29. }
  30. })
  31. },
  32. //根据字典类型获取字典值,返回字典label
  33. getDicts(s,dict){
  34. console.log(this[dict],11111);
  35. //判断内存中是否有该字典,没有就去获取
  36. if( !this[dict]){
  37. getDict( dict ).then(res => {
  38. let { code, data } = res;
  39. if (code == 200) {
  40. this[dict] = data;
  41. //return this[dict].find(v=> s == v.dictValue).dictLabel;
  42. }
  43. })
  44. }else {
  45. return this[dict].find(v=> s == v.dictValue).dictLabel;
  46. }
  47. },
  48. }
  49. }