| 1 |
- var xe=Object.defineProperty;var Ae=Object.getOwnPropertySymbols;var $e=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var ve=(e,o,a)=>o in e?xe(e,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[o]=a,C=(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 H,w as Z,am as Ne,g as Me,y as ue,J as Fe,h as Ge,d as Ue,K as We,r as ge,f as K,o as Ye,a5 as we,_ as de,a6 as pe,k as He,ag as Ke,ah as ze,a9 as me,Z as qe,F as Je,a8 as Te,ab as Xe,aa as Ie,al as Ze,b as Qe}from"./vue-4umLpMSY.js";import{_ as et}from"./FormItem.vue_vue_type_script_lang-BG_Hgd-5.js";import{b as tt,y as U,i as Q,aE as G,aF as nt,B as Oe,aS as Pe,aB as re,d as De,w as st,p as D,h as at,az as ot,aA as rt,aR as it}from"./entry/index-BNACB_--.js";import{aq as Ve,d as ee,k as z,l as ce,h as ie,s as q,ao as he,ap as Se,v as Be,a0 as ct,a2 as ut,R as lt,ai as ft,E as te,aE as dt,aF as pt,av as mt,aw as ht,aG as yt,as as bt,aH as ke,ax as At,aI as vt,aJ as Ft,ah as gt,aK as le,aL as _e,ab as wt}from"./antd-Cume0_44.js";import{b as Tt}from"./index-BcY2Kpt-.js";import{_ as It,f as Pt,e as St,g as Bt,h as Ot,j as Dt,k as Vt}from"./helper-UVqxDIO3.js";import{I as kt,B as _t}from"./index-Ba9m1Z2i.js";import{S as Et}from"./index-xdVQCFbC.js";import{_ as jt}from"./IconPicker.vue_vue_type_script_setup_true_lang-Dv_C7pJU.js";import{C as Rt}from"./index-1M-LKJ9F.js";import{C as Ct}from"./index-D7uXL0a9.js";const{t:pn}=tt(),xt=["DatePicker","MonthPicker","WeekPicker","TimePicker"];function $t(){return[...xt,"RangePicker"]}const Ee=["Input","InputPassword","InputNumber","InputSearch","InputTextArea"];function Lt(e,o){return e&&Ee.includes(e)&&o&&Ve(o)?`${o}`:o}const je=$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 Mt(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 Gt({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)&&!Mt(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)&&!Be(P)&&q(l,V,t(P,F)),!ee(b)&&!Be(b)&&q(l,_,t(b,T)),Se(l,I)}return l}function t(l,m){return m==="timestamp"?G(l).unix():m==="timestampStartDay"?G(l).startOf("day").unix():G(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 Y=24;function Ut({advanceState:e,emit:o,getProps:a,getSchema:r,formModel:h,defaultValueRef:y}){const t=Me(),{realWidthRef:f,screenEnum:l,screenRef:m}=nt(),I=H(()=>{if(!e.isAdvanced)return 0;const F=s(a).emptySpan||0;if(Ve(F))return F;if(U(F)){const{span:T=0}=F,M=s(m);return F[M.toLowerCase()]||T||0}return 0}),V=Oe(P,30);Z([()=>s(r),()=>e.isAdvanced,()=>s(f)],()=>{const{showAdvancedButton:F}=s(a);F&&V()},{immediate:!0});function _(F,T=0,M=!1){const k=s(f),$=parseInt(F.md)||parseInt(F.xs)||parseInt(F.sm)||F.span||Y,j=parseInt(F.lg)||$,R=parseInt(F.xl)||j,L=parseInt(F.xxl)||R;return k<=l.LG?T+=$:k<l.XL?T+=j:k<l.XXL?T+=R:T+=L,M?(e.hideAdvanceBtn=!1,T<=Y*2?(e.hideAdvanceBtn=!0,e.isAdvanced=!0):T>Y*2&&T<=Y*(s(a).autoAdvancedLine||3)?e.hideAdvanceBtn=!1:e.isLoad||(e.isLoad=!0,e.isAdvanced=!e.isAdvanced),{isAdvanced:e.isAdvanced,itemColSum:T}):T>Y*(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:M={}}=s(a);for(const $ of s(r)){const{show:j,colProps:R}=$;let L=!0;if(ct(j)&&(L=j),ce(j)&&(L=j({schema:$,model:h,field:$.field,values:C(C({},s(y)),h)})),L&&(R||M)){const{itemColSum:W,isAdvanced:J}=_(C(C({},M),R),F);F=W||0,J&&(T=F),p[$.field]=J}}(k=t==null?void 0:t.proxy)==null||k.$forceUpdate(),e.actionSpan=T%Y+s(I),_(s(a).actionColOptions||{span:Y},F,!0),o("advanced-change")}function b(){e.isAdvanced=!e.isAdvanced}return{handleToggleAdvanced:b,fieldsIsAdvancedMap:p}}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,f)=>{q(y,f,o[t.trim()])}),y.filter(Boolean).length?y:void 0}}}function Yt(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 Ht({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(E=>E.field===u),w=A==null?void 0:A.defaultValueObj,O=Object.keys(w||{});O.length&&O.map(E=>{a[E]=w[E]}),a[u]=Kt(A,h,u)}),ue(()=>R()),e("reset",Fe(a)),i&&W())})}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 O=s(r).find(c=>c.field===w);let E=he(n,w);const fe=Reflect.has(n,w);E=Lt(O==null?void 0:O.component,E);const{componentProps:ne}=O||{};let x=ne;typeof ne=="function"&&(x=x({formModel:s(a),formActionType:J}));const X=Wt(w,n)||Yt(w,n);if(fe||X){const c=X||E;if(M(w))if(Array.isArray(c)){const B=[];for(const S of c)B.push(S?G(S):null);s(a)[w]=B}else s(a)[w]=c?x!=null&&x.valueFormat?c:G(c):null;else s(a)[w]=c;x!=null&&x.onChange&&(x==null||x.onChange(c)),A.push(w)}else u.forEach(c=>{try{const B=c.split(".").reduce((S,N)=>S[N],n);Pe(B)&&(s(a)[c]=s(B),A.push(c))}catch(B){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(E=>E.field):[n.field];if(u.find(E=>A.includes(E.field))){re("There are schemas that have already been added");return}const w=u.findIndex(E=>E.field===i),O=U(n)?[n]:n;!i||w===-1||g?g?u.unshift(...O):u.push(...O):w!==-1&&u.splice(w+1,0,...O),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(O=>{A.field===O.field&&(w=O)}),w!==void 0&&A.field===w.field){const O=De(A,w);u.push(O)}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 M(n){return s(r).some(i=>i.field===n&&i.component?je.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 j(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 W(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 j();e("submit",u)}catch(u){if((u==null?void 0:u.outOfDate)===!1&&(u!=null&&u.errorFields))return;throw new Error(u)}})}const J={getFieldsValue:T,setFieldsValue:I,resetFields:l,updateSchema:b,resetSchema:P,setProps:$,removeSchemaByField:V,appendSchemaByField:p,clearValidate:R,validateFields:k,validate:j,submit:W,scrollToField:L};return{handleSubmit:W,clearValidate:R,validate:j,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 qt(e)?r||"":(!r&&e&&zt(e)&&(r=[0,0]),!r&&e&&e.component==="ApiTree"&&(r=[]),r)}function zt(e){if(e.component==="Slider"&&e.componentProps&&"range"in e.componentProps)return!0}function qt(e){return(e==null?void 0:e.component)&&Ee.includes(e.component)}const Jt=Symbol();function Xt(e){return st(e,Jt)}function Zt(h){return v(this,arguments,function*({getSchema:e,getProps:o,formElRef:a,isInitedDefault:r}){Ge(()=>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},mn=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=We(),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=H(()=>C(C({},r),s(V))),F=H(()=>[P,{[`${P}--compact`]:s(b).compact}]),T=H(()=>{const{baseRowStyle:c={},rowProps:B}=s(b);return C({style:c},B)}),M=H(()=>C(C(C({},y),r),s(b))),k=H(()=>{var B;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&&je.includes(se)){const Ce={schema:S,tableAction:(B=r.tableAction)!=null?B:{},formModel:t,formActionType:{}},oe=ae?typeof ae=="function"?ae(Ce).valueFormat:ae.valueFormat:null;if(!Array.isArray(N))S.defaultValue=oe?G(N).format(oe):G(N);else{const ye=[];N.forEach(be=>{ye.push(oe?G(be).format(oe):G(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:j}=Gt({getProps:b,defaultValueRef:m,getSchema:k,formModel:t});Zt({getSchema:k,getProps:b,isInitedDefault:I,formElRef:p});const{handleSubmit:R,setFieldsValue:L,clearValidate:W,validate:J,validateFields:n,getFieldsValue:i,updateSchema:g,resetSchema:u,appendSchemaByField:A,removeSchemaByField:w,resetFields:O,scrollToField:E}=Ht({emit:h,getProps:b,formModel:t,getSchema:k,defaultValueRef:m,formElRef:p,schemaRef:_,handleFormValues:$});Xt({resetAction:O,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 B;(B=f==null?void 0:f.redoModalHeight)==null||B.call(f)}),!s(I)&&c!=null&&c.length&&(j(),I.value=!0)}),Z(()=>t,Oe(()=>{s(b).submitOnChange&&R()},300),{deep:!0});function fe(c){return v(this,null,function*(){V.value=De(s(V)||{},c)})}function ne(c,B,S){t[c]=B,h("field-value-change",c,B),S&&S.itemProps&&!S.itemProps.autoLink&&n([c]).catch(N=>{})}function x(c){const{autoSubmitOnEnter:B}=s(b);if(B&&c.key==="Enter"&&c.target&&c.target instanceof HTMLElement){const S=c.target;S&&S.tagName&&S.tagName.toUpperCase()=="INPUT"&&R()}}const X={getFieldsValue:i,setFieldsValue:L,resetFields:O,updateSchema:g,resetSchema:u,setProps:fe,removeSchemaByField:w,appendSchemaByField:A,clearValidate:W,validateFields:n,validate:J,submit:R,scrollToField:E};return H(()=>C(C({},b.value),l)),o(C({},X)),Ye(()=>{j(),h("register",X)}),(c,B)=>(de(),we(s(ft),Ie(M.value,{class:F.value,ref_key:"formElRef",ref:p,model:t,onKeypress:Ze(x,["enter"])}),{default:pe(()=>[He(s(lt),Ke(ze(T.value)),{default:pe(()=>[me(c.$slots,"formHeader"),(de(!0),qe(Je,null,Te(k.value,S=>(de(),we(et,{key:S.field,tableAction:c.tableAction,formActionType:X,schema:S,formProps:b.value,allDefaultValues:m.value,formModel:t,setFormModel:ne},Xe({_: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",Bt);d.set("Switch",yt);d.set("RadioButtonGroup",Ot);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",Et);d.set("IconPicker",jt);d.set("InputCountDown",Rt);d.set("Upload",_t);d.set("Divider",wt);d.set("CropperAvatar",Ct);d.set("BasicTitle",ot);function hn(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{mn as _,hn as u};
|