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