1 |
- import{c as w,b as g,n as A,d as _,r as x,by as F,x as D,u as L,w as m,_ as M,a as o,L as N,z as $,bE as q,p as B,k as U,F as W,A as I}from"./index-869d77fb.js";const[Y,f,z]=w("pull-refresh"),V=50,C=["pulling","loosing","success"],G={disabled:Boolean,modelValue:Boolean,headHeight:g(V),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:A,successDuration:g(500),animationDuration:g(300)};var X=_({name:Y,props:G,emits:["change","refresh","update:modelValue"],setup(a,{emit:i,slots:n}){let l;const u=x(),T=x(),H=F(u),t=D({status:"normal",distance:0,duration:0}),r=L(),k=()=>{if(a.headHeight!==V)return{height:`${a.headHeight}px`}},h=()=>t.status!=="loading"&&t.status!=="success"&&!a.disabled,y=e=>{const s=+(a.pullDistance||a.headHeight);return e>s&&(e<s*2?e=s+(e-s)/2:e=s*1.5+(e-s*2)/4),Math.round(e)},c=(e,s)=>{const d=+(a.pullDistance||a.headHeight);t.distance=e,s?t.status="loading":e===0?t.status="normal":e<d?t.status="pulling":t.status="loosing",i("change",{status:t.status,distance:e})},S=()=>{const{status:e}=t;return e==="normal"?"":a[`${e}Text`]||z(e)},P=()=>{const{status:e,distance:s}=t;if(n[e])return n[e]({distance:s});const d=[];return C.includes(e)&&d.push(o("div",{class:f("text")},[S()])),e==="loading"&&d.push(o(N,{class:f("loading")},{default:S})),d},R=()=>{t.status="success",setTimeout(()=>{c(0)},+a.successDuration)},p=e=>{l=q(H.value)===0,l&&(t.duration=0,r.start(e))},b=e=>{h()&&p(e)},E=e=>{if(h()){l||p(e);const{deltaY:s}=r;r.move(e),l&&s.value>=0&&r.isVertical()&&(B(e),c(y(s.value)))}},v=()=>{l&&r.deltaY.value&&h()&&(t.duration=+a.animationDuration,t.status==="loosing"?(c(+a.headHeight,!0),i("update:modelValue",!0),$(()=>i("refresh"))):c(0))};return m(()=>a.modelValue,e=>{t.duration=+a.animationDuration,e?c(+a.headHeight,!0):n.success||a.successText?R():c(0,!1)}),M("touchmove",E,{target:T}),()=>{var e;const s={transitionDuration:`${t.duration}ms`,transform:t.distance?`translate3d(0,${t.distance}px, 0)`:""};return o("div",{ref:u,class:f()},[o("div",{ref:T,class:f("track"),style:s,onTouchstartPassive:b,onTouchend:v,onTouchcancel:v},[o("div",{class:f("head"),style:k()},[P()]),(e=n.default)==null?void 0:e.call(n)])])}}});const j=U(X),J="_animateWrap_1kuq9_1",K="_loading_1kuq9_5",O="_pullRefresh_1kuq9_13",Q={animateWrap:J,loading:K,pullRefresh:O};const ee=_({name:"m-full-refresh",props:{title:String,modelValue:{type:Boolean,default:!1}},emits:["refresh","update:modelValue"],setup(a,{emit:i,slots:n}){const l=D({fullState:!1});return m(()=>a.modelValue,u=>{l.fullState=u}),m(()=>l.fullState,u=>{i("update:modelValue",u)}),()=>o(j,{modelValue:l.fullState,"onUpdate:modelValue":u=>l.fullState=u,onRefresh:()=>i("refresh"),loadingText:" ",class:Q.pullRefresh},{default:()=>o(W,null,[I(" "),n.default&&n.default()])})}});export{ee as M};
|