UNPKG

snowy-designer

Version:

基于Epic-Designer-Pro版本的设计器,可视化开发页面表单

220 lines (219 loc) 5.51 kB
import { ref as u, reactive as K, watchEffect as L } from "vue"; /* empty css */ import "radix-vue"; import "clsx"; import "tailwind-merge"; import "lucide-vue-next"; import "../../../ui-kit/base-ui/src/shadch-ui/button/index.js"; import "@vueuse/core"; import "../../../ui-kit/base-ui/src/shadch-ui/toast/index.js"; import "vuedraggable"; import { deepCompareAndModify as I, findSchemas as f, getValueByPath as S } from "../common/data.js"; import Q from "lodash"; import { pluginManager as s } from "./pluginManager.js"; import "monaco-editor"; import { request as U } from "../request/index.js"; import "../../../hooks/src/store/index.js"; import { useBoolean as V } from "../../../hooks/src/common/useBoolean.js"; import { usePageSchema as W } from "../../../hooks/src/plugin/usePageSchema.js"; import { useState as X } from "../../../hooks/src/plugin/useState.js"; import { useRequest as Y } from "../../../hooks/src/request/index.js"; function ve() { const r = u({}), p = u({}), m = u(!1), h = u([]), c = K({}), { pageSchema: i, setPageSchema: y } = W(), { apiResults: C, clearPollIntervals: w, fetchApi: E, initRequest: g } = Y(), { removeProperty: P, setProperty: x, state: b } = X(), { bool: $, setFalse: A, setTrue: k } = V(!0); function a(e, o = "id") { const t = l(e, o); return (t == null ? void 0 : t.exposed) ?? null; } function v(e, o = "id") { return d(e, o).map((n) => n.exposed); } function l(e, o = "id") { if (o === "id") return r.value[e] ?? null; const t = f( i.schemas, (n) => S(n, o) === e, !0 ); return !t || !t.id ? null : r.value[t.id] ?? null; } function d(e, o = "id") { if (o === "id") { const n = r.value[e]; return n ? [n] : []; } return f( i.schemas, (n) => S(n, o) === e ).map((n) => r.value[n.id ?? ""]).filter(Boolean); } function D(e, o = "id") { return console.warn( "[Epic 自定义函数]: `getComponent`方法已废弃,后续版本可能移除该函数,请使用`find`方法" ), a(e, o); } function B(e, o) { r.value[e] = o; } function N(e) { delete r.value[e]; } function M(e, o = !1) { const t = {}; for (const n in s.publicMethods) Object.prototype.hasOwnProperty.call(s.publicMethods, n) && (t[n] = s.publicMethods[n].handler); try { const n = { ...t, _: Q, defineExpose: O, fetchApi: E, find: a, findAll: v, findInstance: l, findInstanceAll: d, getComponent: D, global: s.global, pluginManager: s, publicMethods: t, request: U, state: b }; new Function(`const epic = this;const {_} = this;${e}`).bind( n )(); } catch (n) { o && console.error("[epic:自定义函数]异常:", n); } } function O(e) { e && (p.value = e); } function R(e, ...o) { if (!e || e.length === 0) { console.warn("未提供任何动作"); return; } e.forEach((t) => { const n = t.args ? JSON.parse(t.args) : o; switch (t.type) { case "component": { j(t, n); break; } case "custom": { _(t, n); break; } case "public": { F(t, n); break; } default: { console.warn(`未知的动作类型: ${t.type}`); break; } } }); } function F(e, o) { var t; try { (t = s.publicMethods[e.methodName]) == null || t.handler(...o); } catch (n) { console.error(`[Epic:公共函数(${e.methodName})]执行异常:`, n); } } function _(e, o) { var t, n; try { (n = (t = p.value)[e.methodName]) == null || n.call(t, ...o); } catch (H) { console.error(`[Epic:自定义函数(${e.methodName})]执行异常:`, H); } } function j(e, o) { const t = e.componentId && a(e.componentId); if (!t) { console.warn(`[Epic:组件${e.componentId}]未找到`); return; } try { t[e.methodName](...o); } catch (n) { console.error( `[Epic:组件${e.componentId}函数(${e.methodName})]执行异常:`, n ); } } function J(e = !0) { m.value = e; } function T(e) { const o = f( e, () => !0 ); h.value = o.map( (t) => t.id ); } function z(e, o = "default") { if (c[o]) { const t = c[o]; I(e, t); } c[o] = e; } function G(e, o = "default") { if (c[o]) { I(c[o], e, !1); return; } c[o] = e; } return L(() => { const e = i.script; e && e !== "" && M(e, !m.value), g(i); }), { addComponentInstance: B, addFormData: z, apiResults: C, clearPollIntervals: w, componentInstances: r, defaultComponentIds: h, doActions: R, // 推荐使用 find 函数 find: a, findAll: v, findInstance: l, findInstanceAll: d, funcs: p, // 兼容处理 getComponentInstance: a, hideSidebar: A, initRequest: g, isDesignMode: m, isSidebarVisible: $, pageEntity: c, pageSchema: i, removeComponentInstance: N, removeProperty: P, setDefaultComponentIds: T, setDesignMode: J, setFormData: G, setMethods: M, setPageSchema: y, setProperty: x, showSidebar: k, state: b }; } export { ve as usePageManager };