import {isExternal} from '@/utils/validate'
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
}

function isEmpty(str) {
  // 检查是否为 null 或 undefined
  if (str == null) return true;

  // 检查是否为字符串类型
  if (typeof str !== 'string') {
    // 如果不是字符串，尝试转换为字符串再判断
    return String(str).trim() === '';
  }

  // 字符串类型直接去除空格后判断
  return str.trim() === '';
}
