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