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