dict.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Created by 芋道源码
  3. *
  4. * 数据字典工具类
  5. */
  6. import store from '@/store'
  7. export const DICT_TYPE = {
  8. SYS_COMMON_STATUS: 'sys_common_status',
  9. SYS_MENU_TYPE: 'sys_menu_type',
  10. SYS_ROLE_TYPE: 'sys_role_type',
  11. SYS_DATA_SCOPE: 'sys_data_scope',
  12. SYS_USER_SEX: 'sys_user_sex',
  13. SYS_NOTICE_TYPE: 'sys_notice_type',
  14. SYS_OPERATE_TYPE: 'sys_operate_type',
  15. SYS_LOGIN_RESULT: 'sys_login_result',
  16. SYS_CONFIG_TYPE: 'sys_config_type',
  17. INF_REDIS_TIMEOUT_TYPE: 'inf_redis_timeout_type'
  18. }
  19. /**
  20. * 获取 dictType 对应的数据字典数组
  21. *
  22. * @param dictType 数据类型
  23. * @returns {*|Array} 数据字典数组
  24. */
  25. export function getDictDatas(dictType) {
  26. return store.getters.dict_datas[dictType] || []
  27. }
  28. export function getDictDataLabel(dictType, value) {
  29. // 获取 dictType 对应的数据字典数组
  30. const dictDatas = getDictDatas(dictType)
  31. if (!dictDatas || dictDatas.length === 0) {
  32. return ''
  33. }
  34. // 获取 value 对应的展示名
  35. value = value + '' // 强制转换成字符串,因为 DictData 小类数值,是字符串
  36. for (const dictData of dictDatas) {
  37. if (dictData.value === value) {
  38. return dictData.label
  39. }
  40. }
  41. return ''
  42. }