UNPKG

epic-designer

Version:

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

353 lines (352 loc) 10.2 kB
import { isProxy as w, toRaw as A, isRef as b } from "vue"; /* empty css */ /* empty css */ /* empty css */ /* empty css */ import "vue-draggable-plus"; import { getUUID as h } from "./string.js"; import "../../../git/epic/epic-designer/node_modules/.pnpm/jsep@1.4.0/node_modules/jsep/dist/jsep.js"; import "@vueuse/core"; import "../../../hooks/src/store/index.js"; import { pluginManager as k } from "../../../manager/src/pluginManager.js"; function m(n, l = !0, t = /* @__PURE__ */ new WeakMap()) { if (typeof n != "object" || n === null) return n; if (t.has(n)) return t.get(n); if (l && typeof window.structuredClone == "function") { const e = p(n); return structuredClone(e); } if (Array.isArray(n)) { const e = n.map( (i) => m(i, l, t) ); return t.set(n, e), e; } const r = {}; return t.set(n, r), Object.keys(n).forEach((e) => { r[e] = m( n[e], l, t ); }), r; } function p(n, l = /* @__PURE__ */ new WeakMap()) { if (n === null || typeof n != "object") return n; if (l.has(n)) return l.get(n); const t = w(n) ? A(n) : n; if (l.set(n, t), Array.isArray(t)) { let i; for (let o = 0; o < t.length; o++) { const s = t[o]; if (s !== null && typeof s == "object" && (i = p(s, l), i !== s)) { const f = t.slice(0, o); f.push(i); for (let c = o + 1; c < t.length; c++) { const a = t[c]; f.push( a !== null && typeof a == "object" ? p(a, l) : a ); } return f; } } return t; } let r = null; const e = Object.keys(t); for (const i of e) { const o = t[i]; if (o !== null && typeof o == "object") { const s = b(o) ? p(o.value, l) : p(o, l); s !== o && (r || (r = { ...t }), r[i] = s); } } return r || t; } function M(n, l = []) { const [t] = I([m(n)], (r) => { var s, f; let e = 0, i = `${r.type}_${h(4, "number")}`; for (; u( l, (c) => c.id === i, !0 ); ) { if (e++, e >= 50) throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`); i = `${r.type}_${h(4, "number")}`; } const o = { ...r, id: i }; return (o.field || o.input) && !((f = (s = k.component.getConfigByType(o.type)) == null ? void 0 : s.editConstraints) != null && f.fixedField) && (o.field = o.id), o; }); return t; } function g(n, l, t = !0) { const r = n; for (const [e, i] of Object.entries(l)) r[e] && i && typeof r[e] == "object" && typeof i == "object" ? (Array.isArray(r[e]) && !Array.isArray(i) ? r[e] = {} : !Array.isArray(r[e]) && Array.isArray(i) && (r[e] = []), g( r[e], i, t )) : r[e] = i; t && Object.keys(r).reverse().forEach((e) => { Object.prototype.hasOwnProperty.call(l, e) || (Array.isArray(r) ? r.splice(Number(e), 1) : delete r[e]); }); } function W(n, l, t = [], r = /* @__PURE__ */ new WeakMap()) { const e = (i) => { if (Array.isArray(i)) return i.map(e); if (typeof i == "object" && i !== null) { if (r.has(i)) return "[Circular]"; r.set(i, !0); const o = Object.keys(i).sort(), s = {}; return o.forEach((f) => { t.includes(f) || (s[f] = e(i[f])); }), r.delete(i), s; } else return i; }; return JSON.stringify(e(n)) === JSON.stringify(e(l)); } function z(n, l) { const t = []; let r = !1; function e(i) { if (t.push(i), i.id === l && (r = !0), !r && i.children && i.children.length > 0) for (let o = 0; o < i.children.length && (e(i.children[o]), !r); o++) ; if (!r && i.slots) for (const o in i.slots) for (let s = 0; s < i.slots[o].length && (e(i.slots[o][s]), !r); s++) ; r || t.pop(); } return n.forEach(e), r || console.error(`没有查询到id为${l}的节点`), t; } function T(n, l, t) { if (!l) return t; const r = l.split("."); let e = n; for (const i of r) { if (e == null) return t; e = e[i]; } return e === void 0 ? t : e; } function q(n, l, t) { if (!l) return n; const r = l.replaceAll(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean); let e = n; for (let i = 0; i < r.length - 1; i++) { const o = r[i]; e[o] == null && (e[o] = Number.isNaN(Number(r[i + 1])) ? {} : []), e = e[o]; } return e[r[r.length - 1]] = t, n; } function D(n, l = "default") { return C(n, l).map((r) => r.field); } function C(n, l = "default") { const t = u( n, (e) => { var i; return e.type === "form" && (((i = e.props) == null ? void 0 : i.name) ?? e.name === l); }, !0 ); return u( (t == null ? void 0 : t.children) ?? [], (e) => !!e.input, !1, (e) => e.type !== "subform" ); } function u(n, l, t = !1, r) { const e = [], i = [...n]; for (; i.length > 0; ) { const o = i.pop(); if (o != null && o.children && (!r || r(o)) && i.push(...o.children), o != null && o.slots && (!r || r(o))) for (const s in o.slots) i.push(...o.slots[s]); if (l(o) && (e.push(o), t)) return o; } return t ? !1 : e; } function I(n, l, t) { const r = [...n]; for (; r.length > 0; ) { const e = r.pop(); if (e != null && e.children && (!t || t(e)) && r.push(...e.children), e != null && e.slots && (!t || t(e))) for (const i in e.slots) r.push(...e.slots[i]); g(e, l(e)); } return n; } function J(n, l) { const t = u( n, (r) => r.id === l, !0 ); return t || null; } function U(n, l) { const t = [{ type: "", children: n }]; let r = 0, e = null; const i = u( t, (o) => { if (e = o.children ?? null, !e) { if (o != null && o.slots) for (const s in o.slots) { e = o.slots[s]; for (const [f, c] of e.entries()) if (c.id === l) return r = f, !0; } return !1; } for (const [s, f] of e.entries()) if (f.id === l) return r = s, !0; return !1; }, !0 ); if (!e) throw new Error(`没有查询到id为${l}的节点`); return { index: r, parentSchema: i, schema: e[r], list: e }; } function _(n) { n.config || (n.config = {}); const l = { schemas: [ { id: "root", label: "页面", props: { style: { padding: "16px" } }, type: "page", children: [ { label: "表单", type: "form", icon: "epic-icon-daibanshixiang", labelWidth: n.config.labelWidth || 100, name: "default", props: { colon: n.config.colon || !0, hideRequiredMark: n.config.hideRequiredMark || !1, labelAlign: n.config.labelAlign || "right", labelCol: n.config.labelCol || { span: 5 }, labelLayout: n.config.labelLayout === "flex" ? "fixed" : "flex", labelWidth: n.config.labelWidth || 100, layout: n.config.layout || "horizontal", size: n.config.size || "middle", wrapperCol: n.config.wrapperCol || { span: 19 } }, children: [], id: `form_${h()}` } ] } ], script: n.script || "" }; if (l.schemas && l.schemas.length > 0) { const t = l.schemas[0]; if (t.children && t.children.length > 0) { const r = t.children[0]; n.list && (r.children = d(n.list)); } } return l; } function d(n, l) { return n.map((t) => { var f, c; let r = t.type ?? ""; const e = t.options ?? {}, i = (a, y) => { r === a && (r = y, typeof e.defaultValue == "string" && (e.defaultValue = JSON.parse(e.defaultValue))); }; if (i("uploadImg", "upload-image"), i("uploadFile", "upload-file"), r === "date" && e.range && (e.type = "daterange", delete e.range), (r === "date" || r === "time") && (e.valueFormat = e.format), r === "textarea") { const { maxRows: a, minRows: y } = e; e.autoSize = { maxRows: a, minRows: y }, delete e.minRows, delete e.maxRows; } r === "number" && !e.precision && delete e.precision, e.width && (e.style = { width: e.width }, delete e.width), r === "grid" && (r = "row"), l && l.type === "grid" && (r = "col", e.span = t.span, t.key = h()); const o = { field: t.model, icon: t.icon || "", id: t.key, label: t.label, props: e, type: r }; return (e.noFormItem || !e.showLabel) && (o.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(r) && (o.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 && (o.rules = t.rules)), t.list && (o.children = d(t.list, t)), t.columns && (o.children = d(t.columns, t)), t.trs && (o.children = d(t.trs, t)), t.tds && (o.children = d(t.tds, t)), o; }); } function K(n, l = !1) { let t = !1; return u(n.schemas, (r) => (r.componentProps && (r.props = r.componentProps, delete r.componentProps, t = !0), !1)), t && l && console.warn( "[Epic] PageSchema中的componentProps属性已迁移到props,请使用新版本设计器更新数据" ), n; } export { _ as convertKFormData, m as deepClone, g as deepCompareAndModify, W as deepEqual, p as deepToRaw, J as findSchemaById, U as findSchemaInfoById, u as findSchemas, M as generateNewSchema, D as getFormFields, C as getFormSchemas, z as getMatchedById, T as getValueByPath, I as mapSchemas, K as migrateComponentProps, d as recursionConvertedNode, q as setValueByPath };