UNPKG

epic-designer

Version:

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

206 lines (205 loc) 5.5 kB
import { ref as f, reactive as C, watchEffect as J } from "vue"; /* empty css */ /* empty css */ /* empty css */ import { pluginManager as u } from "./pluginManager.js"; /* empty css */ import "vue-draggable-plus"; import { findSchemas as v, getValueByPath as S } from "../../utils/src/common/data.js"; import { FormulaEngine as L } from "../../utils/src/formula/formulaEngine.js"; import "@vueuse/core"; import "../../hooks/src/store/index.js"; import { useHookManager as T } from "../../hooks/src/plugin/useHookManager.js"; import { useMountMonitor as U } from "../../hooks/src/plugin/useMountMonitor.js"; import { usePageSchema as z } from "../../hooks/src/plugin/usePageSchema.js"; const a = "default"; function ce() { const w = new L(), i = f({}), d = f({}), h = f(!1), b = f([]), p = C({}), x = U(), { pageSchema: l, setPageSchema: k } = z(), y = T(); function m(e, o = "id", t = a) { const n = M(e, o, t); return (n == null ? void 0 : n.exposed) ?? null; } function E(e, o = "id", t = a) { return g(e, o, t).map((c) => c.exposed); } function M(e, o = "id", t = a) { var c, r; if (o === "id") return ((c = i.value[e]) == null ? void 0 : c[t]) ?? null; const n = v( l.schemas, (s) => S(s, o) === e, !0 ); return !n || !n.id ? null : ((r = i.value[n.id]) == null ? void 0 : r[t]) ?? null; } function g(e, o = "id", t = a) { var c; if (o === "id") { const r = (c = i.value[e]) == null ? void 0 : c[t]; return r ? [r] : []; } return v( l.schemas, (r) => S(r, o) === e ).map((r) => { var s; return (s = i.value[r.id ?? ""]) == null ? void 0 : s[t]; }).filter(Boolean); } function P(e, o = "id") { return console.warn( "[Epic 自定义函数]: `getComponent`方法已废弃,后续版本可能移除该函数,请使用`find`方法" ), m(e, o); } function $(e, o, t = a) { i.value[e] || (i.value[e] = {}), i.value[e][t] = o; } function A(e, o = a) { var t; (t = i.value[e]) == null || delete t[o]; } function I(e, o = !1) { const t = {}; for (const n in u.publicMethods.methodsMap) Object.prototype.hasOwnProperty.call( u.publicMethods.methodsMap, n ) && (t[n] = u.publicMethods.methodsMap[n].handler); try { new Function(`const epic = this;${e}`).bind({ ...t, defineExpose: D, find: m, findAll: E, findInstance: M, findInstanceAll: g, getComponent: P, pluginManager: u, publicMethods: t, state: u.global })(); } catch (n) { o && console.error("[Epic:自定义函数]异常:", n); } } function D(e) { e && (d.value = e); } function O(e, o = a, ...t) { if (!e || e.length === 0) { console.warn("未提供任何动作"); return; } e.forEach((n) => { let c = n.args ? JSON.parse(n.args) : t; const r = { event: t }; switch (c = c.map((s) => s && typeof s == "object" && s.__isExpression__ ? w.calculate(s.content, r) : s), n.type) { case "component": { j(n, o, c); break; } case "custom": { F(n, c); break; } case "public": { _(n, c); break; } default: { console.warn(`未知的动作类型: ${n.type}`); break; } } }); } function _(e, o) { var t; try { (t = u.publicMethods.methodsMap[e.methodName]) == null || t.handler( ...o ); } catch (n) { console.error(`[Epic:公共函数(${e.methodName})]执行异常:`, n); } } function F(e, o) { var t, n; try { (n = (t = d.value)[e.methodName]) == null || n.call(t, ...o); } catch (c) { console.error(`[Epic:自定义函数(${e.methodName})]执行异常:`, c); } } function j(e, o = a, t) { const n = e.componentId && m(e.componentId, "id", o); if (!n) { console.warn(`[Epic:组件${e.componentId}]未找到`); return; } try { n[e.methodName](...t); } catch (c) { console.error( `[Epic:组件${e.componentId}函数(${e.methodName})]执行异常:`, c ); } } function N(e = !0) { h.value = e; } function B(e) { const o = v( e, () => !0 ); b.value = o.map( (t) => t.id ); } function H(e, o = "default") { if (p[o]) { const n = p[o]; return Object.keys(e).forEach((c) => { n[c] = e[c]; }), n; } const t = C(e); return p[o] = t, t; } return J(() => { const e = l.script; e && e !== "" && I(e, !h.value); }), { addComponentInstance: $, componentInstances: i, defaultComponentIds: b, doActions: O, find: m, findAll: E, findInstance: M, findInstanceAll: g, forms: p, funcs: d, // 兼容处理, 后续版本可能会移除 getComponentInstance: m, hook: y, isDesignMode: h, mountMonitor: x, pageSchema: l, removeComponentInstance: A, setDefaultComponentIds: B, setDesignMode: N, setFormData: H, setMethods: I, setPageSchema: k }; } export { a as DEFAULT_SCOPE, ce as createPageManager };