UNPKG

sm-tool

Version:

sm-tool工具包

61 lines (40 loc) 35.1 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('compressorjs'), require('rxjs'), require('clipboard')) : typeof define === 'function' && define.amd ? define(['exports', 'compressorjs', 'rxjs', 'clipboard'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["sm-tool"] = {}, global.e, global.rxjs, global.o)); })(this, (function (exports, e, rxjs, o) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var e__default = /*#__PURE__*/_interopDefaultLegacy(e); var o__default = /*#__PURE__*/_interopDefaultLegacy(o); class StringUtil{static hasLength(t){return null!=t&&("string"==typeof t&&0!=(null==t?void 0:t.length)||"number"==typeof t)}static subStringWith(t,e,r){if(!(t&&t.includes(e)&&t.includes(r)))return "";const n=t.indexOf(e)+e.length,i=t.indexOf(r);return n<i?t.substring(n,i):""}static isNumberString(t,e){return StringUtil.hasLength(t)&&(e?/^\d+(\.\d+)?$/.test(t):/^\d+$/.test(t))}static jointStr2Arr(t,e=","){return t?(e||(e=","),t.includes(e)?t.split(e):[t]):[]}static trimAll(t){return StringUtil.hasLength(t)?t.replace(/\s/g,""):""}static desensitized(t,e,r,n="*"){if(!t)return "";if(e<0&&(e=0),e>=t.length&&(e=t.length-1),r<0&&(r=0),r>t.length&&(r=t.length),e>r){const t=e;e=r,r=t;}let i="";for(let t=0;t<(r-e||1);t++)i+=n||"";return t.substring(0,e)+i+t.substring(r)}static hasEmojiCharacter(t){let e;if(!t)return !1;if((null==t?void 0:t.length)>0)for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);if(55296<=n&&n<=56319){if(t.length>1){e=t.charCodeAt(r+1);const i=1024*(n-55296)+(e-56320)+65536;if(118784<=i&&i<=128895)return !0}}else if(t.length>1){if(e=t.charCodeAt(r+1),8419==e)return !0}else {if(8448<=n&&n<=10239)return !0;if(11013<=n&&n<=11015)return !0;if(10548<=n&&n<=10549)return !0;if(12951<=n&&n<=12953)return !0;if(169==n||174==n||12349==n||12336==n||11093==n||11036==n||11035==n||11088==n)return !0}}return !1}} class DictUtil{static obj2ItemArray(t,e="value",r="text"){return t?Object.keys(t).map((n=>({[e]:n,[r]:t[n],o:{[e]:n,[r]:t[n]}}))):[]}static objArray2TextValueArray(t,e="key",r="value",n="list",s="key",l="value"){var o;if(!t||0==t.length)return [];let a=[];for(let u of t){let t=[],i=u.hasOwnProperty(n);if(i){let e=u[n];if(e&&e.length>0)for(let r of e)r.hasOwnProperty(s)&&r.hasOwnProperty(l)&&t.push({value:r[s],text:r[l],o:{value:r[s],text:r[l],o:r}});}if(u.hasOwnProperty(e)&&u.hasOwnProperty(r)){let n={value:u[e],text:u[r],o:{value:u[e],text:u[r],o:u,subArr:t}};if(!i)try{null===(o=null==n?void 0:n.o)||void 0===o||delete o.subArr;}catch(t){console.warn(t);}a.push(n);}}return a}static objArray2KvOptsRecursive(t,e="value",r="value",n="label",s="text",l="children",o="children"){return Array.isArray(t)&&t.length>0?t.map((t=>{if(!t.hasOwnProperty(r)&&t.hasOwnProperty(e)&&(t[r]=t[e],delete t[e]),!t.hasOwnProperty(s)&&t.hasOwnProperty(n)&&(t[s]=t[n],delete t[n]),!t.hasOwnProperty(o)&&t.hasOwnProperty(l)&&(t[o]=t[l],delete t[l]),t[o]&&t[o].length>0)t[o]=DictUtil.objArray2KvOptsRecursive(t[o],e,r,n,s,l,o);else try{delete t[o];}catch(t){console.warn(t);}return t})):[]}static k2v(t,e,r="value",n="text"){const s=(e||[]).find((e=>e[r]===t));return s?s[n]:""}static k2Item(t,e,r="value"){return (e||[]).find((e=>e[r]===t))}static v2k(t,e,r="value",n="text"){const s=e||[];let l=0,o=null;for(const e of s)t===e[n]&&(o=e[r],l++);return 1===l?o:null}static getTextsByKeys(t,e,r="value",n="text",s="children"){return DictUtil.getValuesOrItemsByKeys(t,e,!1,r,n,s)}static getItemsByKeys(t,e,r="value",n="text",s="children"){return DictUtil.getValuesOrItemsByKeys(t,e,!0,r,n,s)}static getValuesOrItemsByKeys(t,e,r=!1,n="value",s="text",l="children"){const o=[],a=(e||{length:0}).length;for(let t=0;t<a;t++)o.push(void 0);if(!(t&&t.length>0&&(e||{length:0}).length>0))return o;const u=new Map,i=t=>{t&&t.length>0&&t.forEach((t=>{u.set(t[n],r?t:t[s]),i(t[l]);}));};return i(t),e.map((t=>u.get(t)))}static obj2SvInfoArray(t){return t?Object.keys(t).map((e=>({v:e,s:t[e],o:{v:e,s:t[e]}}))):[]}static objArray2SvInfoArray(t,e="key",r="value",n="list",s="key",l="value"){if(!t||0==t.length)return [];let o=[];for(let a of t){let t=[],u=a.hasOwnProperty(n);if(u){let e=a[n];if(e&&e.length>0)for(let r of e)r.hasOwnProperty(s)&&r.hasOwnProperty(l)&&t.push({v:r[s],s:r[l],o:{v:r[s],s:r[l],o:r}});}if(a.hasOwnProperty(e)&&a.hasOwnProperty(r)){let n={v:a[e],s:a[r],o:{v:a[e],s:a[r],o:a,subSvInfos:t}};if(!u)try{delete n.o.subSvInfos;}catch(t){console.warn(t);}o.push(n);}}return o}static k2vSVInfo(t,e){const r=(e||[]).find((e=>e.v===t));return r?r.s:""}static k2SVInfo(t,e){return (e||[]).find((e=>e.v===t))}static v2kSVInfo(t,e){const r=e||[];let n=0,s=null;for(const{v:t,s:e}of r)t===e&&(s=t,n++);return 1===n?s:null}static topUpKvOpts(t,e,r="value"){if(!(t&&t.length>0&&e))return t;const n=t.findIndex((t=>t[r]===e));if(-1===n)return t;const s=t[0];return t[0]=t[n],t[n]=s,t}static jointStr2Arr(e,r=","){return StringUtil.jointStr2Arr(e,r)}} exports.PlatformType = void 0;!function(e){e[e.IOS_TYPE=1]="IOS_TYPE",e[e.ANDROID_TYPE=2]="ANDROID_TYPE",e[e.OTHER_TYPE=3]="OTHER_TYPE",e[e.WeiXinBrowser_TYPE=4]="WeiXinBrowser_TYPE";}(exports.PlatformType||(exports.PlatformType={}));class OtherUtil{static debounce(e,t=300,r="_custom_debounce"){const o=Symbol.for(r);let n=window[o];const i=(e,t)=>{t&&n&&clearTimeout(n),n=e,window[o]=e;};return function(){n&&i(void 0,!0),i(setTimeout(e,t));}}static throttle(e,t=300,r="_custom_throttle"){const o=Symbol.for(r);let n=window[o];const i=e=>{n=e,window[o]=e;};return null==n&&i(0),function(){const r=(new Date).getTime();r-n>t&&(e(),i(r));}}static logThisData(e){if(!e)return void console.warn("没有传入_this参数");const t={};Object.keys(e).filter((t=>!(t.startsWith("$")||t.startsWith("_")||e[t]instanceof Function||-1!==["options","route"].indexOf(t)||t.endsWith("Util")))).forEach((r=>t[r]=e[r]));let r=e.route;r.includes("/")&&(r=r.split("/"),r.length>=2&&"index"===r[r.length-1]&&(r=r[r.length-2])),console.log(`【${r}】数据:`,t);}static deepCopy(e){let t=e;if(Array.isArray(e)){t=[];for(let r=0;r<e.length;r++)t.push(this.deepCopy(e[r]));}else {if("object"!=typeof e||null==e)return t;t={};for(let r in e)t[r]=this.deepCopy(e[r]);}return t}static deleteAttributes(e,t=[],r){try{if(r){if("object"==typeof e&&null!=e)for(const r in e)e.hasOwnProperty(r)&&(null==t?void 0:t.indexOf(r))>-1&&delete e[r];}else if(Array.isArray(e))for(const o of e)this.deleteAttributes(o,t,r);else if("object"==typeof e&&null!=e)for(const o in e)e.hasOwnProperty(o)&&((null==t?void 0:t.indexOf(o))>-1?delete e[o]:this.deleteAttributes(e[o],t,r)),this.deleteAttributes(e[o],t,r);}catch(e){console.warn(e);}}static slimApiData(e,t=30){try{if(Array.isArray(e))for(let r=0;r<e.length;r++)e[r]=this.slimApiData(e[r],t);else if("object"==typeof e&&null!=e)for(const r in e)e.hasOwnProperty(r)&&(e[r]=this.slimApiData(e[r],t));else if("string"==typeof e&&(null==e?void 0:e.length)>t)return e.substring(0,t)}catch(e){console.warn(e);}return e}static generateApiInterface(e,t={},r=[],o="@"){const n=(e,t={},r=[],o="@")=>{if(e){if("object"==typeof e){for(const i in e)if(e.hasOwnProperty(i)){const s=e[i];if("string"==typeof s)t[i]=`${o}string; // "${s}"${o}`;else if("number"==typeof s)t[i]=`${o}number; // ${s}${o}`;else if("boolean"==typeof s)t[i]=`${o}boolean; // ${s}${o}`;else if(s){if(Array.isArray(s))if(0===s.length)t[i]=`${o}any[]${o}`;else {const e=s[0];"string"==typeof e?t[i]=`${o}string[]; // [${s}]${o}`:"number"==typeof e?t[i]=`${o}number[]; // [${s}]${o}`:"boolean"==typeof e?t[i]=`${o}boolean[]; // [${s}]${o}`:e||(t[i]=`${o}any[]; // [${s}]${o}`);}else if("object"==typeof s){const e="I"+i.charAt(0).toUpperCase()+i.substring(1);r.push(`export interface ${e} {}`),t[i]=n(s,t[i],r,o);}}else t[i]=`${o}any; // ${s}${o}`;}}else console.error("必须传入object类型");return t}},i=n(e,t,r,o);return i?{templateApi:i,subInterfaceArrStr:r.join("\n")}:{templateApi:null,subInterfaceArrStr:""}}static unquoteKeys(e){return e.replace(/"(\\[^]|[^\\"])*"\s*:?/g,(e=>/:$/.test(e)?e.replace(/^"|"(?=\s*:$)/g,""):e))}static getJsType(e){return Object.prototype.toString.call(e).slice(8,-1)}static isArrayHasLength(e){return e&&Array.isArray(e)&&e.length>0}static getSystemPlatformType(){return /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)?exports.PlatformType.IOS_TYPE:/(Android)/i.test(navigator.userAgent)?exports.PlatformType.ANDROID_TYPE:exports.PlatformType.OTHER_TYPE}static isPlatformWeiXinBrowser(){return /micromessenger/i.test(navigator.userAgent)}static filterMoney(e,t){let r="";for(let t of e)"0123456789.".indexOf(t)>-1&&(r+=t);let o=r.indexOf(".");o>-1&&(r=r.replace(/\./g,""),r=r.slice(0,o)+"."+r.slice(o));/(^[1-9][0-9]*$|^0$)|((^[1-9][0-9]*|^0)[\.](\d)*$)/.test(r)||(r=r.slice(0,-1));let n=/\d+\.(\d*)$/g.exec(r);return n&&n.length>0&&n[1].length>t&&(r=r.slice(0,-1)),r}static deepToRaw(e,t=(e=>e)){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map((e=>OtherUtil.deepToRaw(e,t)));const r=t(e);for(const o in e)e.hasOwnProperty(o)&&(r[o]=OtherUtil.deepToRaw(e[o],t));return r}} class DataConverterUtil{static convert2ObjIfNeed(e){if("string"==typeof e)try{return JSON.parse(e)}catch(t){return console.log("转换Json字符串失败"),e}return e}static convert2UrlParams(e){if(!e)return "";let t="";for(const n of Object.keys(e)){const i=e[n];var r=encodeURIComponent(n)+"=";if(null!==i&&""!==i&&void 0!==i)if("object"==typeof i){for(const e of Object.keys(i))if(null!==i[e]&&""!==i[e]&&void 0!==i[e]){t+=encodeURIComponent(n+"["+e+"]")+"="+encodeURIComponent(i[e])+"&";}}else t+=r+encodeURIComponent(i)+"&";}return t}static getParamFromUrl(e,t){if(!e||!/[?]/.test(e))return null;const r=e.split("?")[1].split("&");let n={};for(let e=0;e<r.length;e++){const t=r[e].split("=");n[t[0]]=t.length>1?t[1]:"";}return t?n[t]:n}static jointStr2Arr(t,r=","){return StringUtil.jointStr2Arr(t,r)}static format2Percent(e,t=2){if(null==e)return "";if(0==e)return 0;if((e+"").endsWith("%"))return e;null==t&&(t=2);try{let r=Number(e);return isNaN(r)?e:(100*r).toFixed(t).replace(".00","")+"%"}catch(e){console.error("转换百分数失败",e);}}static formatPercent2Decimal(e,t=2){if(null==e)return 0;if((null==t||t<0)&&(t=2),"number"==typeof e)return Number(Number(e).toFixed(t));if("string"==typeof e){if(/%$/.test(e)){let r=Number(e.substring(0,e.length-1));if(!isNaN(r))return Number((r/100).toFixed(t))}if(!isNaN(Number(e)))return Number(Number(e).toFixed(t))}return 0}static format2Currency(e,t=""){return null==e?"":(e+"").replace(/\B(?=(\d{3})+$)/g,",")+t}static deepMergeWithDedupe(e,t){if(Array.isArray(e)&&Array.isArray(t)){const r=[...e,...t].reduce(((e,t)=>{const r=DataConverterUtil.findIndex(e,(e=>DataConverterUtil.isSameTypeElement(e,t)));return r>-1?e[r]=DataConverterUtil.deepMergeWithDedupe(e[r],t):e.push(DataConverterUtil.deepClone(t)),e}),[]);return DataConverterUtil.deduplicateArray(r)}if(DataConverterUtil.isPlainObject(e)&&DataConverterUtil.isPlainObject(t)){const r=Object.assign({},e);for(const e of Object.keys(t)){const n=t[e];e in r&&null!=n?r[e]=DataConverterUtil.deepMergeWithDedupe(r[e],n):null!=DataConverterUtil.deepClone(n)&&(r[e]=DataConverterUtil.deepClone(n));}return r}return DataConverterUtil.deepClone(t)}}DataConverterUtil.isPlainObject=e=>"[object Object]"===Object.prototype.toString.call(e),DataConverterUtil.isSameTypeElement=(e,t)=>typeof e==typeof t&&(Array.isArray(e)===Array.isArray(t)&&(DataConverterUtil.isPlainObject(e)&&DataConverterUtil.isPlainObject(t)?JSON.stringify(e)===JSON.stringify(t):e===t)),DataConverterUtil.deduplicateArray=e=>e.filter(((t,r,n)=>r===DataConverterUtil.findIndex(e,(e=>JSON.stringify(e)===JSON.stringify(t))))),DataConverterUtil.deepClone=e=>void 0===e?void 0:JSON.parse(JSON.stringify(e)),DataConverterUtil.findIndex=(e,t)=>{for(let r=0;r<e.length;r++)if(t(e[r]))return r;return -1}; class DateUtil{static dateFormat(e,t="yyyy-MM-dd"){if(null==e)return "";const r={Year:0,TYear:"0",Month:0,TMonth:"0",Day:0,TDay:"0",Hour:0,THour:"0",hour:0,Thour:"0",Minute:0,TMinute:"0",Second:0,TSecond:"0",Millisecond:0};let i;return i="number"==typeof e?new Date(e):"string"==typeof e?new Date(DateUtil.compatibleDateOfIos(e)):e,r.Year=i.getFullYear(),r.TYear=String(r.Year).substr(2),r.Month=i.getMonth()+1,r.TMonth=r.Month<10?"0"+r.Month:String(r.Month),r.Day=i.getDate(),r.TDay=r.Day<10?"0"+r.Day:String(r.Day),r.Hour=i.getHours(),r.THour=r.Hour<10?"0"+r.Hour:String(r.Hour),r.hour=r.Hour<13?r.Hour:r.Hour-12,r.Thour=r.hour<10?"0"+r.hour:String(r.hour),r.Minute=i.getMinutes(),r.TMinute=r.Minute<10?"0"+r.Minute:String(r.Minute),r.Second=i.getSeconds(),r.TSecond=r.Second<10?"0"+r.Second:String(r.Second),r.Millisecond=i.getMilliseconds(),t.replace(/yyyy/gi,String(r.Year)).replace(/yyy/gi,String(r.Year)).replace(/yy/gi,r.TYear).replace(/y/gi,r.TYear).replace(/MM/g,r.TMonth).replace(/M/g,String(r.Month)).replace(/dd/gi,r.TDay).replace(/d/gi,String(r.Day)).replace(/HH/g,r.THour).replace(/H/g,String(r.Hour)).replace(/hh/g,r.Thour).replace(/h/g,String(r.hour)).replace(/mm/g,r.TMinute).replace(/m/g,String(r.Minute)).replace(/ss/gi,r.TSecond).replace(/s/gi,String(r.Second)).replace(/fff/gi,String(r.Millisecond)).replace(/SSS/gi,String(r.Millisecond)).replace(/sss/gi,String(r.Millisecond))}static compatibleDateOfIos(e){"string"==typeof e&&(e.indexOf(".")>-1&&(e=e.substring(0,e.indexOf("."))),e=e.replace(/-/g,"/"));if(2===e.split("").reduce(((e,t,r,i)=>e+("/"===t?1:0)),0)){const t=e.split("/"),r=t[1],i=t[2].indexOf(" ")>-1?t[2].split(" ")[0]:t[2];1===r.length&&(t[1]="0"+r),1===i.length&&(t[2]="0"+t[2]),e=t.join("/");}return e}static compare(e,t){if(!e&&t)return -1;if(e&&!t)return 1;if(!e&&!t)return 0;const r=DateUtil.compatibleDateOfIos(e),i=DateUtil.compatibleDateOfIos(t);return r<i?-1:r>i?1:0}static getNowTimeStr(){return DateUtil.dateFormat(new Date,"yyyy-MM-dd HH:mm:ss")}} class FileUtil{static isBase64(e){if(!e)return !1;let t=e;FileUtil.base64Prefix(t||"")&&(t=FileUtil.base64PrefixRemove(t||""));try{return !!atob(t)}catch(e){return !1}}static base64ToFile(e,t="file.png",r){var n,i;if(!FileUtil.isBase64(e))return null;if(!r){const t=FileUtil.base64Prefix(e);r=(null===(i=null===(n=null==t?void 0:t.split(";"))||void 0===n?void 0:n.shift())||void 0===i?void 0:i.split(":").pop())||"image/png";}const o=atob(FileUtil.base64PrefixRemove(e)),a=[];for(let e=0;e<o.length;e+=1024){const t=o.slice(e,e+1024),r=new Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);const n=new Uint8Array(r);a.push(n);}const s=new Blob(a,{type:r});return new File([s],t,{type:r})}static fileToBase64(e,t="image/png"){return `data:${t};base64,`+btoa(new Uint8Array(e).reduce(((e,t)=>e+String.fromCharCode(t)),""))}static fileToBase64Async(e){return new Promise(((t,r)=>{const n=new FileReader;n.onload=function(e){var r;const n=(null===(r=null==e?void 0:e.target)||void 0===r?void 0:r.result)||"";t(n);},n.readAsDataURL(e);}))}static base64ToBlob(e,t="image/png"){t=this.base64MimeType(e)||t;const r=atob(this.base64PrefixRemove(e));let n=r.length;const i=new Uint8Array(n);for(;n--;)i[n]=r.charCodeAt(n);return new Blob([i],{type:t})}static blob2Base64Promise(e,t){return new Promise(((r,n)=>{"text/xml"===e.type&&n("不支持text/xml的文件类型转成base64");const i=new FileReader;i.readAsDataURL(e),i.onload=e=>{let n=e.target.result.toString();const i=n.substring(n.indexOf(",")+1,n.length);(null==n?void 0:n.indexOf("application/octet-stream"))>-1&&(null==t?void 0:t.length)>0&&(n="data:image/jpeg;base64,".replace("jpeg",t.substring(t.indexOf(".")+1))+i),r(n);},i.onerror=e=>{console.warn("文件流转换base64失败:"+e),n(e);};}))}static blob2Base64(e,t){return new rxjs.Observable((r=>{"text/xml"===e.type&&r.error("不支持text/xml的文件类型转成base64");const n=new FileReader;n.readAsDataURL(e),n.onload=e=>{let n=e.target.result.toString();const i=n.substring(n.indexOf(",")+1,n.length);(null==n?void 0:n.indexOf("application/octet-stream"))>-1&&(null==t?void 0:t.length)>0&&(n="data:image/jpeg;base64,".replace("jpeg",t.substring(t.indexOf(".")+1))+i),r.next(n),r.complete();},n.onerror=e=>{console.log("文件流转换base64失败:"+e),r.error(e);};}))}static anyPicBase64ToAnyPicBase64(e,t="image/png"){return new Promise(((r,n)=>{if(e)try{let i=FileUtil.base64ToBlob(e,t),o=URL.createObjectURL(i),a=new Image;a.onload=function(){let e=document.createElement("canvas");e.width=a.width,e.height=a.height;let i=e.getContext("2d");if(i){i.drawImage(a,0,0);let n=e.toDataURL(t);r(n),URL.revokeObjectURL(o);}else n("创建Canvas实例失败");},a.src=o;}catch(e){n("转换图片格式失败");}else r("");}))}static blob2Base64s(e,n){if((null==e?void 0:e.length)<=0)return new rxjs.Observable((e=>{e.next([]),e.complete();}));const i=[];for(let t=0;t<e.length;t++)i.push(this.blob2Base64(e[t],(null==n?void 0:n.length)>0?n[t]:".png"));return rxjs.forkJoin(i)}static file2UTF8Str(e){return e?new Promise(((t,r)=>{const n=new FileReader;n.onload=e=>{var r;t(null===(r=null==e?void 0:e.target)||void 0===r?void 0:r.result);},n.readAsText(e,"UTF-8");})):Promise.resolve(null)}static file2Utf8Str(e){return new rxjs.Observable((t=>{const r=new FileReader;r.onload=e=>{const r=e.target.result.split(","),n=atob(r[1]),i=new TextDecoder("utf-8").decode(new Uint8Array(n.length).map(((e,t)=>n.charCodeAt(t))));t.next(i),t.complete();},r.readAsDataURL(e);}))}static compressImage(t,r=3145728,n="base64",i){if(!t)return Promise.resolve(null);const o=e=>{if(e instanceof File){if("file"===n)return Promise.resolve(e);if("base64"===n)return FileUtil.fileToBase64Async(e)}else {if("file"===n)return Promise.resolve(e);if("base64"===n)return FileUtil.blob2Base64Promise(e,".png")}return Promise.resolve(e)};let a=t;if("string"==typeof t){if(!FileUtil.isBase64(t))return Promise.reject("输入的图片编码不是合法的base64编码");a=FileUtil.base64ToBlob(t);}const s=a.size,l=r<=0?3145728:r;if(s<=r)return o(a);let c=l/s;return new Promise(((t,r)=>{new e__default["default"](a,Object.assign({quality:c,success(e){o(e).then(t);},error:r},i));}))}static getBase64ByFilePath(e){return new Promise(((t,r)=>{fetch(e).then((e=>e.blob())).then((e=>{const n=new FileReader;n.onload=e=>{var r;t(null===(r=null==e?void 0:e.target)||void 0===r?void 0:r.result);},n.onerror=r,n.readAsDataURL(e);})).catch(r);}))}static getBlobByFilePath(e){return new Promise(((t,r)=>{fetch(e).then((e=>e.blob())).then((e=>{t(e);})).catch(r);}))}static base64PrefixAdd(e,t="data:image/png;base64,"){return !e||e&&e.indexOf("base64,")>-1?e:t+e}static base64PrefixAddPng(e){return this.base64PrefixAdd(e,"data:image/png;base64,")}static base64PrefixAddSvg(e){return this.base64PrefixAdd(e,"data:image/svg+xml;base64,")}static base64PrefixRemove(e){return e&&e.indexOf("base64,")>-1?e.substring(e.indexOf("base64,")+7):e}static base64Prefix(e){return (null==e?void 0:e.indexOf(","))>-1&&(null==e?void 0:e.startsWith("data:"))?e.split(",")[0]:""}static base64MimeType(e){return (null==e?void 0:e.indexOf(":"))>-1&&(null==e?void 0:e.indexOf(";"))>-1?StringUtil.subStringWith(e,":",";"):""}static downLoadFileWithBlobUrl(e,t="pdf",r="file.pdf"){if(!e)return;let n=new XMLHttpRequest;n.open("get",e),n.send(null),n.responseType="arraybuffer",n.onreadystatechange=()=>{if(4==n.readyState&&200==n.status&&(console.log(n.response),"object"==typeof n.response)){const e=n.response,i=new Blob([e],{type:t});try{if(window.navigator.msSaveOrOpenBlob)navigator.msSaveBlob(i,r);else {const e=document.createElement("a"),t=document.querySelector("body");e.href=window.URL.createObjectURL(i),e.download=r,e.style.display="none",t&&(t.appendChild(e),e.click(),t.removeChild(e),window.URL.revokeObjectURL(e.href));}}catch(e){console.error("当前设备环境不支持下载",e);}}};}static compressImg(e,t=.66,r="image/png"){return new Promise(((n,i)=>{const o=new FileReader;o.readAsDataURL(e),o.onload=()=>{const i=new Image;i.src=o.result,i.onload=()=>{const o=i.width,a=i.height,s=document.createElement("canvas");s.width=o,s.height=a;const l=s.getContext("2d");if(l){l.fillStyle="#fff",l.fillRect(0,0,s.width,s.height),l.drawImage(i,0,0,o,a);const e=s.toDataURL(r,t),c=this.base64ToBlob(e);console.log("压缩后的file:",c),n(c);}else console.warn("当前环境不支持Canvas,无法压缩图片"),n(e);};};}))}static uBytes2Blob(e,t="text/plain"){const r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return new Blob([new Uint8Array(r)],{type:`${t};charset=UTF-8`})}static stringToBlob(e,t="text/plain"){return new Blob([e],{type:t})}static encodeStr2Hex(e){const t=[];for(let r=0;r<e.length;r++)t[r]=("00"+e.charCodeAt(r).toString(16)).slice(-4);return "\\u"+t.join("\\u")}static decodeHex2Str(e){try{return unescape(e.replace(/\\/g,"%"))}catch(t){return console.warn("解码异常",t),e}}static getFileNameByPath(e){const t=e.split(/[?#]/)[0].replace(/\\/g,"/");try{const e=new URL(t),r=e.pathname.split("/").filter(Boolean).pop()||"";return decodeURIComponent(r)}catch(e){}const r=t.split("/");for(let e=r.length-1;e>=0;e--)if(""!==r[e].trim())return r[e];return t.endsWith("/")?"":t}static formatFileSize(e){if(0===e)return "0Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+""+["Bytes","Kb","M","G"][t]}} class IdCardUtil{static isIDCard(t,r,n){let e,s;const i=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],d=["","","","","","","","","","","","北京","天津","河北","山西","内蒙古","","","","","","辽宁","吉林","黑龙江","","","","","","","","上海","江苏","浙江","安微","福建","江西","山东","","","","河南","湖北","湖南","广东","广西","海南","","","","重庆","四川","贵州","云南","西藏","","","","","","","陕西","甘肃","青海","宁夏","新疆","","","","","","台湾","","","","","","","","","","香港","澳门","","","","","","","","","国外"];let u,o,c=t.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})((\d{3})[X\d])))$/i);if(null==c)return !1;if(c[1]>=d.length||""==d[c[1]])return !1;if(12==c[2].length?(s=t.substr(0,17),u=[c[9],c[10],c[11]].join("-"),o=c[13]):(s=t.substr(0,6)+"19"+t.substr(6),u=["19"+c[4],c[5],c[6]].join("-"),o=c[7]),n&&""!=n&&o%2!=n%2)return !1;if(r&&""!=r&&r!=u)return !1;if(c=u.match(/^((19|20)\d{2})[-](\d{2})[-](\d{2})$/),!c)return !1;const g=c[1],a=1*c[3]-1,l=c[4];if(e=new Date(g,a,l),"object"!=typeof e||e.getFullYear()!=g||e.getMonth()!=a||e.getDate()!=l)return !1;let b=0;for(let t=0;t<=16;t++)b+=s.charAt(t)*i[t];return s+="10X98765432".charAt(b%11),15==t.length||18==t.length&&t==s}static isIdCard18(t){return /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/.test(t)}static getSexByIdCard(t){if(!this.isIDCard(t))return console.error("传入的参数不是有效的身份证号码:"+t),0;const r=18===t.length?t.charAt(16):t.charAt(14);return Number(r)%2==0?2:1}static getBirthdayByIdCard(t){let r="";return this.isIDCard(t)?(18==t.length?r=t.substring(6,10)+"-"+t.substring(10,12)+"-"+t.substring(12,14):15==t.length&&(r="19-"+t.substring(6,8)+"-"+t.substring(8,10)),r):(console.error("传入的参数不是有效的身份证号码:"+t),r)}static getArea(t){const r=t,n={Province:"",City:"",Country:""};let e=0;const s=r.indexOf("省");-1===s?(e=r.indexOf("自治区"),n.Province=-1!==e?r.substring(0,e+3):r.substring(0,0)):n.Province=r.substring(0,s+1);const i=r.indexOf("市");n.City=-1===e?r.substring(e+1,i+1):0===e?r.substring(s+1,i+1):r.substring(e+3,i+1);let d=r.lastIndexOf("区");return -1===d?(d=r.indexOf("县"),n.Country=r.substring(i+1,d+1)):n.Country=r.substring(i+1,d+1),""===n.Province&&""!==n.City&&-1!=["北京市","上海市","重庆市","天津市"].indexOf(n.City)&&(n.Province=n.City),n}} class RandomUtil{static randomChoose(t){if(!t||0===t.length)return null;const a=t.length;return t[Math.floor(Math.random()*a)]}static randomChooseBatches(t,a=1){if(!t||0===t.length)return null;const r=t.filter((()=>!0)),o=r.length;let e=a>=1&&a<=o?a:Math.ceil(Math.random()*o),n=[];for(;e-- >0;)n=n.concat(r.splice(Math.floor(Math.random()*r.length),1));return n}static randomInt(t,a){const r=t<=a?t:a,o=t<=a?a:t;return Math.floor(Math.random()*(o-r))+r}static randomColor(t){const a=Math.floor(256*Math.random()),r=Math.floor(256*Math.random()),o=Math.floor(256*Math.random());if(t){const t=t=>Number(t).toString(16).toUpperCase();return `#${t(a)}${t(r)}${t(o)}`}return `rgba(${a}, ${r}, ${o}, 1)`}static randomCreate(t){let a="";switch(t){case"MOBILE_PHONE":a=this.randomCreateMobilePhone();break;case"ID_CARD":a=this.randomCreateIdCard();break;case"PERSON_NAME":a=this.randomCreatePersonName();break;case"BANK_CARD_NO":a=this.randomCreateBankCardNo();}return a}static randomCreateMobilePhone(){const t=["130","131","132","133","135","137","138","170","187","189"];let a=t[Math.floor(Math.random()*t.length)];for(let t=0;t<8;t++)a+=Math.floor(10*Math.random());return a}static randomCreateIdCard(){const t=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],a="420101",r="19810101",o=Math.floor(10*Math.random()).toString()+Math.floor(10*Math.random()).toString()+Math.floor(10*Math.random()).toString(),e=(a+r+o).split("");let n=0;for(let a in e)n+=parseInt(e[a])*parseInt(t[a]);return a+r+o+["1","0","X","9","8","7","6","5","4","3","2"][parseInt(String(n%11))]}static randomCreatePersonName(){const t=["赵","钱","孙","李","周","吴","郑","王","冯","陈","褚","卫","蒋","沈","韩","杨","朱","秦","尤","许","何","吕","施","张","孔","曹","严","华","金","魏","陶","姜","戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","奚","范","彭","郎","鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","酆","鲍","史","唐","费","廉","岑","薛","雷","贺","倪","汤","滕","殷","罗","毕","郝","邬","安","常","乐","于","时","傅","皮","卞","齐","康","伍","余","元","卜","顾","孟","平","黄","和","穆","萧","尹"],a=["子璇","淼","国栋","夫子","瑞堂","甜","敏","尚","国贤","贺祥","晨涛","昊轩","易轩","益辰","益帆","益冉","瑾春","瑾昆","春齐","杨","文昊","东东","雄霖","浩晨","熙涵","溶溶","冰枫","欣欣","宜豪","欣慧","建政","美欣","淑慧","文轩","文杰","欣源","忠林","榕润","欣汝","慧嘉","新建","建林","亦菲","林","冰洁","佳欣","涵涵","禹辰","淳美","泽惠","伟洋","涵越","润丽","翔","淑华","晶莹","凌晶","苒溪","雨涵","嘉怡","佳毅","子辰","佳琪","紫轩","瑞辰","昕蕊","萌","明远","欣宜","泽远","欣怡","佳怡","佳惠","晨茜","晨璐","运昊","汝鑫","淑君","晶滢","润莎","榕汕","佳钰","佳玉","晓庆","一鸣","语晨","添池","添昊","雨泽","雅晗","雅涵","清妍","诗悦","嘉乐","晨涵","天赫","玥傲","佳昊","天昊","萌萌","若萌"];return t[Math.floor(Math.random()*t.length)]+a[Math.floor(Math.random()*a.length)]}static randomCreateBankCardNo(t){let a={104:"621661",302:"622689",304:"622630",305:"622622",309:"622908",310:"621717",315:"622323",316:"622309","0102":"622202","0103":"622848","0105":"622700","0301":"622262","0303":"622666","0306":"622556","0308":"622588","0410":"622155"},r="";if(!t){const r=Object.keys(a);t=r[Math.floor(Math.random()*r.length)];}r=a[t];for(let t=0;t<13;t++)r+=Math.floor(10*Math.random());return r}static randomPageDataAsync(t,a,r,o,e=.05,n=1e3){return new Promise(((l,s)=>{0<=e&&e<1&&Math.random()<e&&s(new Error("模拟网络错误")),setTimeout((()=>{try{const e=RandomUtil.randomPageData(t,a,r,o);l(e);}catch(t){s(t);}}),n);}))}static randomPageData(t,a=1,r=10,o=52){const e={pageNo:a,pageSize:r,totalCount:t&&Array.isArray(t)?t.length:o,pageCount:0,resultList:[]},n=r>e.totalCount?e.totalCount:r,l=Math.ceil(e.totalCount/n),s=e.totalCount%n;if(e.pageCount=l,0==l||a>l||a<0||parseInt(a+"")!=a)e.resultList=[];else {const r=0!=s&&a==l?s:n;let o=null;for(let l=0;l<r;l++)o=t&&"function"==typeof t?t(n*(a-1)+(l+1)):t&&Array.isArray(t)?t[e.pageSize*(e.pageNo-1)+l]:{id:`id-${n*(a-1)+(l+1)}`,name:RandomUtil.randomCreate("PERSON_NAME"),position:RandomUtil.randomChoose(["职员","经理人","CEO","董事长"])},e.resultList.push(o);}return e}} class RegularUtil{}RegularUtil.Email=/^([a-z0-9A-Z]+[-|.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$/,RegularUtil.PostCode=/^\d{6}$/,RegularUtil.Mobile=/^1[23456789]\d{9}$/,RegularUtil.Telephone=/^\d{2,5}-?\d{7,8}$/,RegularUtil.Base64=/^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i; class ValidatorUtil{static validateFields(t){if(t&&Array.isArray(t)&&t.length>0)for(let i=0;i<t.length;i++){const r=t[i];if(r.msg&&ValidatorUtil.isEmpty(r.value))return r.msg;if(r.validatorMsg&&r.validator&&"function"==typeof r.validator&&!r.validator.call(null,r.value))return r.validatorMsg}return ""}static isEmpty(t){return null==t||("string"==typeof t?""===t:Array.isArray(t)?0===t.length:"object"==typeof t?t instanceof Map||t instanceof Set?0===t.size:0===Object.keys(t).length:"number"==typeof t&&isNaN(t))}static isNullOrUndefined(t){return null==t}static isArrayEmpty(t){return !(Array.isArray(t)&&t&&t.length>0)}static isMobile(i){return RegularUtil.Mobile.test(i)}static isTelephone(i){return RegularUtil.Telephone.test(i)}static isMobileOrTelephone(t){return ValidatorUtil.isMobile(t)||ValidatorUtil.isTelephone(t)}static isEmail(i){return RegularUtil.Email.test(i)}static isPostCode(i){return RegularUtil.PostCode.test(i)}static isSocialUnicode(t){return /^[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/g.test(t)}static isNumberString(t,r){return StringUtil.isNumberString(t,r)}static isPureHanZi(t){return /[\u4e00-\u9fa5]/g.test(t)}static isBlob(t){return "application/json"!==(null==t?void 0:t.type)}static isPropertyHasValue(t,i){return (null==t?void 0:t.hasOwnProperty(i))&&null!=t[i]&&null!=t[i]}} class HtmlUtil{static copyTextPcAndMobile(e,c){try{if(!o__default["default"])return void console.log("需要安装clipboard插件");if(o__default["default"].isSupported()){const t=o__default["default"].copy(e);console.log(t),(null==t?void 0:t.length)>0&&c&&c(!0,"复制成功");}else c&&c(!1,"不支持该设备");}catch(o){console.error(o);}}static copyTextPc(o,e){if(navigator.clipboard)navigator.clipboard.writeText(o).then((()=>{e&&e(!0,"复制成功!");})).catch((()=>{e&&e(!0,"复制失败!");}));else {const c=document.createElement("input");c.value=o,document.body.appendChild(c),c.select();try{document.execCommand("copy"),document.body.removeChild(c),document.execCommand("copy")?e&&e(!0,"复制成功!"):e&&e(!1,"复制失败!");}catch(o){console.error(o),e&&e(!1,"复制失败!");}document.execCommand("copy"),document.body.removeChild(c),document.execCommand("copy")?e&&e(!0,"复制成功!"):e&&e(!1,"复制失败!");}}} class TreeUtil{static toTree(r,e="id",t="parentId",n="children",i="level",l=1,s){i||(i="level");const a=[];let o={};if(!r)return [];for(let t in r)o[r[t][e]]=r[t];r.forEach((r=>{let e=o[r[t]];e?(e[n]||(e[n]=[])).push(r):a.push(r);}));const c=(r,e)=>{if(r)if(Array.isArray(r))for(let t=0;t<r.length;t++)Object.prototype.hasOwnProperty.call(r[t],i)||(r[t][i]=e),c(r[t][n],e+1),s&&s(r[t]);else Object.prototype.hasOwnProperty.call(r,i)||(r[i]=e),s&&s(r);};return c(a,l),a}static toList(r,e="children"){if(!r)return [];const t=(r,n=[])=>{if(!r)return n||[];if(Array.isArray(r)&&r.length>=0)for(let e of r)t(e,n);else {const i=r[e];delete r[e],n.push(r),t(i,n);}return n};return t(r)}static toListWithCallback(r,e="children",t){const n=[],i=r=>{if(r&&(!Array.isArray(r)||0!==r.length))if(Array.isArray(r))for(const e of r)i(e);else {t&&t(r);const l=r[e];delete r[e],n.push(r),i(l);}};return i(r),n}static searchTree(r,e="id",t="parentId",n="children",i=(r=>!0)){if(!r)return [];const l=(r,t={})=>{if(!r)return t;if(Array.isArray(r)&&r.length>=0)for(let e of r)l(e,t);else i&&i(r)&&(t[r[e]]=1),l(r[n],t);return t},s=l(r),a=r=>!!r&&(!!s[r[e]]||!!(Array.isArray(r[n])&&r[n].length>0)&&r[n].some((r=>a(r)))),o=(r,e=[])=>{if(!r)return e||[];if(Array.isArray(r)&&r.length>=0)for(let t of r)o(t,e);else {const t=r[n];if(a(r)){const t=Object.assign({},r);delete t[n],e.push(t);}o(t,e);}return e},c=o(r);return TreeUtil.toTree(c,e,t,n)}static findNodeById(r,e,t="id",n="children"){const i=r=>{if(!r||Array.isArray(r)&&0===r.length)return null;if(Array.isArray(r)){let e=null;for(const t of r)if(e=i(t),e)return e;return null}return r[t]===e?r:i(r[n])};return i(r)}static findParentNode(r,e,t="id",n="parentId",i="children"){const l=TreeUtil.findNodeById(r,e,t,i);return l?TreeUtil.findNodeById(r,l[n],t,i):null}static getTreeMaxDepth(r,e="value",t="text",n="children"){if(null==r)return 0;if(Array.isArray(r))return 0===r.length?0:Math.max(...r.map((r=>TreeUtil.getTreeMaxDepth(r,e,t,n))));const i=r[n];if(!Array.isArray(i)||0===i.length)return 1;const l=i.map((r=>TreeUtil.getTreeMaxDepth(r,e,t,n)));return 1+Math.max(...l)}static getKeysByFirstDepthIndex(r,e,t="value",n="children"){const i=[];if(void 0===r)return i;const l=(r,e)=>{e&&Array.isArray(e)&&0<=r&&r<e.length&&(i.push(e[r][t]),l(0,e[r][n]));};return l(r,e),i}} class CacheUtil{static set(t,e){localStorage&&null!=t&&null!=e&&localStorage.setItem(t,e);}static get(t){return localStorage?null==t?null:localStorage.getItem(t):null}static setJSON(t,e){null!=e&&this.set(t,JSON.stringify(e));}static getJSON(t){const e=this.get(t);if(null!=e)return JSON.parse(e)}static remove(t){localStorage.removeItem(t);}static setSession(t,e){sessionStorage&&null!=t&&null!=e&&sessionStorage.setItem(t,e);}static getSession(t){return sessionStorage?null==t?null:sessionStorage.getItem(t):null}static setJSONSession(t,e){null!=e&&this.set(t,JSON.stringify(e));}static getJSONSession(t){const e=this.get(t);if(null!=e)return JSON.parse(e)}static removeSession(t){sessionStorage.removeItem(t);}} class CacheTtlUtil{} class CustomUtil{constructor(){}}CustomUtil.DateUtil=DateUtil,CustomUtil.StringUtil=StringUtil,CustomUtil.DictUtil=DictUtil,CustomUtil.ValidatorUtil=ValidatorUtil,CustomUtil.RegularUtil=RegularUtil,CustomUtil.RandomUtil=RandomUtil,CustomUtil.IdCardUtil=IdCardUtil,CustomUtil.FileUtil=FileUtil,CustomUtil.DataConverterUtil=DataConverterUtil,CustomUtil.HtmlUtil=HtmlUtil,CustomUtil.TreeUtil=TreeUtil,CustomUtil.CacheUtil=CacheUtil,CustomUtil.CacheTtlUtil=CacheTtlUtil,CustomUtil.OtherUtil=OtherUtil; exports.CacheTtlUtil = CacheTtlUtil; exports.CacheUtil = CacheUtil; exports.CustomUtil = CustomUtil; exports.DataConverterUtil = DataConverterUtil; exports.DateUtil = DateUtil; exports.DictUtil = DictUtil; exports.FileUtil = FileUtil; exports.HtmlUtil = HtmlUtil; exports.IdCardUtil = IdCardUtil; exports.OtherUtil = OtherUtil; exports.RandomUtil = RandomUtil; exports.RegularUtil = RegularUtil; exports.StringUtil = StringUtil; exports.TreeUtil = TreeUtil; exports.ValidatorUtil = ValidatorUtil; Object.defineProperty(exports, '__esModule', { value: true }); }));