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