mirror of
https://github.com/silenty4ng/k5web
synced 2025-01-15 16:22:44 +00:00
25 lines
14 KiB
JavaScript
25 lines
14 KiB
JavaScript
import{i as Fe,_ as A,r as b,s as Ie,v as De}from"./form-model.968f8b89.js";import{d as qe,Z as We,$ as xe,a0 as He,b as ee,f as F,l as je,a1 as ve,a2 as Ue,U as Ee,i as ke,k as _e,m as Ke,a3 as Y,n as Me,a4 as Ge,a5 as Je,w as Pe}from"./index.375cf361.js";import{d as Ae,i as Xe,c as y,j as $,t as Ce,r as Re,o as Ze,b as ze,w as Ve,aI as C,p as ce,n as Qe}from"./arco.b087a425.js";import{u as Be,C as Ye,F as Ne,V as D,a as er}from"./index.3d2df98f.js";/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/var rr={for:{type:String,default:""},help:{type:[String,Function]},label:{type:[String,Function],default:""},labelAlign:{type:String,validator:function(e){return e?["left","right","top"].includes(e):!0}},labelWidth:{type:[String,Number]},name:{type:String,default:""},requiredMark:{type:Boolean,default:void 0},rules:{type:Array},showErrorMessage:{type:Boolean,default:void 0},status:{type:String,default:""},statusIcon:{type:[Boolean,Function],default:void 0},successBorder:Boolean,tips:{type:[String,Function]}};/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/function ar(v,e){return v.replace(/\${(.*?)}/g,function(f,c){return e[c.trim()]||""})}/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/function $e(v,e){var f=Object.keys(v);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(v);e&&(c=c.filter(function(E){return Object.getOwnPropertyDescriptor(v,E).enumerable})),f.push.apply(f,c)}return f}function Oe(v){for(var e=1;e<arguments.length;e++){var f=arguments[e]!=null?arguments[e]:{};e%2?$e(Object(f),!0).forEach(function(c){F(v,c,f[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(v,Object.getOwnPropertyDescriptors(f)):$e(Object(f)).forEach(function(c){Object.defineProperty(v,c,Object.getOwnPropertyDescriptor(f,c))})}return v}function Te(v,e){return e?"".concat(v,"__").concat(e).replace(/(\[|\]\.)/g,"_"):""}var tr=Ae({name:"TFormItem",props:Oe({},rr),setup:function(e,f){var c=f.slots,E=ke(),p=Be(),fe=qe("form"),re=fe.globalConfig,R=We({CheckCircleFilledIcon:xe,CloseCircleFilledIcon:Ye,ErrorCircleFilledIcon:He}),k=R.CheckCircleFilledIcon,I=R.CloseCircleFilledIcon,de=R.ErrorCircleFilledIcon,r=Xe(Ne,void 0),ae=ee(),te=ee("form-item"),me=y(function(){var t,l,a=(t=(l=e.requiredMark)!==null&&l!==void 0?l:r==null?void 0:r.requiredMark)!==null&&t!==void 0?t:re.value.requiredMark,d=K.value.filter(function(o){return o.required}).length>0;return a!=null?a:d}),ne=y(function(){return c.label||e.label}),ge=y(function(){return!!(r!=null&&r.colon&&ne.value)}),q=ee("form__label"),W=y(function(){return Fe(e.labelAlign)?r==null?void 0:r.labelAlign:e.labelAlign}),S=y(function(){return Fe(e.labelWidth)?r==null?void 0:r.labelWidth:e.labelWidth}),pe=y(function(){return[p.value.label,F(F(F(F(F({},"".concat(q.value,"--required"),me.value),"".concat(q.value,"--colon"),ge.value),"".concat(q.value,"--top"),ne.value&&(W.value==="top"||!S.value)),"".concat(q.value,"--left"),W.value==="left"&&S.value),"".concat(q.value,"--right"),W.value==="right"&&S.value)]}),ye=function(){if(Number(S.value)!==0){var l={};return S.value&&W.value!=="top"&&(je(S.value)?l={width:"".concat(S.value,"px")}:l={width:S.value}),C("div",{class:pe.value,style:l},[C("label",{for:e.for||null},[E("label")])])}},le=function(){var l=function(h){return C("span",{class:p.value.status},[C(h,null,null)])},a=j.value;if(L.value===D.SUCCESS)return l(k);if(a!=null&&a[0]){var d=a[0].type||"error",o={error:I,warning:de}[d]||k;return l(o)}return null},ue=function(){var l=e.statusIcon;if(l!==!1){var a=E("statusIcon",{defaultNode:le()});if(a)return C("span",{class:p.value.status},[a]);if(a!==!1&&(a=r==null?void 0:r.renderContent("statusIcon",{defaultNode:le(),params:e}),a))return a}},be=y(function(){if(!_.value)return"";if(L.value===D.SUCCESS)return e.successBorder?[p.value.success,p.value.successBorder].join(" "):p.value.success;if(!!j.value.length){var t=j.value[0].type||"error";return t==="error"?p.value.error:p.value.warning}}),H=y(function(){return[p.value.controls,be.value]}),ie=y(function(){var t={};return S.value&&W.value!=="top"&&(je(S.value)?t={marginLeft:"".concat(S.value,"px")}:t={marginLeft:S.value}),t}),j=$([]),U=$([]),L=$(D.TO_BE_VALIDATED),Z=$(!1),z=$(!1),B=function(){z.value=!1,j.value=[],U.value=[],L.value=D.TO_BE_VALIDATED},he=function(){var l=Object.prototype.toString.call(ve(r==null?void 0:r.data,e.name)),a;return l==="[object String]"&&(a=""),l==="[object Array]"&&(a=[]),l==="[object Object]"&&(a={}),a},Se=function(){var t=A(b.mark(function l(){var a,d=arguments;return b.wrap(function(O){for(;;)switch(O.prev=O.next){case 0:if(a=d.length>0&&d[0]!==void 0?d[0]:r==null?void 0:r.resetType,e.name){O.next=3;break}return O.abrupt("return");case 3:return a==="empty"?Ie(r==null?void 0:r.data,e.name,he()):a==="initial"&&Ie(r==null?void 0:r.data,e.name,w.value),O.next=6,Qe();case 6:Z.value?z.value=!0:B();case 7:case"end":return O.stop()}},l)}));return function(){return t.apply(this,arguments)}}(),se=y(function(){var t;return(t=r==null?void 0:r.errorMessage)!==null&&t!==void 0?t:re.value.errorMessage}),K=y(function(){var t;if((t=e.rules)!==null&&t!==void 0&&t.length)return e.rules;if(!e.name)return[];var l="".concat(e.name).lastIndexOf(".")||-1,a="".concat(e.name).slice(l+1);return ve(r==null?void 0:r.rules,e.name)||ve(r==null?void 0:r.rules,a)||[]}),g=function(){var t=A(b.mark(function l(a){var d,o;return b.wrap(function(h){for(;;)switch(h.prev=h.next){case 0:if(o={successList:[],errorList:[],rules:[],resultList:[],allowSetValue:!1},o.rules=a==="all"?K.value:K.value.filter(function(m){return(m.trigger||"change")===a}),!(K.value.length&&!((d=o.rules)!==null&&d!==void 0&&d.length))){h.next=4;break}return h.abrupt("return",o);case 4:return o.allowSetValue=!0,h.next=7,De(i.value,o.rules);case 7:return o.resultList=h.sent,o.errorList=o.resultList.filter(function(m){return m.result!==!0}).map(function(m){return Object.keys(m).forEach(function(J){if(!m.message&&se.value[J]){var oe=Ke(e.label)?e.label:e.name;m.message=ar(se.value[J],{name:oe,validate:m[J]})}}),m}),o.successList=o.resultList.filter(function(m){return m.result===!0&&m.message&&m.type==="success"}),h.abrupt("return",o);case 11:case"end":return h.stop()}},l)}));return function(a){return t.apply(this,arguments)}}(),n=function(){var t=A(b.mark(function l(a,d){var o,O,h,m,J,oe;return b.wrap(function(X){for(;;)switch(X.prev=X.next){case 0:return Z.value=!0,x.value=d,X.next=4,g(a);case 4:return o=X.sent,O=o.successList,h=o.errorList,m=o.rules,J=o.resultList,oe=o.allowSetValue,oe&&(U.value=O,j.value=h),m.length&&(L.value=h.length?D.FAIL:D.SUCCESS),z.value&&B(),Z.value=!1,X.abrupt("return",F({},e.name,h.length===0?!0:J));case 15:case"end":return X.stop()}},l)}));return function(a,d){return t.apply(this,arguments)}}(),u=function(){var t=A(b.mark(function l(a){var d,o,O;return b.wrap(function(m){for(;;)switch(m.prev=m.next){case 0:return m.next=2,g(a);case 2:return d=m.sent,o=d.errorList,O=d.resultList,m.abrupt("return",F({},e.name,o.length===0?!0:O));case 6:case"end":return m.stop()}},l)}));return function(a){return t.apply(this,arguments)}}(),s=function(l){!l&&!_e(l)||(l.length===0&&(j.value=[],L.value=D.SUCCESS),j.value=l.map(function(a){return Oe(Oe({},a),{},{result:!1})}),L.value=D.FAIL)},i=y(function(){return(r==null?void 0:r.data)&&ve(r==null?void 0:r.data,e.name)}),w=$(void 0),M=Ce(e),P=M.name,N=Re({name:P,resetHandler:B,resetField:Se,validate:n,validateOnly:u,setValidateMessage:s});Ze(function(){w.value=Ue(i.value),r==null||r.children.push(N)}),ze(function(){r&&(r.children=r==null?void 0:r.children.filter(function(t){return t!==N}))}),Ve(i,A(b.mark(function t(){return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,n("change");case 2:case"end":return a.stop()}},t)})),{deep:!0}),Ve(function(){return[e.name,JSON.stringify(e.rules)].join(",")},function(){n("change")});var x=$(void 0),_=y(function(){return Ee(x.value)?x.value:Ee(e.showErrorMessage)?e.showErrorMessage:r==null?void 0:r.showErrorMessage}),V=y(function(){return[p.value.formItem,Te(te.value,e.name),F(F({},p.value.formItemWithHelp,Q.value),p.value.formItemWithExtra,we.value)]}),Q=y(function(){var t=E("help");return t?C("div",{class:p.value.help},[t]):null}),we=y(function(){var t,l=function(o){return C("div",{class:p.value.extra,title:o},[o])},a=j.value;return _.value&&a!==null&&a!==void 0&&(t=a[0])!==null&&t!==void 0&&t.message?l(a[0].message):U.value.length?l(U.value[0].message):null}),T=y(function(){var t=E("tips");if(!t)return null;var l=["".concat(te.value,"-tips"),"".concat(ae.value,"-tips"),"".concat(ae.value,"-is-").concat(e.status||"default")];return C("div",{class:l},[t])}),G=function(){var t=A(b.mark(function l(){return b.wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return d.next=2,n("blur");case 2:case"end":return d.stop()}},l)}));return function(){return t.apply(this,arguments)}}();return ce(er,{handleBlur:G}),function(){return C("div",{class:V.value},[ye(),C("div",{class:H.value,style:ie.value},[C("div",{class:p.value.controlsContent},[E("default"),ue()]),Q.value,T.value,we.value])])}}});/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/var nr={colon:Boolean,data:{type:Object,default:function(){return{}}},disabled:{type:Boolean,default:void 0},errorMessage:{type:Object},formControlledComponents:{type:Array},labelAlign:{type:String,default:"right",validator:function(e){return e?["left","right","top"].includes(e):!0}},labelWidth:{type:[String,Number],default:"100px"},layout:{type:String,default:"vertical",validator:function(e){return e?["vertical","inline"].includes(e):!0}},preventSubmitDefault:{type:Boolean,default:!0},readonly:{type:Boolean,default:void 0},requiredMark:{type:Boolean,default:void 0},resetType:{type:String,default:"empty",validator:function(e){return e?["empty","initial"].includes(e):!0}},rules:{type:Object},scrollToFirstError:{type:String,validator:function(e){return e?["","smooth","auto"].includes(e):!0}},showErrorMessage:{type:Boolean,default:!0},statusIcon:{type:[Boolean,Function],default:void 0},submitWithWarningMessage:Boolean,onReset:Function,onSubmit:Function,onValidate:Function};/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/function Le(v,e){var f=Object.keys(v);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(v);e&&(c=c.filter(function(E){return Object.getOwnPropertyDescriptor(v,E).enumerable})),f.push.apply(f,c)}return f}function lr(v){for(var e=1;e<arguments.length;e++){var f=arguments[e]!=null?arguments[e]:{};e%2?Le(Object(f),!0).forEach(function(c){F(v,c,f[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(v,Object.getOwnPropertyDescriptors(f)):Le(Object(f)).forEach(function(c){Object.defineProperty(v,c,Object.getOwnPropertyDescriptor(f,c))})}return v}var ur=Ae({name:"TForm",props:lr({},nr),setup:function(e,f){var c=f.expose,E=ke(),p=Ce(e),fe=p.disabled,re=p.readonly;ce("formDisabled",{disabled:fe}),ce("formReadonly",{readonly:re});var R=$(null),k=$([]),I=Ce(e),de=I.showErrorMessage,r=I.labelWidth,ae=I.labelAlign,te=I.data,me=I.colon,ne=I.requiredMark,ge=I.rules,q=I.errorMessage,W=I.resetType;ce(Ne,Re({showErrorMessage:de,labelWidth:r,labelAlign:ae,data:te,colon:me,requiredMark:ne,rules:ge,errorMessage:q,resetType:W,children:k,renderContent:E}));var S=ee("form"),pe=Be(),ye=y(function(){return[pe.value.form,F({},"".concat(S.value,"-inline"),e.layout==="inline")]}),le=ee("form-item"),ue=function(n){if(Ee(n))return"";var u=Object.keys(n),s=Me(u,1),i=s[0];if(e.scrollToFirstError){var w=Te(le.value,i);be(w)}var M=n[i];return _e(M)?M.filter(function(P){return!P.result})[0].message:""},be=function(n){var u=R.value.getElementsByClassName(n),s=Me(u,1),i=s[0],w=e.scrollToFirstError;w&&i&&i.scrollIntoView({behavior:w})},H=function(n,u){return!u||!_e(u)?!0:u.indexOf("".concat(n))!==-1},ie=function(n){var u=n.reduce(function(s,i){return Object.assign(s||{},i)},{});return Object.keys(u).forEach(function(s){u[s]===!0&&delete u[s]}),Je(u)?!0:u},j=function(){var g=A(b.mark(function n(u){var s,i,w,M,P,N,x,_,V,Q;return b.wrap(function(T){for(;;)switch(T.prev=T.next){case 0:return i=u||{},w=i.fields,M=i.trigger,P=M===void 0?"all":M,N=i.showErrorMessage,x=k.value.filter(function(G){return Y(G.validate)&&H(String(G.name),w)}).map(function(G){return G.validate(P,N)}),T.next=4,Promise.all(x);case 4:return _=T.sent,V=ie(_),Q=ue(V),(s=e.onValidate)===null||s===void 0||s.call(e,{validateResult:V,firstError:Q}),T.abrupt("return",V);case 9:case"end":return T.stop()}},n)}));return function(u){return g.apply(this,arguments)}}(),U=function(){var g=A(b.mark(function n(u){var s,i,w,M,P,N;return b.wrap(function(_){for(;;)switch(_.prev=_.next){case 0:return s=u||{},i=s.fields,w=s.trigger,M=w===void 0?"all":w,P=k.value.filter(function(V){return Y(V.validateOnly)&&H(String(V.name),i)}).map(function(V){return V.validateOnly(M)}),_.next=4,Promise.all(P);case 4:return N=_.sent,_.abrupt("return",ie(N));case 6:case"end":return _.stop()}},n)}));return function(u){return g.apply(this,arguments)}}(),L=$(),Z=function(n){e.preventSubmitDefault&&n&&(n.preventDefault(),n.stopPropagation()),j(L.value).then(function(u){var s;(s=e.onSubmit)===null||s===void 0||s.call(e,{validateResult:u,firstError:ue(u),e:n})}),L.value=void 0},z=function(){var g=A(b.mark(function n(u){return b.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:L.value=u,Ge(R.value);case 2:case"end":return i.stop()}},n)}));return function(u){return g.apply(this,arguments)}}(),B=$(),he=function(n){var u;e.preventSubmitDefault&&n&&(n.preventDefault(),n.stopPropagation()),k.value.filter(function(s){var i;return Y(s.resetField)&&H(String(s.name),(i=B.value)===null||i===void 0?void 0:i.fields)}).forEach(function(s){var i;return s.resetField((i=B.value)===null||i===void 0?void 0:i.type)}),B.value=void 0,(u=e.onReset)===null||u===void 0||u.call(e,{e:n})},Se=function(n){B.value=n,R.value.reset()},se=function(n){k.value.forEach(function(u){Y(u.resetHandler)&&H(String(u.name),n)&&u.resetHandler()})},K=function(n){var u=Object.keys(n);if(!!u.length){var s=k.value.filter(function(i){return Y(i.setValidateMessage)&&u.includes("".concat(i.name))}).map(function(i){return i.setValidateMessage(n[i.name])});Promise.all(s)}};return c({validate:j,submit:z,reset:Se,clearValidate:se,setValidateMessage:K,validateOnly:U}),function(){return C("form",{ref:R,class:ye.value,onSubmit:function(n){return Z(n)},onReset:function(n){return he(n)}},[E("default")])}}});/**
|
|
* tdesign v1.9.9
|
|
* (c) 2024 tdesign
|
|
* @license MIT
|
|
*/var fr=Pe(ur),dr=Pe(tr);export{dr as F,fr as a};
|