index.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { getAuthCache } from '/@/utils/auth';
  2. import { DB_DICT_DATA_KEY } from '/@/enums/cacheEnum';
  3. import { defHttp } from '/@/utils/http/axios';
  4. /**
  5. * 从缓存中获取字典配置
  6. * @param code
  7. */
  8. export const getDictItemsByCode = (code) => {
  9. if (getAuthCache(DB_DICT_DATA_KEY) && getAuthCache(DB_DICT_DATA_KEY)[code]) {
  10. return getAuthCache(DB_DICT_DATA_KEY)[code];
  11. }
  12. };
  13. /**
  14. * 获取字典数组
  15. * @param dictCode 字典Code
  16. * @return List<Map>
  17. */
  18. export const initDictOptions = (code) => {
  19. //1.优先从缓存中读取字典配置
  20. if (getDictItemsByCode(code)) {
  21. return new Promise((resolve, reject) => {
  22. resolve(getDictItemsByCode(code));
  23. });
  24. }
  25. //2.获取字典数组
  26. //update-begin-author:taoyan date:2022-6-21 for: 字典数据请求前将参数编码处理,但是不能直接编码,因为可能之前已经编码过了
  27. if (code.indexOf(',') > 0 && code.indexOf(' ') > 0) {
  28. // 编码后类似sys_user%20where%20username%20like%20xxx' 是不包含空格的,这里判断如果有空格和逗号说明需要编码处理
  29. code = encodeURI(code);
  30. }
  31. //update-end-author:taoyan date:2022-6-21 for: 字典数据请求前将参数编码处理,但是不能直接编码,因为可能之前已经编码过了
  32. return defHttp.get({ url: `/sys/dict/getDictItems/${code}` });
  33. };
  34. /**
  35. * 获取字典数组
  36. * @param code 字典Code
  37. * @param params 查询参数
  38. * @param options 查询配置
  39. * @return List<Map>
  40. */
  41. export const ajaxGetDictItems = (code, params, options?) => defHttp.get({ url: `/sys/dict/getDictItems/${code}`, params }, options);