epic-designer-dev
Version:
基于vue3的设计器,可视化开发页面表单。在epic-designer的基础上新增了字典选择器
285 lines (284 loc) • 8.18 kB
JavaScript
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 t = r.map((e) => d(e, s));
return s.set(r, t), t;
}
const n = {};
return s.set(r, n), Object.keys(r).forEach((t) => {
n[t] = d(
r[t],
s
);
}), n;
}
function O(r) {
const [s] = A([d(r)], (n) => {
var e, i;
const t = {
...n,
id: `${n.type}_${y(8)}`
};
return (t.field || t.input) && !((i = (e = g.getComponentConfingByType(t.type)) == null ? void 0 : e.editConstraints) != null && i.fixedField) && (t.field = t.id), t;
});
return s;
}
function m(r, s, n = !0) {
const t = r;
for (const [e, i] of Object.entries(s))
t[e] && i && typeof t[e] == "object" && typeof i == "object" ? (Array.isArray(t[e]) && !Array.isArray(i) ? t[e] = {} : !Array.isArray(t[e]) && Array.isArray(i) && (t[e] = []), m(
t[e],
i,
n
)) : t[e] = i;
n && Object.keys(t).reverse().forEach((e) => {
Object.prototype.hasOwnProperty.call(s, e) || (Array.isArray(t) ? t.splice(Number(e), 1) : delete t[e]);
});
}
function B(r, s, n = [], 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((f) => {
n.includes(f) || (o[f] = e(i[f]));
}), t.delete(i), o;
} else
return i;
};
return JSON.stringify(e(r)) === JSON.stringify(e(s));
}
function L(r, s) {
const n = [];
let t = !1;
function e(i) {
if (n.push(i), i.id === s && (t = !0), !t && i.children && 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 || n.pop();
}
return r.forEach(e), t || console.error(`没有查询到id为${s}的节点`), n;
}
function P(r, s, n) {
const t = s.split(".");
let e = r;
for (const i of t) {
if (e == null)
return n;
e = e[i];
}
return e === void 0 ? n : e;
}
function M(r, s, n) {
const t = s.replaceAll(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
let e = r;
for (let i = 0; i < t.length - 1; i++) {
const l = t[i];
e[l] == null && (e[l] = Number.isNaN(Number(t[i + 1])) ? {} : []), e = e[l];
}
return e[t[t.length - 1]] = n, r;
}
function V(r, s = "default") {
return w(r, s).map((t) => t.field);
}
function w(r, s = "default") {
const n = u(
r,
(e) => {
var i;
return e.type === "form" && (((i = e.componentProps) == null ? void 0 : i.name) ?? e.name === s);
},
!0
);
return u(
(n == null ? void 0 : n.children) ?? [],
(e) => !!e.input,
!1,
(e) => e.type !== "subform"
);
}
function u(r, s, n = !1, t) {
const e = [], i = [...r];
for (; i.length > 0; ) {
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), n))
return l;
}
return n ? !1 : e;
}
function A(r, s, n) {
const t = [...r];
for (; t.length > 0; ) {
const e = t.pop();
if (e != null && e.children && (!n || n(e)) && t.push(...e.children), e != null && e.slots && (!n || n(e)))
for (const i in e.slots)
t.push(...e.slots[i]);
m(e, s(e));
}
return r;
}
function z(r, s) {
const n = u(
r,
(t) => t.id === s,
!0
);
return n || null;
}
function E(r, s) {
const n = [{ type: "", children: r }];
let t = 0, e = null;
const i = u(
n,
(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 t = f, !0;
}
return !1;
}
for (const [o, f] of e.entries())
if (f.id === s)
return t = o, !0;
return !1;
},
!0
);
if (!e)
throw new Error(`没有查询到id为${s}的节点`);
return {
index: t,
parentSchema: i,
schema: e[t],
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 n = s.schemas[0];
if (n.children && n.children.length > 0) {
const t = n.children[0];
r.list && (t.children = a(r.list));
}
}
return s;
}
function a(r, s) {
return r.map((n) => {
var f, c;
let t = n.type ?? "";
const e = n.options ?? {}, i = (p, h) => {
t === p && (t = h, typeof e.defaultValue == "string" && (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 { maxRows: p, minRows: h } = e;
e.autoSize = { maxRows: p, minRows: h }, 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 = n.span, n.key = y());
const l = {
componentProps: e,
field: n.model,
icon: n.icon || "",
id: n.key,
label: n.label,
type: t
};
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, ((c = (f = n.rules) == null ? void 0 : f[0]) == null ? void 0 : c.required) === !1 && n.rules.shift(), n.rules && n.rules.length > 0 && (l.rules = n.rules)), n.list && (l.children = a(n.list, n)), n.columns && (l.children = a(n.columns, n)), n.trs && (l.children = a(n.trs, n)), n.tds && (l.children = a(n.tds, n)), 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
};