UNPKG

gepic

Version:

基于vue3的设计器,可视化开发页面表单

271 lines (270 loc) 7.92 kB
import { getUUID as h } from "./string.js"; import "vue"; import { pluginManager as w } from "../manager/pluginManager.js"; import "@vueuse/core"; import "../../hooks/store/index.js"; function d(n, s = /* @__PURE__ */ new WeakMap()) { if (typeof n != "object" || n === null) return n; if (s.has(n)) return s.get(n); if (Array.isArray(n)) { const t = n.map((e) => d(e, s)); return s.set(n, t), t; } const r = {}; return s.set(n, r), Object.keys(n).forEach((t) => { r[t] = d(n[t], s); }), r; } function B(n) { const [s] = k([d(n)], (r) => { var e, i; const t = { ...r, id: `${r.type}_${h(8)}` }; return (t.field || t.input) && !((i = (e = w.getComponentConfingByType(t.type)) == null ? void 0 : e.editConstraints) != null && i.fixedField) && (t.field = t.id), t; }); return s; } function m(n, s, r = !0) { for (const [t, e] of Object.entries(s)) n[t] && e && typeof n[t] == "object" && typeof e == "object" ? (Array.isArray(n[t]) && !Array.isArray(e) ? n[t] = {} : !Array.isArray(n[t]) && Array.isArray(e) && (n[t] = []), m(n[t], e, r)) : n[t] = e; r && Object.keys(n).reverse().forEach((t) => { s.hasOwnProperty(t) || (Array.isArray(n) ? n.splice(Number(t), 1) : delete n[t]); }); } function L(n, s, r = [], t = /* @__PURE__ */ new WeakMap()) { const e = (i) => { if (Array.isArray(i)) return i.map(e); if (typeof i == "object" && i !== null) { if (t.has(i)) return "[Circular]"; t.set(i, !0); const l = Object.keys(i).sort(), o = {}; return l.forEach((a) => { r.includes(a) || (o[a] = e(i[a])); }), t.delete(i), o; } else return i; }; return JSON.stringify(e(n)) === JSON.stringify(e(s)); } function O(n, s) { const r = []; let t = !1; function e(i) { if (r.push(i), i.id === s && (t = !0), !t && i.children != null && i.children.length > 0) for (let l = 0; l < i.children.length && (e(i.children[l]), !t); l++) ; if (!t && i.slots) for (const l in i.slots) for (let o = 0; o < i.slots[l].length && (e(i.slots[l][o]), !t); o++) ; t || r.pop(); } return n.forEach(e), t || console.error(`没有查询到id为${s}的节点`), r; } function P(n, s, r) { const t = s.split("."); let e = n; for (let i = 0; i < t.length; i++) { if (e == null) return r; e = e[t[i]]; } return e === void 0 ? r : e; } function E(n, s, r) { const t = s.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean); let e = n; for (let i = 0; i < t.length - 1; i++) { const l = t[i]; e[l] == null && (e[l] = isNaN(Number(t[i + 1])) ? {} : []), e = e[l]; } return e[t[t.length - 1]] = r, n; } function M(n, s = "default") { return A(n, s).map((t) => t.field); } function A(n, s = "default") { const r = c( n, (e) => { var i; return e.type === "form" && (((i = e.componentProps) == null ? void 0 : i.name) ?? e.name === s); }, !0 ); return c( (r == null ? void 0 : r.children) ?? [], (e) => !!e.input, !1, (e) => e.type !== "subform" ); } function c(n, s, r = !1, t) { const e = [], i = [...n]; for (; i.length; ) { const l = i.pop(); if (l != null && l.children && (!t || t(l)) && i.push(...l.children), l != null && l.slots && (!t || t(l))) for (const o in l.slots) i.push(...l.slots[o]); if (s(l) && (e.push(l), r)) return l; } return r ? !1 : e; } function k(n, s, r) { const t = [...n]; for (; t.length; ) { const e = t.pop(); if (e != null && e.children && (!r || r(e)) && t.push(...e.children), e != null && e.slots && (!r || r(e))) for (const i in e.slots) t.push(...e.slots[i]); m(e, s(e)); } return n; } function V(n, s) { const r = c( n, (t) => t.id === s, !0 ); if (!r) throw new Error(`没有查询到id为${s}的节点`); return r; } function z(n, s) { const r = [{ type: "", children: n }]; let t = 0, e = null; const i = c( r, (l) => { if (e = l.children ?? null, !e) { if (l != null && l.slots) for (const o in l.slots) { e = l.slots[o]; for (let a = 0; a < e.length; a++) if (e[a].id === s) return t = a, !0; } return !1; } for (let o = 0; o < e.length; o++) if (e[o].id === s) return t = o, !0; return !1; }, !0 ); if (!e) throw new Error(`没有查询到id为${s}的节点`); return { list: e, schema: e[t], index: t, parentSchema: i }; } function R(n) { const s = { schemas: [ { type: "page", id: "root", label: "页面", children: [ { label: "表单", type: "form", icon: "epic-icon-daibanshixiang", labelWidth: n.config.labelWidth || 100, name: "default", componentProps: { layout: n.config.layout || "horizontal", labelWidth: n.config.labelWidth || 100, labelLayout: n.config.labelLayout === "flex" ? "fixed" : "flex", labelCol: n.config.labelCol || { span: 5 }, wrapperCol: n.config.wrapperCol || { span: 19 }, hideRequiredMark: n.config.hideRequiredMark || !1, colon: n.config.colon || !0, labelAlign: n.config.labelAlign || "right", size: n.config.size || "middle" }, children: [], id: "form_" + h() } ], componentProps: { style: { padding: "16px" } } } ], script: n.script || "" }; return s.schemas[0].children[0].children = f( n.list ), s; } function f(n, s) { return n.map((r) => { var a, y, g; let t = r.type ?? ""; const e = r.options ?? {}, i = (u, p) => { t === u && (t = p, e.defaultValue && (e.defaultValue = JSON.parse(e.defaultValue))); }; if (i("uploadImg", "upload-image"), i("uploadFile", "upload-file"), t === "date" && e.range && (e.type = "daterange", delete e.range), (t === "date" || t === "time") && (e.valueFormat = e.format), t === "textarea") { const { minRows: u, maxRows: p } = e; e.autoSize = { minRows: u, maxRows: p }, delete e.minRows, delete e.maxRows; } t === "number" && !e.precision && delete e.precision, e.width && (e.style = { width: e.width }, delete e.width), t === "grid" && (t = "row"), s && s.type === "grid" && (t = "col", e.span = r.span, r.key = h()); const l = { label: r.label, type: t, icon: r.icon || "", field: r.model, componentProps: e, id: r.key }; return (e.noFormItem || !e.showLabel) && (l.noFormItem = !0, delete e.noFormItem, delete e.showLabel), e.clearable && (e.allowClear = !0, delete e.clearable), [ "input", "textarea", "number", "password", "select", "cascader", "checkbox", "radio", "date", "time", "slider", "switch", "color-picker", "upload-file", "upload-image" ].includes(t) && (l.input = !0, ((y = (a = r.rules) == null ? void 0 : a[0]) == null ? void 0 : y.required) === !1 && r.rules.shift(), ((g = r.rules) == null ? void 0 : g.length) > 0 && (l.rules = r.rules)), r.list && (l.children = f(r.list, r)), r.columns && (l.children = f(r.columns, r)), r.trs && (l.children = f(r.trs, r)), r.tds && (l.children = f(r.tds, r)), l; }); } export { R as convertKFormData, d as deepClone, m as deepCompareAndModify, L as deepEqual, V as findSchemaById, z as findSchemaInfoById, c as findSchemas, B as generateNewSchema, M as getFormFields, A as getFormSchemas, O as getMatchedById, P as getValueByPath, k as mapSchemas, f as recursionConvertedNode, E as setValueByPath };