UNPKG

epic-designer-gold

Version:

基于vue3的设计器,可视化开发页面表单

2 lines (1 loc) 11.4 kB
"use strict";var B=Object.defineProperty;var M=(s,e,n)=>e in s?B(s,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[e]=n;var l=(s,e,n)=>M(s,typeof e!="symbol"?e+"":e,n);const p=require("vue"),k=require("./index-BoL2PSBk.cjs"),h=(s,e)=>p.defineAsyncComponent({loader:s,loadingComponent:e,delay:80});function m(s=10){const e="abcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let i=0;i<s;i++){const t=Math.floor(Math.random()*e.length);n+=e[t]}return n}function F(s){return s.charAt(0).toUpperCase()+s.slice(1)}const{t:S}=k.useLocale();function d(s,e=new WeakMap){if(typeof s!="object"||s===null)return s;if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=s.map(t=>d(t,e));return e.set(s,i),i}const n={};return e.set(s,n),Object.keys(s).forEach(i=>{n[i]=d(s[i],e)}),n}function P(s){const[e]=x([d(s)],n=>{var t,o;const i={...n,id:`${n.type}_${m(8)}`};return(i.field||i.input)&&!((o=(t=G.getComponentConfingByType(i.type))==null?void 0:t.editConstraints)!=null&&o.fixedField)&&(i.field=i.id),i});return e}function C(s,e,n=!0){for(const[i,t]of Object.entries(e)){let o=s==null?void 0:s[i];o&&t&&typeof o=="object"&&typeof t=="object"?(Array.isArray(o)&&!Array.isArray(t)?o=s[i]={}:!Array.isArray(o)&&Array.isArray(t)&&(o=s[i]=[]),C(o,t,n)):s[i]=t}n&&Object.keys(s).reverse().forEach(i=>{e.hasOwnProperty(i)||(Array.isArray(s)?s.splice(Number(i),1):delete s[i])})}function z(s,e,n=[],i=new WeakMap){const t=o=>{if(Array.isArray(o))return o.map(t);if(typeof o=="object"&&o!==null){if(i.has(o))return"[Circular]";i.set(o,!0);const r=Object.keys(o).sort(),a={};return r.forEach(c=>{n.includes(c)||(a[c]=t(o[c]))}),i.delete(o),a}else return o};return JSON.stringify(t(s))===JSON.stringify(t(e))}function E(s,e){const n=[];let i=!1;function t(o){if(n.push(o),o.id===e&&(i=!0),!i&&o.children!=null&&o.children.length>0)for(let r=0;r<o.children.length&&(t(o.children[r]),!i);r++);if(!i&&o.slots)for(let r in o.slots)for(let a=0;a<o.slots[r].length&&(t(o.slots[r][a]),!i);a++);i||n.pop()}return s.forEach(t),i||console.error(`没有查询到id为${e}的节点`),n}function O(s,e,n){const i=e.split(".");let t=s;for(let o=0;o<i.length;o++){if(t==null)return n;t=t[i[o]]}return t===void 0?n:t}function L(s,e,n){const i=e.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let t=s;for(let o=0;o<i.length-1;o++){const r=i[o];t[r]==null&&(t[r]=isNaN(Number(i[o+1]))?{}:[]),t=t[r]}return t[i[i.length-1]]=n,s}function R(s,e="default"){return b(s,e).map(i=>i.field)}function b(s,e="default"){const n=f(s,t=>{var o;return t.type==="form"&&(((o=t.componentProps)==null?void 0:o.name)??t.name===e)},!0);return f((n==null?void 0:n.children)??[],t=>!!t.input,!1,t=>t.type!=="subform")}function f(s,e,n=!1,i){const t=[],o=[...s];for(;o.length;){const r=o.pop();if(r!=null&&r.children&&(!i||i(r))&&o.push(...r.children),r!=null&&r.slots&&(!i||i(r)))for(let a in r.slots)o.push(...r.slots[a]);if(e(r)&&(t.push(r),n))return r}return n?!1:t}function x(s,e,n){const i=[...s];for(;i.length;){const t=i.pop();if(t!=null&&t.children&&(!n||n(t))&&i.push(...t.children),t!=null&&t.slots&&(!n||n(t)))for(let o in t.slots)i.push(...t.slots[o]);C(t,e(t))}return s}function T(s,e){const n=f(s,i=>i.id===e,!0);if(!n)throw new Error(`没有查询到id为${e}的节点`);return n}function D(s,e){const n=[{type:"",children:s}];let i=0,t=null;if(f(n,o=>{if(t=o.children??null,!t){if(o!=null&&o.slots)for(let r in o.slots){t=o.slots[r];for(let a=0;a<t.length;a++)if(t[a].id===e)return i=a,!0}return!1}for(let r=0;r<t.length;r++)if(t[r].id===e)return i=r,!0;return!1},!0),!t)throw new Error(`没有查询到id为${e}的节点`);return{list:t,schema:t[i],index:i}}function V(s){const e={schemas:[{type:"page",id:"root",label:S("page"),children:[{label:S("form"),type:"form",icon:"epic-icon-daibanshixiang",labelWidth:s.config.labelWidth||100,name:"default",componentProps:{layout:s.config.layout||"horizontal",labelWidth:s.config.labelWidth||100,labelLayout:s.config.labelLayout==="flex"?"fixed":"flex",labelCol:s.config.labelCol||{span:5},wrapperCol:s.config.wrapperCol||{span:19},hideRequiredMark:s.config.hideRequiredMark||!1,colon:s.config.colon||!0,labelAlign:s.config.labelAlign||"right",size:s.config.size||"middle"},children:[],id:"form_"+m()}],componentProps:{style:{padding:"16px"}}}],script:s.script||""};return e.schemas[0].children[0].children=u(s.list),e}function u(s,e){return s.map(n=>{var c,v,w;let i=n.type??"";const t=n.options??{},o=(y,g)=>{i===y&&(i=g,t.defaultValue&&(t.defaultValue=JSON.parse(t.defaultValue)))};if(o("uploadImg","upload-image"),o("uploadFile","upload-file"),i==="date"&&t.range&&(t.type="daterange",delete t.range),(i==="date"||i==="time")&&(t.valueFormat=t.format),i==="textarea"){const{minRows:y,maxRows:g}=t;t.autoSize={minRows:y,maxRows:g},delete t.minRows,delete t.maxRows}i==="number"&&!t.precision&&delete t.precision,t.width&&(t.style={width:t.width},delete t.width),i==="grid"&&(i="row"),e&&e.type==="grid"&&(i="col",t.span=n.span,n.key=m());const r={label:n.label,type:i,icon:n.icon||"",field:n.model,componentProps:t,id:n.key};return(t.noFormItem||!t.showLabel)&&(r.noFormItem=!0,delete t.noFormItem,delete t.showLabel),t.clearable&&(t.allowClear=!0,delete t.clearable),["input","textarea","number","password","select","cascader","checkbox","radio","date","time","slider","switch","color-picker","upload-file","upload-image"].includes(i)&&(r.input=!0,((v=(c=n.rules)==null?void 0:c[0])==null?void 0:v.required)===!1&&n.rules.shift(),((w=n.rules)==null?void 0:w.length)>0&&(r.rules=n.rules)),n.list&&(r.children=u(n.list,n)),n.columns&&(r.children=u(n.columns,n)),n.trs&&(r.children=u(n.trs,n)),n.tds&&(r.children=u(n.tds,n)),r})}function N(s){return{all:s=s||new Map,on:function(e,n){var i=s.get(e);i?i.push(n):s.set(e,[n])},off:function(e,n){var i=s.get(e);i&&(n?i.splice(i.indexOf(n)>>>0,1):s.set(e,[]))},emit:function(e,n){var i=s.get(e);i&&i.slice().map(function(t){t(n)}),(i=s.get("*"))&&i.slice().map(function(t){t(e,n)})}}}const A=N();class I{constructor(){l(this,"initialized",p.ref(!1));l(this,"sourceData",[]);l(this,"components",{});l(this,"componentConfigs",{});l(this,"baseComponentTypes",[]);l(this,"componentSchemaGroups",p.ref([]));l(this,"hiddenComponents",[]);l(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"}]);l(this,"componentGroupNameMap",{});l(this,"sortedGroups",["表单","布局","业务组件"]);l(this,"viewsContainers",{activitybars:p.shallowRef([]),rightSidebars:p.shallowRef([])});l(this,"publicMethods",{})}component(e,n){typeof n=="function"&&(n=h(n)),this.components[e]=n}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]}setSourceData(e){this.sourceData=e,A.emit("updateSource",new Date)}getSourceData(){return Object.prototype.toString.call(this.sourceData)==="[object Array]"?this.sourceData:[]}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(e.component)),typeof e.visible>"u"&&(e.visible=!0);const n=this.viewsContainers.activitybars.value.findIndex(i=>i.id===e.id);n!==-1?this.viewsContainers.activitybars.value[n]=e:this.viewsContainers.activitybars.value.push(e)}getActivitybars(){return this.viewsContainers.activitybars.value}hideActivitybar(e,n="title"){const i=this.viewsContainers.activitybars.value.findIndex(t=>t[n]===e);i!==-1&&(this.viewsContainers.activitybars.value[i].visible=!1)}showActivitybar(e,n="title"){const i=this.viewsContainers.activitybars.value.findIndex(t=>t[n]===e);i!==-1&&(this.viewsContainers.activitybars.value[i].visible=!0)}registerRightSidebar(e){typeof e.component=="function"&&(e.component=h(e.component)),typeof e.visible>"u"&&(e.visible=!0);const n=this.viewsContainers.rightSidebars.value.findIndex(i=>i.id===e.id);n!==-1?this.viewsContainers.rightSidebars.value[n]=e:this.viewsContainers.rightSidebars.value.push(e)}getRightSidebars(){return this.viewsContainers.rightSidebars.value}hideRightSidebar(e,n="title"){const i=this.viewsContainers.rightSidebars.value.findIndex(t=>t[n]===e);i!==-1&&(this.viewsContainers.rightSidebars.value[i].visible=!1)}showRightSidebar(e,n="title"){const i=this.viewsContainers.rightSidebars.value.findIndex(t=>t[n]===e);i!==-1&&(this.viewsContainers.rightSidebars.value[i].visible=!0)}getComponentConfings(){return this.componentConfigs}getComponentConfingByType(e){return this.componentConfigs[e]}computedComponentSchemaGroups(){const e=[];Object.values(this.componentConfigs).forEach(n=>{if(!this.hiddenComponents.includes(n.defaultSchema.type)&&n.groupName){const i=this.componentGroupNameMap[n.groupName]??n.groupName;let t=e.findIndex(r=>r.title===i);t===-1&&(e.push({title:i,list:[]}),t=e.length-1);let o=e[t].list.findIndex(r=>r.type===n.defaultSchema.type);o!==-1?e[t].list[o]=n.defaultSchema:e[t].list.push(n.defaultSchema)}}),e.sort((n,i)=>{const t=this.sortedGroups.indexOf(n.title),o=this.sortedGroups.indexOf(i.title);return t===-1?1:o===-1?-1:t-o}),e.forEach(n=>{n.list.sort((i,t)=>{var a,c;const o=((a=this.componentConfigs[i.type])==null?void 0:a.sort)??1e3,r=((c=this.componentConfigs[t.type])==null?void 0:c.sort)??1e3;return o-r})}),this.componentSchemaGroups.value=e}getComponentSchemaGroups(){return this.componentSchemaGroups}setComponentGroupNameMap(e,n){this.componentGroupNameMap[e]=n}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(n=>n!==e),this.computedComponentSchemaGroups()}setHideComponents(e){this.hiddenComponents=e,this.computedComponentSchemaGroups()}setInitialized(e){this.initialized.value=e}addPublicMethod(e){const n=e.methodName??e.name,i=e.method??e.handler;this.publicMethods[n]={...e,name:n,handler:i}}removePublicMethod(e){delete this.publicMethods[e]}}const G=new I;exports.EventBus=A;exports.PluginManager=I;exports.capitalizeFirstLetter=F;exports.convertKFormData=V;exports.deepClone=d;exports.deepCompareAndModify=C;exports.deepEqual=z;exports.findSchemaById=T;exports.findSchemaInfoById=D;exports.findSchemas=f;exports.generateNewSchema=P;exports.getFormFields=R;exports.getFormSchemas=b;exports.getMatchedById=E;exports.getUUID=m;exports.getValueByPath=O;exports.loadAsyncComponent=h;exports.mapSchemas=x;exports.pluginManager=G;exports.recursionConvertedNode=u;exports.setValueByPath=L;