index.626c48f9.js 3.0 KB

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