componentMap-6df01015.js 15 KB

1
  1. var Re=Object.defineProperty;var ye=Object.getOwnPropertySymbols;var $e=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var Ae=(e,o,n)=>o in e?Re(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,R=(e,o)=>{for(var n in o||(o={}))$e.call(o,n)&&Ae(e,n,o[n]);if(ye)for(var n of ye(o))Le.call(o,n)&&Ae(e,n,o[n]);return e};var j=(e,o,n)=>new Promise((r,v)=>{var u=c=>{try{O(n.next(c))}catch(h){v(h)}},m=c=>{try{O(n.throw(c))}catch(h){v(h)}},O=c=>c.done?r(c.value):Promise.resolve(c.value).then(u,m);O((n=n.apply(e,o)).next())});import{u as s,g as Ne,c as K,w as Z,an as Me,x as me,H as ve,h as Ge,d as Ue,J as We,r as ge,f as J,o as Ye,Y as ue,a6 as Fe,a7 as le,l as He,ag as we,ah as Te,N as fe,Z as Ke,F as Xe,a8 as Ie,ab as qe,aa as ze,am as Je}from"./vue-8fccce23.js";import{b as Ze,n as Qe,c as et,o as tt,e as nt,g as st,f as at,p as ot,q as rt,r as it,B as ct,C as ut}from"./FormItem.vue_vue_type_script_lang-35d3ca4d.js";import{a as lt,y as U,aB as Q,aQ as G,aR as ft,B as De,aS as Oe,av as de,d as _e,v as dt,p as P,h as pt,at as mt}from"./index.js";import{ai as Se,e as re,k as oe,s as X,al as pe,at as Pe,d as ee,v as Be,f as q,X as ht,Z as bt,R as yt,aa as At,A as te,aP as vt,aS as gt,ax as Ft,aA as wt,aT as Tt,aw as It,am as ke,aB as Ot,aU as Pt,aV as Bt,aC as Dt,aW as ie,aX as Ve,a5 as _t}from"./antd-ecb53b14.js";import{b as St}from"./index-8cbf1e33.js";import{S as kt}from"./index-22d6b33a.js";import{C as Vt}from"./index-3eef3423.js";lt();const jt=["DatePicker","MonthPicker","WeekPicker","TimePicker"];function xt(){return[...jt,"RangePicker"]}const je=["Input","InputPassword","InputNumber","InputSearch","InputTextArea"];function Ct(e,o){return e&&je.includes(e)&&o&&Se(o)?`${o}`:o}const xe=xt();function Et(e,o,n){const r=/^\[(.+)\]$/;if(r.test(e)){const v=e.match(r);if(v&&v[1]){const u=v[1].split(",");return o=Array.isArray(o)?o:[o],u.forEach((m,O)=>{X(n,m.trim(),o[O])}),!0}}}function Rt(e,o,n){const r=/^\{(.+)\}$/;if(r.test(e)){const v=e.match(r);if(v&&v[1]){const u=v[1].split(",");return o=U(o)?o:{},u.forEach(m=>{X(n,m.trim(),o[m.trim()])}),!0}}}function $t({defaultValueRef:e,getSchema:o,formModel:n,getProps:r}){function v(c){var I,_;if(!U(c))return{};const h={};for(const B of Object.entries(c)){let[,f]=B;const[p]=B;if(!p||Q(f)&&f.length===0||re(f))continue;const S=s(r).transformDateFunc;U(f)&&(f=S==null?void 0:S(f)),Q(f)&&((I=f[0])!=null&&I.format)&&((_=f[1])!=null&&_.format)&&(f=f.map(A=>S==null?void 0:S(A))),oe(f)&&(f===""?f=void 0:f=f.trim()),!Et(p,f,h)&&!Rt(p,f,h)&&X(h,p,f)}return u(h)}function u(c){const h=s(r).fieldMapToTime;if(!h||!Array.isArray(h))return c;for(const[I,[_,B],f="YYYY-MM-DD"]of h){if(!I||!_||!B)continue;if(!pe(c,I)){Pe(c,I);continue}const[p,S]=pe(c,I),[A,w]=Array.isArray(f)?f:[f,f];!ee(p)&&!Be(p)&&X(c,_,m(p,A)),!ee(S)&&!Be(S)&&X(c,B,m(S,w)),Pe(c,I)}return c}function m(c,h){return h==="timestamp"?G(c).unix():h==="timestampStartDay"?G(c).startOf("day").unix():G(c).format(h)}function O(){const c=s(o),h={};c.forEach(I=>{const{defaultValue:_,defaultValueObj:B}=I,f=Object.keys(B||{});f.length&&f.map(p=>{h[p]=B[p],n[p]===void 0&&(n[p]=B[p])}),ee(_)||(h[I.field]=_,n[I.field]===void 0&&(n[I.field]=_))}),e.value=q(h)}return{handleFormValues:v,initDefault:O}}const H=24;function Lt({advanceState:e,emit:o,getProps:n,getSchema:r,formModel:v,defaultValueRef:u}){const m=Ne(),{realWidthRef:O,screenEnum:c,screenRef:h}=ft(),I=K(()=>{if(!e.isAdvanced)return 0;const A=s(n).emptySpan||0;if(Se(A))return A;if(U(A)){const{span:w=0}=A,x=s(h);return A[x.toLowerCase()]||w||0}return 0}),_=De(p,30);Z([()=>s(r),()=>e.isAdvanced,()=>s(O)],()=>{const{showAdvancedButton:A}=s(n);A&&_()},{immediate:!0});function B(A,w=0,x=!1){const $=s(O),L=parseInt(A.md)||parseInt(A.xs)||parseInt(A.sm)||A.span||H,k=parseInt(A.lg)||L,N=parseInt(A.xl)||k,M=parseInt(A.xxl)||N;return $<=c.LG?w+=L:$<c.XL?w+=k:$<c.XXL?w+=N:w+=M,x?(e.hideAdvanceBtn=!1,w<=H*2?(e.hideAdvanceBtn=!0,e.isAdvanced=!0):w>H*2&&w<=H*(s(n).autoAdvancedLine||3)?e.hideAdvanceBtn=!1:e.isLoad||(e.isLoad=!0,e.isAdvanced=!e.isAdvanced),{isAdvanced:e.isAdvanced,itemColSum:w}):w>H*(s(n).alwaysShowLines||1)?{isAdvanced:e.isAdvanced,itemColSum:w}:{isAdvanced:!0,itemColSum:w}}const f=Me({});function p(){var $;let A=0,w=0;const{baseColProps:x={}}=s(n);for(const L of s(r)){const{show:k,colProps:N}=L;let M=!0;if(ht(k)&&(M=k),re(k)&&(M=k({schema:L,model:v,field:L.field,values:R(R({},s(u)),v)})),M&&(N||x)){const{itemColSum:W,isAdvanced:Y}=B(R(R({},x),N),A);A=W||0,Y&&(w=A),f[L.field]=Y}}($=m==null?void 0:m.proxy)==null||$.$forceUpdate(),e.actionSpan=w%H+s(I),B(s(n).actionColOptions||{span:H},A,!0),o("advanced-change")}function S(){e.isAdvanced=!e.isAdvanced}return{handleToggleAdvanced:S,fieldsIsAdvancedMap:f}}function Nt(e,o={}){const n=/^\[(.+)\]$/;if(n.test(e)){const r=e.match(n);if(r&&r[1]){const v=r[1].split(",");if(!v.length)return;const u=[];return v.forEach((m,O)=>{X(u,O,o[m.trim()])}),u.filter(Boolean).length?u:void 0}}}function Mt(e,o={}){const n=/^\{(.+)\}$/;if(n.test(e)){const r=e.match(n);if(r&&r[1]){const v=r[1].split(",");if(!v.length)return;const u={};return v.forEach(m=>{X(u,m.trim(),o[m.trim()])}),Object.values(u).filter(Boolean).length?u:void 0}}}function Gt({emit:e,getProps:o,formModel:n,getSchema:r,defaultValueRef:v,formElRef:u,schemaRef:m,handleFormValues:O}){function c(){return j(this,null,function*(){const{resetFunc:t,submitOnReset:a}=s(o);t&&re(t)&&(yield t()),s(u)&&(Object.keys(n).forEach(i=>{const b=s(r).find(V=>V.field===i),F=b==null?void 0:b.defaultValueObj,D=Object.keys(F||{});D.length&&D.map(V=>{n[V]=F[V]}),n[i]=Ut(b,v,i)}),me(()=>N()),e("reset",ve(n)),a&&W())})}const h=()=>s(r).map(t=>[...t.fields||[],t.field]).flat(1).filter(Boolean);function I(t){return j(this,null,function*(){if(Object.keys(t).length===0)return;const a=h(),g=".",i=a.filter(F=>String(F).indexOf(g)>=0),b=[];a.forEach(F=>{const D=s(r).find(y=>y.field===F);let V=pe(t,F);const ce=Reflect.has(t,F);V=Ct(D==null?void 0:D.component,V);const{componentProps:ne}=D||{};let C=ne;typeof ne=="function"&&(C=C({formModel:s(n),formActionType:Y}));const d=Nt(F,t)||Mt(F,t);if(ce||d){const y=d||V;if(x(F))if(Array.isArray(y)){const T=[];for(const E of y)T.push(E?G(E):null);s(n)[F]=T}else s(n)[F]=y?C!=null&&C.valueFormat?y:G(y):null;else s(n)[F]=y;C!=null&&C.onChange&&(C==null||C.onChange(y)),b.push(F)}else i.forEach(y=>{try{const T=y.split(".").reduce((E,z)=>E[z],t);Oe(T)&&(s(n)[y]=s(T),b.push(y))}catch(T){Oe(v.value[y])&&(s(n)[y]=q(s(v.value[y])))}})}),$(b).catch(F=>{})})}function _(t){return j(this,null,function*(){const a=q(s(r));if(!t)return;let g=oe(t)?[t]:t;oe(t)&&(g=[t]);for(const i of g)B(i,a);m.value=a})}function B(t,a){if(oe(t)){const g=a.findIndex(i=>i.field===t);g!==-1&&(delete n[t],a.splice(g,1))}}function f(t,a,g=!1){return j(this,null,function*(){const i=q(s(r)),b=Array.isArray(t)?t.map(V=>V.field):[t.field];if(i.find(V=>b.includes(V.field))){de("There are schemas that have already been added");return}const F=i.findIndex(V=>V.field===a),D=U(t)?[t]:t;!a||F===-1||g?g?i.unshift(...D):i.push(...D):F!==-1&&i.splice(F+1,0,...D),m.value=i,A(t)})}function p(t){return j(this,null,function*(){let a=[];if(U(t)&&a.push(t),Q(t)&&(a=[...t]),!a.every(i=>i.component==="Divider"||Reflect.has(i,"field")&&i.field)){de("All children of the form Schema array that need to be updated must contain the `field` field");return}m.value=a})}function S(t){return j(this,null,function*(){let a=[];if(U(t)&&a.push(t),Q(t)&&(a=[...t]),!a.every(b=>b.component==="Divider"||Reflect.has(b,"field")&&b.field)){de("All children of the form Schema array that need to be updated must contain the `field` field");return}const i=[];s(r).forEach(b=>{let F;if(a.forEach(D=>{b.field===D.field&&(F=D)}),F!==void 0&&b.field===F.field){const D=_e(b,F);i.push(D)}else i.push(b)}),A(i),m.value=bt(i,"field")})}function A(t){let a=[];U(t)&&a.push(t),Q(t)&&(a=[...t]);const g={},i=w();a.forEach(b=>{b.component!="Divider"&&Reflect.has(b,"field")&&b.field&&!ee(b.defaultValue)&&(!(b.field in i)||ee(i[b.field]))&&(g[b.field]=b.defaultValue)}),I(g)}function w(){return s(u)?O(ve(s(n))):{}}function x(t){return s(r).some(a=>a.field===t&&a.component?xe.includes(a.component):!1)}function $(t){return j(this,null,function*(){var g;const a=yield(g=s(u))==null?void 0:g.validateFields(t);return O(a)})}function L(t){return j(this,null,function*(){var a;yield(a=s(u))==null?void 0:a.setProps(t)})}function k(t){return j(this,null,function*(){var i;let a;t===void 0?a=h():a=t===Array.isArray(t)?t:void 0;const g=yield(i=s(u))==null?void 0:i.validate(a);return O(g)})}function N(t){return j(this,null,function*(){var a;yield(a=s(u))==null?void 0:a.clearValidate(t)})}function M(t,a){return j(this,null,function*(){var g;yield(g=s(u))==null?void 0:g.scrollToField(t,a)})}function W(t){return j(this,null,function*(){t&&t.preventDefault();const{submitFunc:a}=s(o);if(a&&re(a)){yield a();return}if(s(u))try{const i=yield k();e("submit",i)}catch(i){if((i==null?void 0:i.outOfDate)===!1&&(i!=null&&i.errorFields))return;throw new Error(i)}})}const Y={getFieldsValue:w,setFieldsValue:I,resetFields:c,updateSchema:S,resetSchema:p,setProps:L,removeSchemaByField:_,appendSchemaByField:f,clearValidate:N,validateFields:$,validate:k,submit:W,scrollToField:M};return{handleSubmit:W,clearValidate:N,validate:k,validateFields:$,getFieldsValue:w,updateSchema:S,resetSchema:p,appendSchemaByField:f,removeSchemaByField:_,resetFields:c,setFieldsValue:I,scrollToField:M}}function Ut(e,o,n){let r=q(o.value[n]);return Yt(e)?r||"":(!r&&e&&Wt(e)&&(r=[0,0]),!r&&e&&e.component==="ApiTree"&&(r=[]),r)}function Wt(e){if(e.component==="Slider"&&e.componentProps&&"range"in e.componentProps)return!0}function Yt(e){return(e==null?void 0:e.component)&&je.includes(e.component)}const Ht=Symbol();function Kt(e){return dt(e,Ht)}function Xt(v){return j(this,arguments,function*({getSchema:e,getProps:o,formElRef:n,isInitedDefault:r}){Ge(()=>j(this,null,function*(){if(s(r)||!s(o).autoFocusFirstItem)return;yield me();const u=s(e),m=s(n),O=m==null?void 0:m.$el;if(!m||!O||!u||u.length===0)return;const c=u[0];if(!c.component||!c.component.includes("Input"))return;const h=O.querySelector(".ant-row:first-child input");h&&(h==null||h.focus())}))})}const qt={model:{type:Object,default:()=>({})},labelWidth:{type:[Number,String],default:0},fieldMapToTime:{type:Array,default:()=>[]},compact:P.bool,schemas:{type:Array,default:()=>[]},mergeDynamicData:{type:Object,default:null},baseRowStyle:{type:Object},baseColProps:{type:Object},autoSetPlaceHolder:P.bool.def(!0),autoSubmitOnEnter:P.bool.def(!1),submitOnReset:P.bool,submitOnChange:P.bool,size:P.oneOf(["default","small","large"]).def("default"),disabled:P.bool,emptySpan:{type:[Number,Object],default:0},showAdvancedButton:P.bool,transformDateFunc:{type:Function,default:e=>{var o,n;return(n=(o=e==null?void 0:e.format)==null?void 0:o.call(e,"YYYY-MM-DD HH:mm:ss"))!=null?n:e}},rulesMessageJoinLabel:P.bool.def(!0),autoAdvancedLine:P.number.def(3),alwaysShowLines:P.number.def(1),showActionButtonGroup:P.bool.def(!0),actionColOptions:Object,showResetButton:P.bool.def(!0),autoFocusFirstItem:P.bool,resetButtonOptions:Object,showSubmitButton:P.bool.def(!0),submitButtonOptions:Object,resetFunc:Function,submitFunc:Function,hideRequiredMark:P.bool,labelCol:Object,layout:P.oneOf(["horizontal","vertical","inline"]).def("horizontal"),tableAction:{type:Object},wrapperCol:Object,colon:P.bool,labelAlign:P.string,rowProps:Object},an=Ue({name:"BasicForm",__name:"BasicForm",props:qt,emits:["advanced-change","reset","submit","register","field-value-change"],setup(e,{expose:o,emit:n}){const r=e,v=We(),u=ge({}),m=St(),O=ge({isAdvanced:!0,hideAdvanceBtn:!1,isLoad:!1,actionSpan:6}),c=J({}),h=J(!1),I=J(),_=J(null),B=J(null),{prefixCls:f}=pt("basic-form"),p=K(()=>R(R({},r),s(I))),S=K(()=>[f,{[`${f}--compact`]:s(p).compact}]),A=K(()=>{const{baseRowStyle:d={},rowProps:y}=s(p);return R({style:d},y)}),w=K(()=>R(R(R({},v),r),s(p))),x=K(()=>{var y;const d=s(_)||s(p).schemas;for(const T of d){const{defaultValue:E,component:z,componentProps:se={},isHandleDateDefaultValue:Ce=!0}=T;if(Ce&&E&&z&&xe.includes(z)){const Ee={schema:T,tableAction:(y=r.tableAction)!=null?y:{},formModel:u,formActionType:{}},ae=se?typeof se=="function"?se(Ee).valueFormat:se.valueFormat:null;if(!Array.isArray(E))T.defaultValue=ae?G(E).format(ae):G(E);else{const he=[];E.forEach(be=>{he.push(ae?G(be).format(ae):G(be))}),T.defaultValue=he}}}return s(p).showAdvancedButton?q(d.filter(T=>T.component!=="Divider")):q(d)});Lt({advanceState:O,emit:n,getProps:p,getSchema:x,formModel:u,defaultValueRef:c});const{handleFormValues:$,initDefault:L}=$t({getProps:p,defaultValueRef:c,getSchema:x,formModel:u});Xt({getSchema:x,getProps:p,isInitedDefault:h,formElRef:B});const{handleSubmit:k,setFieldsValue:N,clearValidate:M,validate:W,validateFields:Y,getFieldsValue:t,updateSchema:a,resetSchema:g,appendSchemaByField:i,removeSchemaByField:b,resetFields:F,scrollToField:D}=Gt({emit:n,getProps:p,formModel:u,getSchema:x,defaultValueRef:c,formElRef:B,schemaRef:_,handleFormValues:$});Kt({resetAction:F,submitAction:k}),Z(()=>s(p).model,()=>{const{model:d}=s(p);d&&N(d)},{immediate:!0}),Z(()=>r.schemas,d=>{g(d!=null?d:[])}),Z(()=>x.value,d=>{me(()=>{var y;(y=m==null?void 0:m.redoModalHeight)==null||y.call(m)}),!s(h)&&d!=null&&d.length&&(L(),h.value=!0)}),Z(()=>u,De(()=>{s(p).submitOnChange&&k()},300),{deep:!0});function V(d){return j(this,null,function*(){I.value=_e(s(I)||{},d)})}function ce(d,y,T){u[d]=y,n("field-value-change",d,y),T&&T.itemProps&&!T.itemProps.autoLink&&Y([d]).catch(E=>{})}function ne(d){const{autoSubmitOnEnter:y}=s(p);if(y&&d.key==="Enter"&&d.target&&d.target instanceof HTMLElement){const T=d.target;T&&T.tagName&&T.tagName.toUpperCase()=="INPUT"&&k()}}const C={getFieldsValue:t,setFieldsValue:N,resetFields:F,updateSchema:a,resetSchema:g,setProps:V,removeSchemaByField:b,appendSchemaByField:i,clearValidate:M,validateFields:Y,validate:W,submit:k,scrollToField:D};return K(()=>R(R({},p.value),O)),o(R({},C)),Ye(()=>{L(),n("register",C)}),(d,y)=>(ue(),Fe(s(At),ze(w.value,{class:S.value,ref_key:"formElRef",ref:B,model:u,onKeypress:Je(ne,["enter"])}),{default:le(()=>[He(s(yt),we(Te(A.value)),{default:le(()=>[fe(d.$slots,"formHeader"),(ue(!0),Ke(Xe,null,Ie(x.value,T=>(ue(),Fe(Ze,{key:T.field,tableAction:d.tableAction,formActionType:C,schema:T,formProps:p.value,allDefaultValues:c.value,formModel:u,setFormModel:ce},qe({_:2},[Ie(Object.keys(d.$slots),E=>({name:E,fn:le(z=>[fe(d.$slots,E,we(Te(z||{})))])}))]),1032,["tableAction","schema","formProps","allDefaultValues","formModel"]))),128)),fe(d.$slots,"formFooter")]),_:3},16)]),_:3},16,["class","model","onKeypress"]))}});const l=new Map;l.set("Input",te);l.set("InputGroup",te.Group);l.set("InputPassword",te.Password);l.set("InputSearch",te.Search);l.set("InputTextArea",te.TextArea);l.set("InputNumber",vt);l.set("AutoComplete",gt);l.set("ImageUpload",Qe);l.set("Select",Ft);l.set("ApiSelect",et);l.set("ApiTree",tt);l.set("TreeSelect",wt);l.set("ApiTreeSelect",nt);l.set("ApiRadioGroup",st);l.set("Switch",Tt);l.set("RadioButtonGroup",at);l.set("RadioGroup",It.Group);l.set("Checkbox",ke);l.set("CheckboxGroup",ke.Group);l.set("ApiCascader",ot);l.set("Cascader",Ot);l.set("Slider",Pt);l.set("Rate",Bt);l.set("Transfer",Dt);l.set("ApiTransfer",rt);l.set("DatePicker",ie);l.set("MonthPicker",ie.MonthPicker);l.set("RangePicker",ie.RangePicker);l.set("WeekPicker",ie.WeekPicker);l.set("TimePicker",Ve);l.set("TimeRangePicker",Ve.TimeRangePicker);l.set("StrengthMeter",kt);l.set("IconPicker",it);l.set("InputCountDown",Vt);l.set("Upload",ct);l.set("Divider",_t);l.set("CropperAvatar",ut);l.set("BasicTitle",mt);export{an as _};