import { getAction } from '@/api/flowable/manage';

import store from '@/store';

export function formatDictText(dicts, values) {
  if (!(Array.isArray(dicts) && dicts.length > 0)) {
    return values;
  }
  if (!values) {
    return '';
  }
  let valueArr = values.split(',');
  let contentArr = [];
  dicts.forEach((dict) => {
    for (let i = 0; i < valueArr.length; i++) {
      if (valueArr[i] === dict.value) {
        contentArr.push(dict.content);
        break;
      }
    }
  });
  return contentArr.toString();
}

export function randomString(len) {
  len = len || 32;
  const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  const maxPos = $chars.length;
  let pwd = '';
  for (let i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}
// 深度拷贝
export function copyObj(obj) {
  //变量先置空
  let newobj = null;

  //判断是否需要继续进行递归
  if (typeof obj == 'object' && obj !== null) {
    newobj = obj instanceof Array ? [] : {}; //进行下一层递归克隆
    for (const i in obj) {
      newobj[i] = copyObj(obj[i]);
    } //如果不是对象直接赋值
  } else newobj = obj;
  return newobj;
}
