auto-tools
Version:
常用函数的封装使用
2 lines (1 loc) • 15.2 kB
JavaScript
(function(l,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(l=typeof globalThis<"u"?globalThis:l||self,Y(l.AutoTools={}))})(this,function(l){"use strict";var Y=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ot={exports:{}};(function(t,n){(function(i,e){t.exports=e()})(Y,function(){var i=1e3,e=6e4,r=36e5,u="millisecond",c="second",$="minute",b="hour",j="day",L="week",A="month",H="quarter",N="year",P="date",W="Invalid Date",Z=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,G=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,Q={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(d){var a=["th","st","nd","rd"],o=d%100;return"["+d+(a[(o-20)%10]||a[o]||a[0])+"]"}},B=function(d,a,o){var f=String(d);return!f||f.length>=a?d:""+Array(a+1-f.length).join(o)+d},k={s:B,z:function(d){var a=-d.utcOffset(),o=Math.abs(a),f=Math.floor(o/60),s=o%60;return(a<=0?"+":"-")+B(f,2,"0")+":"+B(s,2,"0")},m:function d(a,o){if(a.date()<o.date())return-d(o,a);var f=12*(o.year()-a.year())+(o.month()-a.month()),s=a.clone().add(f,A),m=o-s<0,h=a.clone().add(f+(m?-1:1),A);return+(-(f+(o-s)/(m?s-h:h-s))||0)},a:function(d){return d<0?Math.ceil(d)||0:Math.floor(d)},p:function(d){return{M:A,y:N,w:L,d:j,D:P,h:b,m:$,s:c,ms:u,Q:H}[d]||String(d||"").toLowerCase().replace(/s$/,"")},u:function(d){return d===void 0}},v="en",I={};I[v]=Q;var X=function(d){return d instanceof T},E=function d(a,o,f){var s;if(!a)return v;if(typeof a=="string"){var m=a.toLowerCase();I[m]&&(s=m),o&&(I[m]=o,s=m);var h=a.split("-");if(!s&&h.length>1)return d(h[0])}else{var g=a.name;I[g]=a,s=g}return!f&&s&&(v=s),s||!f&&v},S=function(d,a){if(X(d))return d.clone();var o=typeof a=="object"?a:{};return o.date=d,o.args=arguments,new T(o)},p=k;p.l=E,p.i=X,p.w=function(d,a){return S(d,{locale:a.$L,utc:a.$u,x:a.$x,$offset:a.$offset})};var T=function(){function d(o){this.$L=E(o.locale,null,!0),this.parse(o)}var a=d.prototype;return a.parse=function(o){this.$d=function(f){var s=f.date,m=f.utc;if(s===null)return new Date(NaN);if(p.u(s))return new Date;if(s instanceof Date)return new Date(s);if(typeof s=="string"&&!/Z$/i.test(s)){var h=s.match(Z);if(h){var g=h[2]-1||0,O=(h[7]||"0").substring(0,3);return m?new Date(Date.UTC(h[1],g,h[3]||1,h[4]||0,h[5]||0,h[6]||0,O)):new Date(h[1],g,h[3]||1,h[4]||0,h[5]||0,h[6]||0,O)}}return new Date(s)}(o),this.$x=o.x||{},this.init()},a.init=function(){var o=this.$d;this.$y=o.getFullYear(),this.$M=o.getMonth(),this.$D=o.getDate(),this.$W=o.getDay(),this.$H=o.getHours(),this.$m=o.getMinutes(),this.$s=o.getSeconds(),this.$ms=o.getMilliseconds()},a.$utils=function(){return p},a.isValid=function(){return this.$d.toString()!==W},a.isSame=function(o,f){var s=S(o);return this.startOf(f)<=s&&s<=this.endOf(f)},a.isAfter=function(o,f){return S(o)<this.startOf(f)},a.isBefore=function(o,f){return this.endOf(f)<S(o)},a.$g=function(o,f,s){return p.u(o)?this[f]:this.set(s,o)},a.unix=function(){return Math.floor(this.valueOf()/1e3)},a.valueOf=function(){return this.$d.getTime()},a.startOf=function(o,f){var s=this,m=!!p.u(f)||f,h=p.p(o),g=function(R,D){var _=p.w(s.$u?Date.UTC(s.$y,D,R):new Date(s.$y,D,R),s);return m?_:_.endOf(j)},O=function(R,D){return p.w(s.toDate()[R].apply(s.toDate("s"),(m?[0,0,0,0]:[23,59,59,999]).slice(D)),s)},M=this.$W,w=this.$M,V=this.$D,C="set"+(this.$u?"UTC":"");switch(h){case N:return m?g(1,0):g(31,11);case A:return m?g(1,w):g(0,w+1);case L:var K=this.$locale().weekStart||0,J=(M<K?M+7:M)-K;return g(m?V-J:V+(6-J),w);case j:case P:return O(C+"Hours",0);case b:return O(C+"Minutes",1);case $:return O(C+"Seconds",2);case c:return O(C+"Milliseconds",3);default:return this.clone()}},a.endOf=function(o){return this.startOf(o,!1)},a.$set=function(o,f){var s,m=p.p(o),h="set"+(this.$u?"UTC":""),g=(s={},s[j]=h+"Date",s[P]=h+"Date",s[A]=h+"Month",s[N]=h+"FullYear",s[b]=h+"Hours",s[$]=h+"Minutes",s[c]=h+"Seconds",s[u]=h+"Milliseconds",s)[m],O=m===j?this.$D+(f-this.$W):f;if(m===A||m===N){var M=this.clone().set(P,1);M.$d[g](O),M.init(),this.$d=M.set(P,Math.min(this.$D,M.daysInMonth())).$d}else g&&this.$d[g](O);return this.init(),this},a.set=function(o,f){return this.clone().$set(o,f)},a.get=function(o){return this[p.p(o)]()},a.add=function(o,f){var s,m=this;o=Number(o);var h=p.p(f),g=function(w){var V=S(m);return p.w(V.date(V.date()+Math.round(w*o)),m)};if(h===A)return this.set(A,this.$M+o);if(h===N)return this.set(N,this.$y+o);if(h===j)return g(1);if(h===L)return g(7);var O=(s={},s[$]=e,s[b]=r,s[c]=i,s)[h]||1,M=this.$d.getTime()+o*O;return p.w(M,this)},a.subtract=function(o,f){return this.add(-1*o,f)},a.format=function(o){var f=this,s=this.$locale();if(!this.isValid())return s.invalidDate||W;var m=o||"YYYY-MM-DDTHH:mm:ssZ",h=p.z(this),g=this.$H,O=this.$m,M=this.$M,w=s.weekdays,V=s.months,C=function(D,_,it,x){return D&&(D[_]||D(f,m))||it[_].slice(0,x)},K=function(D){return p.s(g%12||12,D,"0")},J=s.meridiem||function(D,_,it){var x=D<12?"AM":"PM";return it?x.toLowerCase():x},R={YY:String(this.$y).slice(-2),YYYY:this.$y,M:M+1,MM:p.s(M+1,2,"0"),MMM:C(s.monthsShort,M,V,3),MMMM:C(V,M),D:this.$D,DD:p.s(this.$D,2,"0"),d:String(this.$W),dd:C(s.weekdaysMin,this.$W,w,2),ddd:C(s.weekdaysShort,this.$W,w,3),dddd:w[this.$W],H:String(g),HH:p.s(g,2,"0"),h:K(1),hh:K(2),a:J(g,O,!0),A:J(g,O,!1),m:String(O),mm:p.s(O,2,"0"),s:String(this.$s),ss:p.s(this.$s,2,"0"),SSS:p.s(this.$ms,3,"0"),Z:h};return m.replace(G,function(D,_){return _||R[D]||h.replace(":","")})},a.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},a.diff=function(o,f,s){var m,h=p.p(f),g=S(o),O=(g.utcOffset()-this.utcOffset())*e,M=this-g,w=p.m(this,g);return w=(m={},m[N]=w/12,m[A]=w,m[H]=w/3,m[L]=(M-O)/6048e5,m[j]=(M-O)/864e5,m[b]=M/r,m[$]=M/e,m[c]=M/i,m)[h]||M,s?w:p.a(w)},a.daysInMonth=function(){return this.endOf(A).$D},a.$locale=function(){return I[this.$L]},a.locale=function(o,f){if(!o)return this.$L;var s=this.clone(),m=E(o,f,!0);return m&&(s.$L=m),s},a.clone=function(){return p.w(this.$d,this)},a.toDate=function(){return new Date(this.valueOf())},a.toJSON=function(){return this.isValid()?this.toISOString():null},a.toISOString=function(){return this.$d.toISOString()},a.toString=function(){return this.$d.toUTCString()},d}(),F=T.prototype;return S.prototype=F,[["$ms",u],["$s",c],["$m",$],["$H",b],["$W",j],["$M",A],["$y",N],["$D",P]].forEach(function(d){F[d[1]]=function(a){return this.$g(a,d[0],d[1])}}),S.extend=function(d,a){return d.$i||(d(a,T,S),d.$i=!0),S},S.locale=E,S.isDayjs=X,S.unix=function(d){return S(1e3*d)},S.en=I[v],S.Ls=I,S.p={},S})})(ot);const tt=ot.exports;var q=(t=>(t.PAGE="P",t.DIR="D",t.BUTTON="B",t))(q||{});function z(t){if(t==null)return!0;if(typeof t=="string"){if(t.trim()==="undefined"||t.trim()==="")return!0}else if(typeof t=="object"){for(const n in t)if(Object.hasOwnProperty.call(t,n))return!1;return!0}return!1}function y(t){return!z(t)}function ft(t,n=!1,i=!1,e=!0){if(y(t)&&et(t)){const r={};for(const u in t)if(Object.hasOwnProperty.call(t,u)){let c=t[u];const $=typeof c=="number";($&&!isNaN(c)||!$)&&(n&&z(c)||(typeof c=="string"&&(c=c.trim()),c===""||c===null||c===void 0?i||e&&(r[u]=""):r[u]=c))}return r}else return t}function dt(t){return Object.prototype.toString.call(t)==="[object Array]"}function ht(t){return Object.prototype.toString.call(t)==="[object Function]"}function mt(t){return Object.prototype.toString.call(t)==="[object AsyncFunction]"}function et(t){return Object.prototype.toString.call(t)==="[object Object]"}function nt(t){return Object.prototype.toString.call(t)==="[object String]"}function pt(t){return Object.prototype.toString.call(t)==="[object Boolean]"}function gt(t){return Object.prototype.toString.call(t)==="[object Promise]"}function yt(t){return Object.prototype.toString.call(t)==="[object Number]"}function $t(t,n="*"){window.parent.postMessage({type:t.type,data:t.data},n)}function vt(t,n){return JSON.stringify(t)!==JSON.stringify(n)}function Mt(t,n="admin-user",i){let e=window.localStorage;return i==="session"&&(e=window.sessionStorage),JSON.parse(e.getItem(n)||"{}")[t]}function bt(t,n="label",i="value",e=!0){const r=[],u=[];for(let c=0;c<t.length;c++){const $=t[c];r.push($[n]);let b=$[i];e&&(b+=""),u.push(b)}return{labelList:r,valueList:u}}function St(t,n,i="key"){for(let e=0;e<t.length;e++){const r=t[e][i],u=t[e].defaultVal;n[r]=y(u)?u:void 0}return n}function Ot(t,n,i="modelKey"){for(let e=0;e<t.length;e++){const r=t[e][i],u=t[e].defaultVal;n[r]=y(u)?u:void 0;const c=t[e].beforeModelKey,$=t[e].afterModelKey;if(y(c)){const b=t[e].defaultSBVal;n[c]=y(b)?b:void 0}if(y($)){const b=t[e].defaultSAVal;n[$]=y(b)?b:void 0}}return n}function wt(t,n="+86"){return y(t)?t.startsWith(n)?t:n+t:""}function Tt(t,n="+86"){return y(t)?t.startsWith(n)?t.substring(n.length):t:""}function Dt(t,n){const i=n||"YYYY-MM-DD HH:mm:ss";return t==="now"?tt().format(i):y(t)?tt(t).format(i):""}function At(t){return y(t)?t instanceof tt?t.valueOf():t instanceof Date?t.getTime():nt(t)?new Date(t).getTime():"":""}function Nt(t,n,i="modelKey"){return t.findIndex(e=>e[i]===n)}const jt=(t,n)=>{const i=[];for(let e=t;e<n;e++)i.push(e);return i};async function Pt(t){if(t)try{return!!await t.validateFields()}catch{return!1}else return!1}function It(){return"zhCN"}function st(t,n=Date.now()+"",i="_blank",e){if(nt(t))window.open(t,i);else{const r=document.createElement("a");r.download=e?n+e:n,r.href=window.URL.createObjectURL(t),r.style.display="none",document.body.appendChild(r),r.click(),URL.revokeObjectURL(r.href),document.body.removeChild(r)}}function Ct(t,n=5e3){if(y(t)){const i=document.createElement("div");i.id="iframe_down_dom",i.style.display="none",document.body.appendChild(i),t.forEach(e=>{if(y(e)){const r=document.createElement("iframe");r.style.display="none",r.style.height="0",r.src=e,i.appendChild(r);const u=setTimeout(function(){const c=document.getElementById("iframe_down_dom");c&&document.body.removeChild(c),clearTimeout(u)},n)}})}}const Vt=(t,n=Date.now()+"")=>{const i=new Blob([t],{type:"application/vnd.ms-excel"});st(i,n)};function _t(){let t="#";for(let n=0;n<6;n++)t+=parseInt(Math.random()*15+"").toString(16);return t}function U(t){const n=Number(t);return isNaN(n)?"--":n<10?"0"+n:n}function Ft(){const t=new Date,n=t.getUTCFullYear()+"",i=U(t.getUTCMonth()+1),e=U(t.getUTCDate()),r=U(t.getUTCHours()),u=U(t.getUTCMinutes()),c=U(t.getUTCSeconds());return n+i+e+r+u+c}function Ut(t,n="id"){const i={},e=[];for(let r=0;r<t.length;r++)i[t[r][n]]||(e.push(t[r]),i[t[r][n]]=!0);return e}function Lt(t,n,i=""){let e=[];if(i){const r=n.map(u=>u[i]);t.filter(u=>r.includes(u[i]))}else e=t.filter(r=>n.includes(r));return e}function Bt(t,n,i=!1){let e=[];return i||(e=[...t,...n]),e}function at(t,n="pid"){const i=t;return i.sort((e,r)=>{const u=parseInt(e[n]),c=parseInt(r[n]);if(!(u&&c)&&u!==0&&c!==0)throw console.log("sortArrById error!"),new Error("sortArrById error");return u-c}),i}function Et(t,n="pid"){const i=at(t),e=ut(i),r=[];for(let u=0,c=i.length;u<c;u++){const $=i[u];if($[n]==="0")r.push($);else{const b=e[$[n]];b.children&&b.children.push($)}}return r}function Rt(t){const n=[],i={};return t.forEach(e=>{i[e.id]=e}),t.forEach(e=>{const r=i[e.parentId];r?(r.children=r.children||[],r.children.push(e)):n.push(e)}),n}function Yt(t){const n=[],i=e=>{e&&e.length>0&&e.forEach(r=>{n.push(r),i(r.children)})};return i(t),n}function ut(t,n="value"){const i={};if(y(t))for(let e=0;e<t.length;e++){const r=t[e][n];i[r]=t[e]}return i}function Ht(t){const n={};for(let i=0,e=t.length;i<e;i++){const r=t[i].TX;n[r]=n[r]+1||1}return n}function Wt(t,n=!0){if(t&&et(t)){const i={};for(const e in t)if(Object.hasOwnProperty.call(t,e)){const r=t[e];z(r)&&n?i[e]=void 0:i[e]=r}return i}else return t}function kt(t,n,i,e,r=!0,u,c=[],$=[q.DIR],b=[q.PAGE],j=[q.BUTTON],L=0,A=!1){var G,Q,B;const H=ct(i,r,u);let N=[],P=[];const W=[],Z=[];for(let k=0;k<H.length;k++){const v=H[k],I=$.includes(v.menuType);if(b.includes(v.menuType)||I){const E=y(v.path),S=y(v.componentPath),p=e||v.visible===L,T={...v};if(E){if(y(c)){let F=v.path;const a=F.split("/")[2];if(F=F.split(a)[1],T.path=F,S){const f=(G=v.componentPath)!=null&&G.startsWith("/")?v.componentPath:"/"+v.componentPath;if((Q=v.componentPath)!=null&&Q.endsWith(".vue")?T.component=t[`../views${f}`]:(B=v.componentPath)!=null&&B.endsWith("index")?T.component=t[`../views${f}.vue`]:T.component=t[`../views${f}/index.vue`],p){const s=A?T.path:T.menuName;n.children&&n.children.push({name:s,path:T.path,component:T.component,meta:{title:s}})}}}Z.push(v.path)}p&&P.push(T)}else!e&&y(v.perms)&&W.push(v.perms);N.push(v)}return N=rt(N,j),P=rt(P,j),{myAllMenus:N,mySiderMenu:P,myPerms:W,myPagePaths:Z}}function ct(t,n=!0,i){if(n){let e=[];if(y(t)){const u=Object.assign({id:"id",menuName:"menuName",menuType:"menuType",parentId:"parentId",perms:"perms",path:"path",index:"index",icon:"icon",platformId:"platformId",platformStr:"platformStr",reqMethod:"reqMethod",visible:"visible",componentPath:"componentPath",children:"children",createTime:"createTime",creatorName:"creatorName",updateTime:"updateTime",updaterName:"updaterName"},i);e=t.map(c=>({id:c[u.id]+"",menuName:c[u.menuName],menuType:c[u.menuType],parentId:c[u.parentId]+"",perms:c[u.perms],path:c[u.path],index:c[u.index],icon:c[u.icon],platformId:c[u.platformId],platformStr:c[u.platformStr],reqMethod:c[u.reqMethod],visible:c[u.visible],componentPath:c[u.componentPath],children:c[u.children],createTime:c[u.createTime],creatorName:c[u.creatorName],updateTime:c[u.updateTime],updaterName:c[u.updaterName]}))}return e}else return t}function lt(t,n=0){const i=[];for(let e=0;e<t.length;e++){const r=t[e],u={title:r.menuName,isClass1:r.parentId===n,routeKey:r.path,menuType:r.menuType,icon:r.icon,children:[]};r.children&&y(r.children)&&(u.children=lt(r.children)),i&&i.push(u)}return i}function rt(t,n){const i=t.filter(e=>{const r=t.filter(u=>e.id===u.parentId);return y(r)&&(r.sort((u,c)=>u.index-c.index),n.includes(e.menuType)||(e.children=r)),e.parentId===0||e.parentId==="0"});return i.sort((e,r)=>e.index-r.index),i||[]}l.ExportExlFile=Vt,l.arr2Tree=Et,l.batchDownload=Ct,l.delRepeat=Ut,l.downloadFile=st,l.findIdxByKey=Nt,l.generateMenuRoutes=kt,l.getArrObjKVs=bt,l.getCrossArray=Lt,l.getCurrentLang=It,l.getPlusPhone=wt,l.getRandomColor=_t,l.getRepeatProNum=Ht,l.getStorageVal=Mt,l.getSubPhone=Tt,l.getTimeStamp=At,l.getUTCtime=Ft,l.getUnionArray=Bt,l.handleObjNull=ft,l.hasChangeData=vt,l.isArrayVal=dt,l.isAsyncFuncVal=mt,l.isBoolVal=pt,l.isEmpty=z,l.isFuncVal=ht,l.isNotEmpty=y,l.isNumberVal=yt,l.isObjectVal=et,l.isPromiseVal=gt,l.isStringVal=nt,l.list2Map=ut,l.list2ObjAttr=St,l.list2ObjAttrAB=Ot,l.list2TreeById=Rt,l.parseTime=Dt,l.postParentMsg=$t,l.setRangeNumArr=jt,l.sortArrById=at,l.sortRelationship=rt,l.tranlateTime10=U,l.translateMenusField=ct,l.translateSiderOps=lt,l.tree2Arr=Yt,l.val2Undefined=Wt,l.validateMyForm=Pt,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});