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