1 |
- import{A as k,aa as h,E as _,d as y,S as A,ab as N,Q as $,ah as p,a2 as w,j as c,aS as B,ap as I,W as L,ag as M,N as R}from"./index.394decd7.js";const[U,r,Y]=k("pull-refresh"),v=50,j=["pulling","loosing","success"],C={disabled:Boolean,modelValue:Boolean,headHeight:h(v),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:_,successDuration:h(500),animationDuration:h(300)};var F=y({name:U,props:C,emits:["refresh","update:modelValue"],setup(a,{emit:f,slots:o}){let u;const g=A(),D=N(g),e=$({status:"normal",distance:0,duration:0}),i=p(),x=()=>{if(a.headHeight!==v)return{height:`${a.headHeight}px`}},d=()=>e.status!=="loading"&&e.status!=="success"&&!a.disabled,H=t=>{const s=+(a.pullDistance||a.headHeight);return t>s&&(t<s*2?t=s+(t-s)/2:t=s*1.5+(t-s*2)/4),Math.round(t)},n=(t,s)=>{const l=+(a.pullDistance||a.headHeight);e.distance=t,s?e.status="loading":t===0?e.status="normal":t<l?e.status="pulling":e.status="loosing"},T=()=>{const{status:t}=e;return t==="normal"?"":a[`${t}Text`]||Y(t)},P=()=>{const{status:t,distance:s}=e;if(o[t])return o[t]({distance:s});const l=[];return j.includes(t)&&l.push(c("div",{class:r("text")},[T()])),t==="loading"&&l.push(c(B,{class:r("loading")},{default:T})),l},E=()=>{e.status="success",setTimeout(()=>{n(0)},+a.successDuration)},m=t=>{u=M(D.value)===0,u&&(e.duration=0,i.start(t))},V=t=>{d()&&m(t)},b=t=>{if(d()){u||m(t);const{deltaY:s}=i;i.move(t),u&&s.value>=0&&i.isVertical()&&(I(t),n(H(s.value)))}},S=()=>{u&&i.deltaY.value&&d()&&(e.duration=+a.animationDuration,e.status==="loosing"?(n(+a.headHeight,!0),f("update:modelValue",!0),L(()=>f("refresh"))):n(0))};return w(()=>a.modelValue,t=>{e.duration=+a.animationDuration,t?n(+a.headHeight,!0):o.success||a.successText?E():n(0,!1)}),()=>{var t;const s={transitionDuration:`${e.duration}ms`,transform:e.distance?`translate3d(0,${e.distance}px, 0)`:""};return c("div",{ref:g,class:r()},[c("div",{class:r("track"),style:s,onTouchstart:V,onTouchmove:b,onTouchend:S,onTouchcancel:S},[c("div",{class:r("head"),style:x()},[P()]),(t=o.default)==null?void 0:t.call(o)])])}}});const Q=R(F);export{Q as P};
|