UNPKG

epic-designer

Version:

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

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