epic-designer-dev
Version:
基于vue3的设计器,可视化开发页面表单。在epic-designer的基础上新增了字典选择器
2 lines (1 loc) • 5.96 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("vue");;/* empty css */require("vuedraggable");const y=require("./string.cjs");require("@vueuse/core");require("../../../hooks/src/store/index.cjs");const S=require("../manager/pluginManager.cjs");function p(r,s=new WeakMap){if(typeof r!="object"||r===null)return r;if(s.has(r))return s.get(r);if(Array.isArray(r)){const n=r.map(e=>p(e,s));return s.set(r,n),n}const t={};return s.set(r,t),Object.keys(r).forEach(n=>{t[n]=p(r[n],s)}),t}function A(r){const[s]=w([p(r)],t=>{var e,i;const n={...t,id:`${t.type}_${y.getUUID(8)}`};return(n.field||n.input)&&!((i=(e=S.pluginManager.getComponentConfingByType(n.type))==null?void 0:e.editConstraints)!=null&&i.fixedField)&&(n.field=n.id),n});return s}function g(r,s,t=!0){const n=r;for(const[e,i]of Object.entries(s))n[e]&&i&&typeof n[e]=="object"&&typeof i=="object"?(Array.isArray(n[e])&&!Array.isArray(i)?n[e]={}:!Array.isArray(n[e])&&Array.isArray(i)&&(n[e]=[]),g(n[e],i,t)):n[e]=i;t&&Object.keys(n).reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(s,e)||(Array.isArray(n)?n.splice(Number(e),1):delete n[e])})}function b(r,s,t=[],n=new WeakMap){const e=i=>{if(Array.isArray(i))return i.map(e);if(typeof i=="object"&&i!==null){if(n.has(i))return"[Circular]";n.set(i,!0);const l=Object.keys(i).sort(),o={};return l.forEach(a=>{t.includes(a)||(o[a]=e(i[a]))}),n.delete(i),o}else return i};return JSON.stringify(e(r))===JSON.stringify(e(s))}function C(r,s){const t=[];let n=!1;function e(i){if(t.push(i),i.id===s&&(n=!0),!n&&i.children&&i.children.length>0)for(let l=0;l<i.children.length&&(e(i.children[l]),!n);l++);if(!n&&i.slots)for(const l in i.slots)for(let o=0;o<i.slots[l].length&&(e(i.slots[l][o]),!n);o++);n||t.pop()}return r.forEach(e),n||console.error(`没有查询到id为${s}的节点`),t}function k(r,s,t){const n=s.split(".");let e=r;for(const i of n){if(e==null)return t;e=e[i]}return e===void 0?t:e}function I(r,s,t){const n=s.replaceAll(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let e=r;for(let i=0;i<n.length-1;i++){const l=n[i];e[l]==null&&(e[l]=Number.isNaN(Number(n[i+1]))?{}:[]),e=e[l]}return e[n[n.length-1]]=t,r}function F(r,s="default"){return m(r,s).map(n=>n.field)}function m(r,s="default"){const t=f(r,e=>{var i;return e.type==="form"&&(((i=e.componentProps)==null?void 0:i.name)??e.name===s)},!0);return f((t==null?void 0:t.children)??[],e=>!!e.input,!1,e=>e.type!=="subform")}function f(r,s,t=!1,n){const e=[],i=[...r];for(;i.length>0;){const l=i.pop();if(l!=null&&l.children&&(!n||n(l))&&i.push(...l.children),l!=null&&l.slots&&(!n||n(l)))for(const o in l.slots)i.push(...l.slots[o]);if(s(l)&&(e.push(l),t))return l}return t?!1:e}function w(r,s,t){const n=[...r];for(;n.length>0;){const e=n.pop();if(e!=null&&e.children&&(!t||t(e))&&n.push(...e.children),e!=null&&e.slots&&(!t||t(e)))for(const i in e.slots)n.push(...e.slots[i]);g(e,s(e))}return r}function B(r,s){const t=f(r,n=>n.id===s,!0);return t||null}function q(r,s){const t=[{type:"",children:r}];let n=0,e=null;const i=f(t,l=>{if(e=l.children??null,!e){if(l!=null&&l.slots)for(const o in l.slots){e=l.slots[o];for(const[a,u]of e.entries())if(u.id===s)return n=a,!0}return!1}for(const[o,a]of e.entries())if(a.id===s)return n=o,!0;return!1},!0);if(!e)throw new Error(`没有查询到id为${s}的节点`);return{index:n,parentSchema:i,schema:e[n],list:e}}function x(r){r.config||(r.config={});const s={schemas:[{componentProps:{style:{padding:"16px"}},id:"root",label:"页面",type:"page",children:[{label:"表单",type:"form",icon:"epic-icon-daibanshixiang",labelWidth:r.config.labelWidth||100,name:"default",componentProps:{colon:r.config.colon||!0,hideRequiredMark:r.config.hideRequiredMark||!1,labelAlign:r.config.labelAlign||"right",labelCol:r.config.labelCol||{span:5},labelLayout:r.config.labelLayout==="flex"?"fixed":"flex",labelWidth:r.config.labelWidth||100,layout:r.config.layout||"horizontal",size:r.config.size||"middle",wrapperCol:r.config.wrapperCol||{span:19}},children:[],id:`form_${y.getUUID()}`}]}],script:r.script||""};if(s.schemas&&s.schemas.length>0){const t=s.schemas[0];if(t.children&&t.children.length>0){const n=t.children[0];r.list&&(n.children=c(r.list))}}return s}function c(r,s){return r.map(t=>{var a,u;let n=t.type??"";const e=t.options??{},i=(d,h)=>{n===d&&(n=h,typeof e.defaultValue=="string"&&(e.defaultValue=JSON.parse(e.defaultValue)))};if(i("uploadImg","upload-image"),i("uploadFile","upload-file"),n==="date"&&e.range&&(e.type="daterange",delete e.range),(n==="date"||n==="time")&&(e.valueFormat=e.format),n==="textarea"){const{maxRows:d,minRows:h}=e;e.autoSize={maxRows:d,minRows:h},delete e.minRows,delete e.maxRows}n==="number"&&!e.precision&&delete e.precision,e.width&&(e.style={width:e.width},delete e.width),n==="grid"&&(n="row"),s&&s.type==="grid"&&(n="col",e.span=t.span,t.key=y.getUUID());const l={componentProps:e,field:t.model,icon:t.icon||"",id:t.key,label:t.label,type:n};return(e.noFormItem||!e.showLabel)&&(l.noFormItem=!0,delete e.noFormItem,delete e.showLabel),e.clearable&&(e.allowClear=!0,delete e.clearable),["input","textarea","number","password","select","cascader","checkbox","radio","date","time","slider","switch","color-picker","upload-file","upload-image"].includes(n)&&(l.input=!0,((u=(a=t.rules)==null?void 0:a[0])==null?void 0:u.required)===!1&&t.rules.shift(),t.rules&&t.rules.length>0&&(l.rules=t.rules)),t.list&&(l.children=c(t.list,t)),t.columns&&(l.children=c(t.columns,t)),t.trs&&(l.children=c(t.trs,t)),t.tds&&(l.children=c(t.tds,t)),l})}exports.convertKFormData=x;exports.deepClone=p;exports.deepCompareAndModify=g;exports.deepEqual=b;exports.findSchemaById=B;exports.findSchemaInfoById=q;exports.findSchemas=f;exports.generateNewSchema=A;exports.getFormFields=F;exports.getFormSchemas=m;exports.getMatchedById=C;exports.getValueByPath=k;exports.mapSchemas=w;exports.recursionConvertedNode=c;exports.setValueByPath=I;