UNPKG

auto-tools

Version:

常用函数的封装使用

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