You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
3.2 KiB
2 lines
3.2 KiB
var l=(F,b,c)=>new Promise((f,w)=>{var o=u=>{try{y(c.next(u))}catch(v){w(v)}},h=u=>{try{y(c.throw(u))}catch(v){w(v)}},y=u=>u.done?f(u.value):Promise.resolve(u.value).then(o,h);y((c=c.apply(F,b)).next())});import{u as s,aj as S,K as j,aY as x,ah as O,ak as D,aX as T,ao as V,a6 as K,b1 as C,b2 as G}from"./index-f4658ae7.js";import{handleInputNumberValue as H,dateItemType as J}from"./helper-2176e41a.js";function Z({emit:F,getProps:b,formModel:c,getSchema:f,defaultValueRef:w,formElRef:o,schemaRef:h,handleFormValues:y}){function u(){return l(this,null,function*(){const{resetFunc:e,submitOnReset:n}=s(b);e&&S(e)&&(yield e()),s(o)&&(Object.keys(c).forEach(t=>{c[t]=w.value[t]}),B(),F("reset",j(c)),n&&I())})}function v(e){return l(this,null,function*(){const n=s(f).map(t=>t.field).filter(Boolean),i=[];Object.keys(e).forEach(t=>{const a=s(f).find(p=>p.field===t);let r=e[t];const m=Reflect.has(e,t);if(r=H(a==null?void 0:a.component,r),m&&n.includes(t)){if(_(t))if(Array.isArray(r)){const p=[];for(const d of r)p.push(d?x(d):null);c[t]=p}else{const{componentProps:p}=a||{};let d=p;typeof p=="function"&&(d=d({formModel:c})),c[t]=r?d!=null&&d.valueFormat?r:x(r):null}else c[t]=r;i.push(t)}}),E(i).catch(t=>{})})}function L(e){return l(this,null,function*(){const n=O(s(f));if(!e)return;let i=D(e)?[e]:e;D(e)&&(i=[e]);for(const t of i)q(t,n);h.value=n})}function q(e,n){if(D(e)){const i=n.findIndex(t=>t.field===e);i!==-1&&(delete c[e],n.splice(i,1))}}function N(e,n,i=!1){return l(this,null,function*(){const t=O(s(f)),a=t.findIndex(r=>r.field===n);if(!n||a===-1||i){i?t.unshift(e):t.push(e),h.value=t;return}a!==-1&&t.splice(a+1,0,e),h.value=t})}function U(e){return l(this,null,function*(){let n=[];if(T(e)&&n.push(e),V(e)&&(n=[...e]),!n.every(t=>t.component==="Divider"||Reflect.has(t,"field")&&t.field)){K("All children of the form Schema array that need to be updated must contain the `field` field");return}h.value=n})}function X(e){return l(this,null,function*(){let n=[];if(T(e)&&n.push(e),V(e)&&(n=[...e]),!n.every(a=>a.component==="Divider"||Reflect.has(a,"field")&&a.field)){K("All children of the form Schema array that need to be updated must contain the `field` field");return}const t=[];n.forEach(a=>{s(f).forEach(r=>{if(r.field===a.field){const m=C(r,a);t.push(m)}else t.push(r)})}),h.value=G(t,"field")})}function Y(){return s(o)?y(j(s(c))):{}}function _(e){return s(f).some(n=>n.field===e?J.includes(n.component):!1)}function E(e){return l(this,null,function*(){var n;return(n=s(o))==null?void 0:n.validateFields(e)})}function A(e){return l(this,null,function*(){var n;return yield(n=s(o))==null?void 0:n.validate(e)})}function B(e){return l(this,null,function*(){var n;yield(n=s(o))==null?void 0:n.clearValidate(e)})}function z(e,n){return l(this,null,function*(){var i;yield(i=s(o))==null?void 0:i.scrollToField(e,n)})}function I(e){return l(this,null,function*(){e&&e.preventDefault();const{submitFunc:n}=s(b);if(n&&S(n)){yield n();return}if(s(o))try{const t=yield A(),a=y(t);F("submit",a)}catch(t){throw new Error(t)}})}return{handleSubmit:I,clearValidate:B,validate:A,validateFields:E,getFieldsValue:Y,updateSchema:X,resetSchema:U,appendSchemaByField:N,removeSchemaByFiled:L,resetFields:u,setFieldsValue:v,scrollToField:z}}export{Z as useFormEvents};
|