util.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import store from '@/store';
  2. export function formatDictText(dicts, values) {
  3. if (!(Array.isArray(dicts) && dicts.length > 0)) {
  4. return values;
  5. }
  6. if (!values) {
  7. return '';
  8. }
  9. let valueArr = values.split(',');
  10. let contentArr = [];
  11. dicts.forEach((dict) => {
  12. for (let i = 0; i < valueArr.length; i++) {
  13. if (valueArr[i] === dict.value) {
  14. contentArr.push(dict.content);
  15. break;
  16. }
  17. }
  18. });
  19. return contentArr.toString();
  20. }
  21. export function randomString(len) {
  22. len = len || 32;
  23. const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  24. /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  25. const maxPos = $chars.length;
  26. let pwd = '';
  27. for (let i = 0; i < len; i++) {
  28. pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  29. }
  30. return pwd;
  31. }
  32. // 深度拷贝
  33. export function copyObj(obj) {
  34. //变量先置空
  35. let newobj = null;
  36. //判断是否需要继续进行递归
  37. if (typeof obj == 'object' && obj !== null) {
  38. newobj = obj instanceof Array ? [] : {}; //进行下一层递归克隆
  39. for (const i in obj) {
  40. newobj[i] = copyObj(obj[i]);
  41. } //如果不是对象直接赋值
  42. } else newobj = obj;
  43. return newobj;
  44. }