/**
* 获取本地图
* @param name // 文件名 如 doc.png
* @returns {*|string}
*/
export function getAssetsImages(name: string, path: string = '') {
    return new URL(`/src/assets/img${path}/${name}`, import.meta.url).href;
}

/**
 * 是否外部路径
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path: string) {
    const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path);
    return isExternal;
}

/**
 * 
 * @param value 
 * @param data 
 * @returns 
 */
export function formatLabel(value: string | number, data: Array<Option>) {
    const item = data.find(v => v.value === value)
    if (!item) return ''
    return item.label
}

export function autoCompleteNo(num: number, pageBean: any) {
    const no = (pageBean.page - 1) * pageBean.pageSize + num
    // if (no > 0 && no < 10) return '00' + no
    // if (no > 9 && no < 100) return '0' + no
    return no
}

export function validFloat(value:any, bool:boolean) {
    if (bool && (value === undefined || value === '' || value === null)) {
      return false
    } else if (value) {
      //校验输入的保证金的金额是否正确
      var pattern = /^(-?\d+)(\.\d+)?$/;
      if (!pattern.test(value)) {
        return false
      }
    }
    return true
  }


interface Option {
    name: string;
    age?: number;
    [propName: string]: any;
}