dict.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // 系统全局字典
  2. import useDictStore from '@/stores/modules/dict'
  3. import { getDictsApi } from '@/api/modules/system/dictData'
  4. import { ref, toRefs } from 'vue'
  5. /**
  6. * 获取字典数据
  7. */
  8. export function useDict(...args: any[]) {
  9. const res = ref<any>({})
  10. return (() => {
  11. args.forEach(dictType => {
  12. res.value[dictType] = []
  13. const dicts = useDictStore().getDict(dictType)
  14. if (dicts) {
  15. res.value[dictType] = dicts
  16. } else {
  17. getDictsApi(dictType).then(resp => {
  18. res.value[dictType] = resp.data.map((p: any) => ({
  19. label: p.dictLabel,
  20. value: p.dictValue,
  21. elTagType: p.listClass,
  22. elTagClass: p.cssClass
  23. }))
  24. useDictStore().setDict(dictType, res.value[dictType])
  25. })
  26. }
  27. })
  28. return toRefs(res.value)
  29. })()
  30. }
  31. /**
  32. * @description:用户性别
  33. */
  34. export const genderType = [
  35. { label: '男', value: 1 },
  36. { label: '女', value: 2 }
  37. ]
  38. /**
  39. * @description:用户状态
  40. */
  41. export const userStatus = [
  42. { label: '启用', value: 1, tagType: 'success' },
  43. { label: '禁用', value: 0, tagType: 'danger' }
  44. ]