2 lines
2.7 KiB
JavaScript
2 lines
2.7 KiB
JavaScript
var m=(t,e,n)=>new Promise((s,u)=>{var l=a=>{try{r(n.next(a))}catch(c){u(c)}},o=a=>{try{r(n.throw(a))}catch(c){u(c)}},r=a=>a.done?s(a.value):Promise.resolve(a.value).then(l,o);r((n=n.apply(t,e)).next())});import{s as I,aw as h,ac as C,f as S,ao as z,ak as F,aj as k,k as d,ax as A,r as f,ay as T,a as g,B as N,c as j,J as y,az as D,aA as p,o as w,j as _,x as v,y as E,t as O,aB as $,b as P,aC as R,aD as L,aE as V,aF as q,aG as x,p as G,L as B}from"./index.d70f4f63.js";function J(t,e="value",n="change",s){const u=A(),l=u==null?void 0:u.emit,o=I({value:t[e]}),r=h(o),a=i=>{o.value=i};return C(()=>{o.value=t[e]}),[S({get(){return o.value},set(i){z(i,r.value)||(o.value=i,F(()=>{l==null||l(n,i,...k(d(s))||[])}))}}),a,r]}function U(t){const e=f(t),n=f(!1);let s;function u(){s&&window.clearInterval(s)}function l(){n.value=!1,u(),s=null}function o(){d(n)||!!s||(n.value=!0,s=setInterval(()=>{d(e)===1?(l(),e.value=t):e.value-=1},1e3))}function r(){e.value=t,l()}function a(){r(),o()}return T(()=>{r()}),{start:o,reset:r,restart:a,clear:u,stop:l,currentCount:e,isStart:n}}const H={value:{type:[Object,Number,String,Array]},count:{type:Number,default:60},beforeStartFunc:{type:Function,default:null}},K=g({name:"CountButton",components:{Button:N},props:H,setup(t){const e=f(!1),{currentCount:n,isStart:s,start:u,reset:l}=U(t.count),{t:o}=j(),r=S(()=>d(s)?o("component.countdown.sendText",[d(n)]):o("component.countdown.normalText"));C(()=>{t.value===void 0&&l()});function a(){return m(this,null,function*(){const{beforeStartFunc:c}=t;if(c&&D(c)){e.value=!0;try{(yield c())&&u()}finally{e.value=!1}}else u()})}return{handleStart:a,currentCount:n,loading:e,getButtonText:r,isStart:s}}});function M(t,e,n,s,u,l){const o=p("Button");return w(),_(o,$(t.$attrs,{disabled:t.isStart,onClick:t.handleStart,loading:t.loading}),{default:v(()=>[E(O(t.getButtonText),1)]),_:1},16,["disabled","onClick","loading"])}var b=y(K,[["render",M]]);const Q={value:{type:String},size:{type:String,validator:t=>["default","large","small"].includes(t)},count:{type:Number,default:60},sendCodeApi:{type:Function,default:null}},W=g({name:"CountDownInput",components:{CountButton:b},inheritAttrs:!1,props:Q,setup(t){const{prefixCls:e}=P("countdown-input"),[n]=J(t);return{prefixCls:e,state:n}}});function X(t,e,n,s,u,l){const o=p("CountButton"),r=p("a-input");return w(),_(r,$(t.$attrs,{class:t.prefixCls,size:t.size,value:t.state}),R({addonAfter:v(()=>[G(o,{size:t.size,count:t.count,value:t.state,beforeStartFunc:t.sendCodeApi},null,8,["size","count","value","beforeStartFunc"])]),_:2},[L(Object.keys(t.$slots).filter(a=>a!=="addonAfter"),a=>({name:a,fn:v(c=>[V(t.$slots,a,q(x(c||{})))])}))]),1040,["class","size","value"])}var Y=y(W,[["render",X]]);const et=B(Y);B(b);export{et as C,J as u};
|