gepic
Version:
基于vue3的设计器,可视化开发页面表单
2 lines (1 loc) • 5.13 kB
JavaScript
"use strict";var m=Object.defineProperty;var c=(a,e,t)=>e in a?m(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var o=(a,e,t)=>c(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../common/component.cjs"),p=require("vue");require("@vueuse/core");require("../../hooks/store/index.cjs");class d{constructor(){o(this,"initialized",p.ref(!1));o(this,"components",{});o(this,"componentConfigs",{});o(this,"baseComponentTypes",[]);o(this,"componentSchemaGroups",p.ref([]));o(this,"hiddenComponents",[]);o(this,"formSchemas",[{label:"表单",type:"form",componentProps:{layout:"horizontal",name:"default",labelWidth:100,labelLayout:"fixed",labelCol:{span:5},wrapperCol:{span:19},colon:!0,labelAlign:"right",labelPlacement:"left"},children:[],id:"root"}]);o(this,"componentGroupNameMap",{});o(this,"sortedGroups",["表单","布局"]);o(this,"viewsContainers",{activitybars:p.shallowRef([]),rightSidebars:p.shallowRef([])});o(this,"publicMethods",{})}component(e,t){typeof t=="function"&&(t=h.loadAsyncComponent(t)),this.components[e]=t}registerComponent(e){this.component(e.defaultSchema.type,e.component),e.defaultSchema.input&&(e.config.action||(e.config.action=[]),e.config.action.unshift({type:"setValue",describe:"设置值",argsConfigs:[{...e.defaultSchema,label:"设置数据",field:"0"}]},{type:"getValue",describe:"获取值"})),this.componentConfigs[e.defaultSchema.type]=e,this.computedComponentSchemaGroups()}removeComponent(e){delete this.componentConfigs[e],delete this.components[e]}setBaseComponentTypes(e){this.baseComponentTypes=e}addBaseComponentTypes(e){this.baseComponentTypes.push(e)}removeBaseComponents(){this.baseComponentTypes.forEach(e=>{this.removeComponent(e)}),this.setBaseComponentTypes([]),this.computedComponentSchemaGroups()}getComponents(){return this.components}getComponent(e){return this.components[e]}registerActivitybar(e){typeof e.component=="function"&&(e.component=h.loadAsyncComponent(e.component)),typeof e.visible>"u"&&(e.visible=!0);const t=this.viewsContainers.activitybars.value.findIndex(s=>s.id===e.id);t!==-1?this.viewsContainers.activitybars.value[t]=e:this.viewsContainers.activitybars.value.push(e)}getActivitybars(){return this.viewsContainers.activitybars.value}hideActivitybar(e,t="title"){const s=this.viewsContainers.activitybars.value.findIndex(n=>n[t]===e);s!==-1&&(this.viewsContainers.activitybars.value[s].visible=!1)}showActivitybar(e,t="title"){const s=this.viewsContainers.activitybars.value.findIndex(n=>n[t]===e);s!==-1&&(this.viewsContainers.activitybars.value[s].visible=!0)}registerRightSidebar(e){typeof e.component=="function"&&(e.component=h.loadAsyncComponent(e.component)),typeof e.visible>"u"&&(e.visible=!0);const t=this.viewsContainers.rightSidebars.value.findIndex(s=>s.id===e.id);t!==-1?this.viewsContainers.rightSidebars.value[t]=e:this.viewsContainers.rightSidebars.value.push(e)}getRightSidebars(){return this.viewsContainers.rightSidebars.value}hideRightSidebar(e,t="title"){const s=this.viewsContainers.rightSidebars.value.findIndex(n=>n[t]===e);s!==-1&&(this.viewsContainers.rightSidebars.value[s].visible=!1)}showRightSidebar(e,t="title"){const s=this.viewsContainers.rightSidebars.value.findIndex(n=>n[t]===e);s!==-1&&(this.viewsContainers.rightSidebars.value[s].visible=!0)}getComponentConfings(){return this.componentConfigs}getComponentConfingByType(e){return this.componentConfigs[e]}computedComponentSchemaGroups(){const e=[];Object.values(this.componentConfigs).forEach(t=>{if(!this.hiddenComponents.includes(t.defaultSchema.type)&&t.groupName){const s=this.componentGroupNameMap[t.groupName]??t.groupName;let n=e.findIndex(r=>r.title===s);n===-1&&(e.push({title:s,list:[]}),n=e.length-1);const i=e[n].list.findIndex(r=>r.type===t.defaultSchema.type);i!==-1?e[n].list[i]=t.defaultSchema:e[n].list.push(t.defaultSchema)}}),e.sort((t,s)=>{const n=this.sortedGroups.indexOf(t.title),i=this.sortedGroups.indexOf(s.title);return n===-1?1:i===-1?-1:n-i}),e.forEach(t=>{t.list.sort((s,n)=>{var u,l;const i=((u=this.componentConfigs[s.type])==null?void 0:u.sort)??1e3,r=((l=this.componentConfigs[n.type])==null?void 0:l.sort)??1e3;return i-r})}),this.componentSchemaGroups.value=e}getComponentSchemaGroups(){return this.componentSchemaGroups}setComponentGroupNameMap(e,t){this.componentGroupNameMap[e]=t}clearComponentGroupNameMap(){this.componentGroupNameMap={}}setSortedGroups(e){this.sortedGroups=e,this.computedComponentSchemaGroups()}clearSortedGroups(){this.sortedGroups=[],this.computedComponentSchemaGroups()}hideComponent(e){this.hiddenComponents.push(e),this.computedComponentSchemaGroups()}showComponent(e){this.hiddenComponents=this.hiddenComponents.filter(t=>t!==e),this.computedComponentSchemaGroups()}setHideComponents(e){this.hiddenComponents=e,this.computedComponentSchemaGroups()}setInitialized(e){this.initialized.value=e}addPublicMethod(e){const t=e.methodName??e.name,s=e.method??e.handler;this.publicMethods[t]={...e,name:t,handler:s}}removePublicMethod(e){delete this.publicMethods[e]}}const f=new d;exports.PluginManager=d;exports.pluginManager=f;