UNPKG

fx-epic-designer

Version:

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

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