k5web/assets/index.b441bfa0.js
2024-07-10 20:44:50 +08:00

26 lines
14 KiB
JavaScript

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