UNPKG

jobsys-mpower

Version:

Enhanced component based on Taro & NutUI

287 lines (286 loc) 7.61 kB
import T from "axios"; import { T as a } from "./index-76a93d23.js"; import { reduce as m, find as D, isString as d, isFunction as h, cloneDeep as F, isBoolean as y, isObject as E, isUndefined as C, isArray as A } from "lodash-es"; import f from "dayjs"; const S = { STATE_CODE_SUCCESS: "SUCCESS", // 成功 STATE_CODE_FAIL: "FAIL", // 失败 STATE_CODE_NOT_FOUND: "NOT_FOUND", // 找不到资源 STATE_CODE_INFO_NOT_COMPLETE: "INCOMPLETE", // 信息不完整 STATE_CODE_NOT_ALLOWED: "NOT_ALLOWED" //没有权限 }; function v(e) { return e || (e = {}), e.loading = !0, { /** * get请求 * @param url * @param {Object} [config] - axios config * @returns {Promise<unknown>} */ get(n, s) { return new Promise((u, t) => { T.get(n, s).then((l) => { u(l); }).catch((l) => { t(l); }).finally(() => { e.loading = !1; }); }); }, /** * post请求 * @param {string} url * @param {Object} data * @param {Object} [config] - axios config * @returns {Promise<unknown>} */ post(n, s, u) { return new Promise((t, l) => { T.post(n, s, u).then((i) => { t(i); }).catch((i) => { l(i); }).finally(() => { e.loading = !1; }); }); } }; } const V = async (e, n, s) => { if (e.finishedText = e.finishedText || "加载完毕", e.loading = !0, !e.uri) { console.error("URI is required in pagination"); return; } let u = {}; try { a.showLoading({ title: "加载中...", mask: !0 }), u = await v().get(e.uri, { params: { ...e.params || {}, page: n || !e.page ? 1 : e.page + 1 } }); } catch { e.loading = !1, e.finished = !1, e.error = !0; return; } finally { a.hideLoading(); } if (u.status !== S.STATE_CODE_SUCCESS) { e.loading = !1, e.error = !0, e.errorText = u.result; return; } let t; s ? t = s(u) : t = u.result; let l = t.data; !n && e.items && (l = e.items.concat(l)); const i = t.current_page || t.current || t.page || 1, r = t.last_page || t.lastPage || t.pages || 0, o = t.total_size || t.totalSize || t.total || 0; e.loading = !1, e.error = !1, e.page = i, e.items = l, e.finished = r === 0 || r === i, e.empty = o === 0; }; function W(e, n) { if (!n) return ""; const s = n.find((u) => u.value === e); return s ? s.text : ""; } function Y(e, n, s) { s = s || { value: "value", label: "text", children: "children" }; const u = []; function t(l) { var i; n.includes(l[s.value]) && u.push(l[s.label]), (i = l[s.children]) != null && i.length && l[s.children].forEach((r) => { t(r); }); } return e.forEach((l) => { t(l); }), u; } function w(e, n, s) { s = s || { value: "value", label: "text", children: "children" }; let u = []; return m( n, (t, l) => { const i = D(t, { [s.value]: l }); if (i) return u.push(i[s.label]), i[s.children]; }, e ), u; } function z(e, n, s) { return s = s || { value: "value", label: "text", children: "children" }, w(e, n, s); } function H(e, n, s) { s = s || { value: "value", label: "text", children: "children" }; const u = []; function t(l, i, r) { for (const o of l) if (o[s.value] === i) { r.unshift(o[s.value]); break; } else if (o[s.children] && t(o[s.children], i, r).length > 0) { r.unshift(o[s.value]); break; } return r; } return t(e, n, u); } const { STATE_CODE_FAIL: x, STATE_CODE_INFO_NOT_COMPLETE: g, STATE_CODE_NOT_FOUND: P, STATE_CODE_NOT_ALLOWED: L, STATE_CODE_SUCCESS: _ } = S; function q(e) { const { url: n, data: s, csrfToken: u } = e; let { method: t } = e; t = t || "post"; const l = document.createElement("form"); if (l.action = n, l.method = t, l.target = "_blank", l.style.display = "none", Object.keys(s).forEach((i) => { const r = document.createElement("input"); r.type = "hidden", r.name = i, r.value = s[i], l.appendChild(r); }), !u) { const i = document.createElement("input"); i.type = "hidden", i.name = "_token", i.value = document.querySelector('meta[name="csrf-token"]').getAttribute("content"), l.appendChild(i); } return document.body.appendChild(l), l; } function N(e, n) { const { status: s } = e, u = e.result, t = {}; t.default = "请求失败, 请检查数据并重试", t[x] = "系统错误,请稍候再试", t[P] = "请求的内容不存在", t[g] = "信息不完整", t[L] = "没有权限"; const l = { [_]: "success" }, i = n[s] || n[l[s]] || t[s] || t.def; d(i) ? s === _ ? a.showToast({ title: i, icon: "success", duration: 2e3 }) : a.showToast({ title: u || i, icon: "none", duration: 2e3 }) : h(i) && i(); } function B(e, n) { N(e, { success: n }); } function b(e) { e && e.errorFields ? e.errorFields.forEach((n) => { a.showToast({ title: n.errors.join(" "), icon: "none", duration: 2e3 }); }) : e && e.response ? a.showToast({ title: "网络异常", icon: "error", duration: 2e3 }) : a.showToast({ title: "请检查填写项", icon: "error", duration: 2e3 }); } function G(e, n) { const s = F(e); n = n || {}; const u = (t) => { var l, i; for (let r in t) { let o; if (f.isDayjs(t[r]) ? o = t[r] : Object.prototype.toString.call(t[r]) === "[object Date]" && (o = f(t[r])), o && n.date) { d(n.date) ? t[r] = o.format(n.date) : h(n.date) ? t[r] = n.date(o) : t[r] = t[r].unix(); continue; } if (y(t[r]) && n.boolean) { n.boolean === !0 ? t[r] = t[r] ? 1 : 0 : Array.isArray(n.boolean) && (t[r] = t[r] ? ((l = n.boolean) == null ? void 0 : l[0]) || 1 : ((i = n.boolean) == null ? void 0 : i[1]) || 0); continue; } if (n.attachment) { const c = n.attachment; if (E(t[r]) && d(c) && !C(t[r][c])) { t[r] = t[r][c]; continue; } else if (E(t[r]) && h(c)) { t[r] = c(t[r]); continue; } } if (A(t[r])) for (let c in t[r]) t[r][c] = u(t[r][c]); } return t; }; return u(s); } function J(e, n) { return n ? f(e, n) : f(e); } function I(e, n) { return e ? (f.isDayjs(e) || (e = f(e)), e.format(n || "YYYY-MM-DD HH:mm")) : ""; } function K(e) { return e ? (f.isDayjs(e) || (e = f(e)), e.unix()) : ""; } function Q(e, n) { return e && d(e) && (e = parseInt(e)), e < 9999999999 && (e *= 1e3), I(new Date(e), n); } const U = ["showToast", "showNotify", "showDialog", "showImagePreview"]; function O(e, n) { return console.log(e, "MpUIResolver", n), { name: e, from: "jobsys-mpower", sideEffects: "jobsys/dist/style.css" }; } function X(e = {}) { return { type: "component", resolve: (n) => { const { autoImport: s = !1 } = e; if (s && U.includes(n)) return O(n, e); if (console.log("component", n), n.startsWith("Mp")) return O(n.slice(2), e); } }; } export { X as MpUIResolver, S as STATUS, I as useDateFormat, K as useDateUnix, J as useDayjs, v as useFetch, w as useFindLabelsFromPath, H as useFindParentValues, z as useFindTextsFromPath, Y as useFindTextsInValues, b as useFormFail, G as useFormFormat, q as useHiddenForm, V as usePage, N as useProcessStatus, B as useProcessStatusSuccess, W as useTextFromOptionsValue, Q as useTimestampFormat }; //# sourceMappingURL=hooks.js.map