UNPKG

gepic

Version:

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

2 lines (1 loc) 5.78 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./string.cjs");require("vue");const A=require("../manager/pluginManager.cjs");require("@vueuse/core");require("../../hooks/store/index.cjs");function u(n,s=new WeakMap){if(typeof n!="object"||n===null)return n;if(s.has(n))return s.get(n);if(Array.isArray(n)){const t=n.map(e=>u(e,s));return s.set(n,t),t}const r={};return s.set(n,r),Object.keys(n).forEach(t=>{r[t]=u(n[t],s)}),r}function k(n){const[s]=S([u(n)],r=>{var e,i;const t={...r,id:`${r.type}_${h.getUUID(8)}`};return(t.field||t.input)&&!((i=(e=A.pluginManager.getComponentConfingByType(t.type))==null?void 0:e.editConstraints)!=null&&i.fixedField)&&(t.field=t.id),t});return s}function y(n,s,r=!0){for(const[t,e]of Object.entries(s))n[t]&&e&&typeof n[t]=="object"&&typeof e=="object"?(Array.isArray(n[t])&&!Array.isArray(e)?n[t]={}:!Array.isArray(n[t])&&Array.isArray(e)&&(n[t]=[]),y(n[t],e,r)):n[t]=e;r&&Object.keys(n).reverse().forEach(t=>{s.hasOwnProperty(t)||(Array.isArray(n)?n.splice(Number(t),1):delete n[t])})}function C(n,s,r=[],t=new WeakMap){const e=i=>{if(Array.isArray(i))return i.map(e);if(typeof i=="object"&&i!==null){if(t.has(i))return"[Circular]";t.set(i,!0);const l=Object.keys(i).sort(),o={};return l.forEach(a=>{r.includes(a)||(o[a]=e(i[a]))}),t.delete(i),o}else return i};return JSON.stringify(e(n))===JSON.stringify(e(s))}function I(n,s){const r=[];let t=!1;function e(i){if(r.push(i),i.id===s&&(t=!0),!t&&i.children!=null&&i.children.length>0)for(let l=0;l<i.children.length&&(e(i.children[l]),!t);l++);if(!t&&i.slots)for(const l in i.slots)for(let o=0;o<i.slots[l].length&&(e(i.slots[l][o]),!t);o++);t||r.pop()}return n.forEach(e),t||console.error(`没有查询到id为${s}的节点`),r}function F(n,s,r){const t=s.split(".");let e=n;for(let i=0;i<t.length;i++){if(e==null)return r;e=e[t[i]]}return e===void 0?r:e}function B(n,s,r){const t=s.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let e=n;for(let i=0;i<t.length-1;i++){const l=t[i];e[l]==null&&(e[l]=isNaN(Number(t[i+1]))?{}:[]),e=e[l]}return e[t[t.length-1]]=r,n}function x(n,s="default"){return w(n,s).map(t=>t.field)}function w(n,s="default"){const r=c(n,e=>{var i;return e.type==="form"&&(((i=e.componentProps)==null?void 0:i.name)??e.name===s)},!0);return c((r==null?void 0:r.children)??[],e=>!!e.input,!1,e=>e.type!=="subform")}function c(n,s,r=!1,t){const e=[],i=[...n];for(;i.length;){const l=i.pop();if(l!=null&&l.children&&(!t||t(l))&&i.push(...l.children),l!=null&&l.slots&&(!t||t(l)))for(const o in l.slots)i.push(...l.slots[o]);if(s(l)&&(e.push(l),r))return l}return r?!1:e}function S(n,s,r){const t=[...n];for(;t.length;){const e=t.pop();if(e!=null&&e.children&&(!r||r(e))&&t.push(...e.children),e!=null&&e.slots&&(!r||r(e)))for(const i in e.slots)t.push(...e.slots[i]);y(e,s(e))}return n}function M(n,s){const r=c(n,t=>t.id===s,!0);if(!r)throw new Error(`没有查询到id为${s}的节点`);return r}function P(n,s){const r=[{type:"",children:n}];let t=0,e=null;const i=c(r,l=>{if(e=l.children??null,!e){if(l!=null&&l.slots)for(const o in l.slots){e=l.slots[o];for(let a=0;a<e.length;a++)if(e[a].id===s)return t=a,!0}return!1}for(let o=0;o<e.length;o++)if(e[o].id===s)return t=o,!0;return!1},!0);if(!e)throw new Error(`没有查询到id为${s}的节点`);return{list:e,schema:e[t],index:t,parentSchema:i}}function q(n){const s={schemas:[{type:"page",id:"root",label:"页面",children:[{label:"表单",type:"form",icon:"epic-icon-daibanshixiang",labelWidth:n.config.labelWidth||100,name:"default",componentProps:{layout:n.config.layout||"horizontal",labelWidth:n.config.labelWidth||100,labelLayout:n.config.labelLayout==="flex"?"fixed":"flex",labelCol:n.config.labelCol||{span:5},wrapperCol:n.config.wrapperCol||{span:19},hideRequiredMark:n.config.hideRequiredMark||!1,colon:n.config.colon||!0,labelAlign:n.config.labelAlign||"right",size:n.config.size||"middle"},children:[],id:"form_"+h.getUUID()}],componentProps:{style:{padding:"16px"}}}],script:n.script||""};return s.schemas[0].children[0].children=f(n.list),s}function f(n,s){return n.map(r=>{var a,g,m;let t=r.type??"";const e=r.options??{},i=(p,d)=>{t===p&&(t=d,e.defaultValue&&(e.defaultValue=JSON.parse(e.defaultValue)))};if(i("uploadImg","upload-image"),i("uploadFile","upload-file"),t==="date"&&e.range&&(e.type="daterange",delete e.range),(t==="date"||t==="time")&&(e.valueFormat=e.format),t==="textarea"){const{minRows:p,maxRows:d}=e;e.autoSize={minRows:p,maxRows:d},delete e.minRows,delete e.maxRows}t==="number"&&!e.precision&&delete e.precision,e.width&&(e.style={width:e.width},delete e.width),t==="grid"&&(t="row"),s&&s.type==="grid"&&(t="col",e.span=r.span,r.key=h.getUUID());const l={label:r.label,type:t,icon:r.icon||"",field:r.model,componentProps:e,id:r.key};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(t)&&(l.input=!0,((g=(a=r.rules)==null?void 0:a[0])==null?void 0:g.required)===!1&&r.rules.shift(),((m=r.rules)==null?void 0:m.length)>0&&(l.rules=r.rules)),r.list&&(l.children=f(r.list,r)),r.columns&&(l.children=f(r.columns,r)),r.trs&&(l.children=f(r.trs,r)),r.tds&&(l.children=f(r.tds,r)),l})}exports.convertKFormData=q;exports.deepClone=u;exports.deepCompareAndModify=y;exports.deepEqual=C;exports.findSchemaById=M;exports.findSchemaInfoById=P;exports.findSchemas=c;exports.generateNewSchema=k;exports.getFormFields=x;exports.getFormSchemas=w;exports.getMatchedById=I;exports.getValueByPath=F;exports.mapSchemas=S;exports.recursionConvertedNode=f;exports.setValueByPath=B;