epic-designer
Version:
基于vue3的设计器,可视化开发页面表单
417 lines (416 loc) • 12.3 kB
JavaScript
import { isProxy as C, toRaw as T, isRef as B } from "vue";
/* empty css */
/* empty css */
/* empty css */
/* empty css */
import "vue-draggable-plus";
import { getUUID as w } 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 A } from "../../../manager/src/pluginManager.js";
function k(n, i = !0, r = /* @__PURE__ */ new WeakMap()) {
if (typeof n != "object" || n === null)
return n;
if (r.has(n))
return r.get(n);
if (i && typeof window.structuredClone == "function") {
const e = y(n);
return structuredClone(e);
}
if (Array.isArray(n)) {
const e = n.map(
(l) => k(l, i, r)
);
return r.set(n, e), e;
}
const t = {};
return r.set(n, t), Object.keys(n).forEach((e) => {
t[e] = k(
n[e],
i,
r
);
}), t;
}
function y(n, i = /* @__PURE__ */ new WeakMap()) {
if (n === null || typeof n != "object")
return n;
if (i.has(n))
return i.get(n);
const r = C(n) ? T(n) : n;
if (i.set(n, r), Array.isArray(r)) {
let l;
for (let s = 0; s < r.length; s++) {
const o = r[s];
if (o !== null && typeof o == "object" && (l = y(o, i), l !== o)) {
const f = r.slice(0, s);
f.push(l);
for (let a = s + 1; a < r.length; a++) {
const u = r[a];
f.push(
u !== null && typeof u == "object" ? y(u, i) : u
);
}
return f;
}
}
return r;
}
let t = null;
const e = Object.keys(r);
for (const l of e) {
const s = r[l];
if (s !== null && typeof s == "object") {
const o = B(s) ? y(s.value, i) : y(s, i);
o !== s && (t || (t = { ...r }), t[l] = o);
}
}
return t || r;
}
function U(n, i = []) {
const [r] = F([k(n)], (t) => {
var o, f;
let e = 0, l = `${t.type}_${w(4, "number")}`;
for (; p(
i,
(a) => a.id === l,
!0
); ) {
if (e++, e >= 50)
throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`);
l = `${t.type}_${w(4, "number")}`;
}
const s = {
...t,
id: l
};
return (s.field || s.input) && !((f = (o = A.component.getConfigByType(s.type)) == null ? void 0 : o.editConstraints) != null && f.fixedField) && (s.field = s.id), s;
});
return r;
}
function I(n, i, r = !0) {
const t = n;
for (const [e, l] of Object.entries(i))
t[e] && l && typeof t[e] == "object" && typeof l == "object" ? (Array.isArray(t[e]) && !Array.isArray(l) ? t[e] = {} : !Array.isArray(t[e]) && Array.isArray(l) && (t[e] = []), I(
t[e],
l,
r
)) : t[e] = l;
r && Object.keys(t).reverse().forEach((e) => {
Object.prototype.hasOwnProperty.call(i, e) || (Array.isArray(t) ? t.splice(Number(e), 1) : delete t[e]);
});
}
function g(n, i, r = [], t = /* @__PURE__ */ new WeakMap()) {
if (Object.is(n, i))
return !0;
if (typeof n != "object" || n === null || typeof i != "object" || i === null)
return !1;
if (t.has(n))
return t.get(n) === i;
if (t.has(i))
return t.get(i) === n;
t.set(n, i), t.set(i, n);
let e = !1;
try {
if (n instanceof Date && i instanceof Date)
return e = n.getTime() === i.getTime(), e;
if (n instanceof RegExp && i instanceof RegExp)
return e = n.source === i.source && n.flags === i.flags, e;
if (n instanceof Map && i instanceof Map) {
if (n.size !== i.size)
return e = !1, e;
for (const [c, h] of n)
if (!i.has(c) || !g(h, i.get(c), r, t))
return e = !1, e;
return e = !0, e;
}
if (n instanceof Set && i instanceof Set) {
if (n.size !== i.size)
return e = !1, e;
const c = Array.from(i);
for (const h of n) {
const x = c.findIndex(
(S) => g(h, S, r, t)
);
if (x === -1)
return e = !1, e;
c.splice(x, 1);
}
return e = !0, e;
}
const l = Array.isArray(n), s = Array.isArray(i);
if (l !== s)
return e = !1, e;
if (l && s) {
if (n.length !== i.length)
return e = !1, e;
for (const [c, h] of n.entries())
if (!g(h, i[c], r, t))
return e = !1, e;
return e = !0, e;
}
const o = n, f = i, a = (c) => Object.keys(c).filter((h) => !r.includes(h)), u = a(o), d = a(f);
if (u.length !== d.length)
return e = !1, e;
for (const c of u)
if (!Object.prototype.hasOwnProperty.call(f, c) || !g(o[c], f[c], r, t))
return e = !1, e;
return e = !0, e;
} finally {
t.delete(n), t.delete(i);
}
}
function _(n, i) {
const r = [];
let t = !1;
function e(l) {
if (r.push(l), l.id === i && (t = !0), !t && l.children && l.children.length > 0)
for (let s = 0; s < l.children.length && (e(l.children[s]), !t); s++)
;
if (!t && l.slots)
for (const s in l.slots)
for (let o = 0; o < l.slots[s].length && (e(l.slots[s][o]), !t); o++)
;
t || r.pop();
}
return n.forEach(e), t || console.error(`没有查询到id为${i}的节点`), r;
}
function J(n, i, r) {
if (!i)
return r;
const t = i.split(".");
let e = n;
for (const l of t) {
if (e == null)
return r;
e = e[l];
}
return e === void 0 ? r : e;
}
function G(n, i, r) {
if (!i)
return n;
const t = i.replaceAll(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
let e = n;
for (let l = 0; l < t.length - 1; l++) {
const s = t[l];
e[s] == null && (e[s] = Number.isNaN(Number(t[l + 1])) ? {} : []), e = e[s];
}
return e[t[t.length - 1]] = r, n;
}
function H(n, i = "default") {
return P(n, i).map((t) => t.field);
}
function P(n, i = "default") {
const r = p(
n,
(e) => {
var l;
return e.type === "form" && (((l = e.props) == null ? void 0 : l.name) ?? e.name === i);
},
!0
);
return p(
(r == null ? void 0 : r.children) ?? [],
(e) => !!e.input,
!1,
(e) => e.type !== "subform"
);
}
function p(n, i, r = !1, t) {
const e = [], l = [...n];
for (; l.length > 0; ) {
const s = l.pop();
if (s != null && s.children && (!t || t(s)) && l.push(...s.children), s != null && s.slots && (!t || t(s)))
for (const o in s.slots)
l.push(...s.slots[o]);
if (i(s) && (e.push(s), r))
return s;
}
return r ? !1 : e;
}
function F(n, i, r) {
const t = [...n];
for (; t.length > 0; ) {
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 l in e.slots)
t.push(...e.slots[l]);
I(e, i(e));
}
return n;
}
function Q(n, i) {
const r = p(
n,
(t) => (t == null ? void 0 : t.id) === i,
!0
);
return r || null;
}
function X(n, i) {
const r = [{ type: "", children: n }];
let t = 0, e = null;
const l = p(
r,
(s) => {
if (e = s.children ?? null, !e) {
if (s != null && s.slots)
for (const o in s.slots) {
e = s.slots[o];
for (const [f, a] of e.entries())
if (a.id === i)
return t = f, !0;
}
return !1;
}
for (const [o, f] of e.entries())
if (f.id === i)
return t = o, !0;
return !1;
},
!0
);
if (!e)
throw new Error(`没有查询到id为${i}的节点`);
return {
index: t,
parentSchema: l,
schema: e[t],
list: e
};
}
function Y(n) {
n.config || (n.config = {});
const i = {
schemas: [
{
id: "root",
label: "页面",
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_${w()}`
}
]
}
],
script: n.script || ""
};
if (i.schemas && i.schemas.length > 0) {
const r = i.schemas[0];
if (r.children && r.children.length > 0) {
const t = r.children[0];
n.list && (t.children = m(n.list));
}
}
return i;
}
function m(n, i) {
return n.map((r) => {
var f, a;
let t = r.type ?? "";
const e = r.options ?? {}, l = (u, d) => {
t === u && (t = d, typeof e.defaultValue == "string" && (e.defaultValue = JSON.parse(e.defaultValue)));
};
if (l("uploadImg", "upload-image"), l("uploadFile", "upload-file"), t === "date" && e.range && (e.type = "daterange", delete e.range), (t === "date" || t === "time") && (e.valueFormat = e.format), t === "textarea") {
const { maxRows: u, minRows: d } = e;
e.autoSize = { maxRows: u, minRows: d }, 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"), i && i.type === "grid" && (t = "col", e.span = r.span, r.key = w());
const s = {
field: r.model,
icon: r.icon || "",
id: r.key,
label: r.label,
props: e,
type: t
};
return (e.noFormItem || !e.showLabel) && (s.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) && (s.input = !0, ((a = (f = r.rules) == null ? void 0 : f[0]) == null ? void 0 : a.required) === !1 && r.rules.shift(), r.rules && r.rules.length > 0 && (s.rules = r.rules)), r.list && (s.children = m(r.list, r)), r.columns && (s.children = m(r.columns, r)), r.trs && (s.children = m(r.trs, r)), r.tds && (s.children = m(r.tds, r)), s;
});
}
function Z(n, i = !1) {
var e, l;
let r = !1;
p(n.schemas, (s) => (s.componentProps && (s.props = s.componentProps, delete s.componentProps, r = !0), !1)), r && i && console.warn(
"[Epic] PageSchema中的componentProps属性已迁移到props,请使用新版本设计器更新数据"
);
const t = (l = (e = n.schemas[0]) == null ? void 0 : e.props) == null ? void 0 : l.style;
return (t == null ? void 0 : t.padding) === "16px" && delete t.padding, n;
}
function K(n, i = []) {
return p(
n.schemas,
(t) => t.type === "form"
).forEach((t) => {
var s;
if (!((s = t.children) != null && s.length)) return;
const e = [], l = p(
t.children,
(o) => {
const f = A.component.getConfigByType(o.type), a = !!(o.input && f && !f.isSubTable);
return a && i.includes(o.type) && (o.class = "ep-full-width"), a;
},
!1,
(o) => {
const f = A.component.getConfigByType(o.type);
return f != null && f.isSubTable ? (o.class = "ep-sub-table ep-full-width", e.push(o), !1) : !0;
}
);
t.children = l.reverse(), t.children.push(...e);
}), n;
}
export {
Y as convertKFormData,
k as deepClone,
I as deepCompareAndModify,
g as deepEqual,
y as deepToRaw,
Q as findSchemaById,
X as findSchemaInfoById,
p as findSchemas,
U as generateNewSchema,
H as getFormFields,
P as getFormSchemas,
_ as getMatchedById,
J as getValueByPath,
F as mapSchemas,
Z as migrateComponentProps,
m as recursionConvertedNode,
K as reorganizeSchemasForTableView,
G as setValueByPath
};