globalMixins.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { getDict } from '@/api/toConsult.js'
  2. import dayjs from 'dayjs'
  3. import Dicts from '../utils/dicts'
  4. import {mapActions} from 'vuex'
  5. export default {
  6. data() {
  7. return {
  8. }
  9. },
  10. created() {
  11. /** 组件中设置dicts数组,会将字典存储在vuex中*/
  12. if(this.dicts && this.dicts.length > 0){
  13. this.setDicts()
  14. }
  15. },
  16. methods: {
  17. ...mapActions(['setDict']),
  18. setDicts(){
  19. this.dicts.forEach(item=>{
  20. this.setDict(item)
  21. })
  22. },
  23. /** 获取字典值
  24. * key: String 字典类型
  25. * 组件页面中需要设置:mapGetters(['dictionary']']),
  26. * */
  27. getDictItem(key){
  28. let item = this.dictionary.find((v)=>{
  29. return v.key === key
  30. })
  31. console.log(item,'item')
  32. return item?.value
  33. },
  34. //查询字典具体类型的中的某一项
  35. getDictLabel(key,dictType){
  36. let item = this.dictionary?.find((v)=>{
  37. return v.key === dictType
  38. })
  39. let dictLabel = item?.value?.find(v=>{
  40. if( v.dictValue == key){
  41. return v?.dictLabel
  42. }
  43. })
  44. return dictLabel?.dictLabel
  45. },
  46. //时间范围模板:2020-01-01~2020-01-02
  47. rangDate(start,end,a){
  48. if(!start || !end) return '暂无';
  49. !a && (a = '~')
  50. return `${start}${a}${end}`;
  51. },
  52. //根据字典类型获取字典值
  53. getDictHandler(dictType,callBack) {
  54. getDict( dictType ).then(res => {
  55. let { data } = res
  56. callBack(data)
  57. })
  58. },
  59. }
  60. }