UNPKG

epic-designer-dev

Version:

基于vue3的设计器,可视化开发页面表单。在epic-designer的基础上新增了字典选择器

2 lines (1 loc) 3.25 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue");;/* empty css */require("vuedraggable");const a=require("../common/data.cjs"),i=require("./pluginManager.cjs");require("@vueuse/core");require("../../../hooks/src/store/index.cjs");const D=require("../../../hooks/src/plugin/usePageSchema.cjs");function O(){const c=s.ref({}),l=s.ref({}),p=s.ref(!1),h=s.ref([]),r=s.reactive({}),{pageSchema:d,setPageSchema:b}=D.usePageSchema();function u(e,t="id"){const n=f(e,t);return(n==null?void 0:n.exposed)??null}function g(e,t="id"){return m(e,t).map(o=>o.exposed)}function f(e,t="id"){if(t==="id")return c.value[e]??null;const n=a.findSchemas(d.schemas,o=>a.getValueByPath(o,t)===e,!0);return!n||!n.id?null:c.value[n.id]??null}function m(e,t="id"){if(t==="id"){const o=c.value[e];return o?[o]:[]}return a.findSchemas(d.schemas,o=>a.getValueByPath(o,t)===e).map(o=>c.value[o.id??""]).filter(Boolean)}function v(e,t="id"){return console.warn("[Epic 自定义函数]: `getComponent`方法已废弃,后续版本可能移除该函数,请使用`find`方法"),u(e,t)}function S(e,t){c.value[e]=t}function I(e){delete c.value[e]}function M(e,t=!1){const n={};for(const o in i.pluginManager.publicMethods)Object.prototype.hasOwnProperty.call(i.pluginManager.publicMethods,o)&&(n[o]=i.pluginManager.publicMethods[o].handler);try{new Function(`const epic = this;${e}`).bind({...n,defineExpose:y,find:u,findAll:g,findInstance:f,findInstanceAll:m,getComponent:v,pluginManager:i.pluginManager,publicMethods:n})()}catch(o){t&&console.error("[Epic:自定义函数]异常:",o)}}function y(e){e&&(l.value=e)}function C(e,...t){if(!e||e.length===0){console.warn("未提供任何动作");return}e.forEach(n=>{const o=n.args?JSON.parse(n.args):t;switch(n.type){case"component":{w(n,o);break}case"custom":{E(n,o);break}case"public":{P(n,o);break}default:{console.warn(`未知的动作类型: ${n.type}`);break}}})}function P(e,t){var n;try{(n=i.pluginManager.publicMethods[e.methodName])==null||n.handler(...t)}catch(o){console.error(`[Epic:公共函数(${e.methodName})]执行异常:`,o)}}function E(e,t){var n,o;try{(o=(n=l.value)[e.methodName])==null||o.call(n,...t)}catch(q){console.error(`[Epic:自定义函数(${e.methodName})]执行异常:`,q)}}function w(e,t){const n=e.componentId&&u(e.componentId);if(!n){console.warn(`[Epic:组件${e.componentId}]未找到`);return}try{n[e.methodName](...t)}catch(o){console.error(`[Epic:组件${e.componentId}函数(${e.methodName})]执行异常:`,o)}}function $(e=!0){p.value=e}function A(e){const t=a.findSchemas(e,()=>!0);h.value=t.map(n=>n.id)}function k(e,t="default"){if(r[t]){const n=r[t];a.deepCompareAndModify(e,n)}r[t]=e}function x(e,t="default"){if(r[t]){a.deepCompareAndModify(r[t],e,!1);return}r[t]=e}return s.watchEffect(()=>{const e=d.script;e&&e!==""&&M(e,!p.value)}),{addComponentInstance:S,addFormData:k,componentInstances:c,defaultComponentIds:h,doActions:C,find:u,findAll:g,findInstance:f,findInstanceAll:m,forms:r,funcs:l,getComponentInstance:u,isDesignMode:p,pageSchema:d,removeComponentInstance:I,setDefaultComponentIds:A,setDesignMode:$,setFormData:x,setMethods:M,setPageSchema:b}}exports.usePageManager=O;