| 1 |
- import{c as V,r as be,e as B,y as Q,n as A,z as G,A as z,a as le,C as ce,v as ye,m as K,t as N,f as xe,u as we,D as $e,E as F,p as ae,w as j,F as De,G as re,H as Ee,J as Be,K as Ve,L as He,d as ue,g as Oe,I as Ce}from"./index-c2909177.js";import{u as X}from"./axios-12198959.js";import{L as Re}from"./index-29e84163.js";import{u as Ne}from"./index-8665d1db.js";import{d as _,r as I,a as P,D as _e,c as m,y as U,z as de,m as ie,l as Ye,T as Ae,w as Fe,v as ze}from"./index-e4df6086.js";import{H as W,d as Le,e as Ke}from"./use-route-01d6b0b1.js";import{C as Ue}from"./index-b2f82041.js";import{P as We}from"./function-call-c516a4d7.js";import{u as je}from"./index-017156a0.js";import{u as Ge}from"./use-placeholder-0e4fa972.js";const[Ze,$,me]=V("picker"),ke=e=>e.find(n=>!n.disabled)||e[0];function qe(e,n){const t=e[0];if(t){if(Array.isArray(t))return"multiple";if(n.children in t)return"cascade"}return"default"}function J(e,n){n=Q(n,0,e.length);for(let t=n;t<e.length;t++)if(!e[t].disabled)return t;for(let t=n-1;t>=0;t--)if(!e[t].disabled)return t;return 0}const fe=(e,n,t)=>n!==void 0&&!!e.find(c=>c[t.value]===n);function oe(e,n,t){const c=e.findIndex(r=>r[t.value]===n),l=J(e,c);return e[l]}function Je(e,n,t){const c=[];let l={[n.children]:e},r=0;for(;l&&l[n.children];){const u=l[n.children],h=t.value[r];if(l=be(h)?oe(u,h,n):void 0,!l&&u.length){const f=ke(u)[n.value];l=oe(u,f,n)}r++,c.push(u)}return c}function Qe(e){const{transform:n}=window.getComputedStyle(e),t=n.slice(7,n.length-1).split(", ")[5];return Number(t)}function Xe(e){return B({text:"text",value:"value",children:"children"},e)}const ve=200,he=300,et=15,[Te,te]=V("picker-column"),pe=Symbol(Te);var tt=_({name:Te,props:{value:A,fields:G(Object),options:z(),readonly:Boolean,allowHtml:Boolean,optionHeight:G(Number),swipeDuration:G(A),visibleOptionNum:G(A)},emits:["change","clickOption","scrollInto"],setup(e,{emit:n,slots:t}){let c,l,r,u,h;const f=I(),w=I(),v=I(0),y=I(0),C=Ne(),k=()=>e.options.length,p=()=>e.optionHeight*(+e.visibleOptionNum-1)/2,T=g=>{let o=J(e.options,g);const s=-o*e.optionHeight,d=()=>{o>k()-1&&(o=J(e.options,g));const E=e.options[o][e.fields.value];E!==e.value&&n("change",E)};c&&s!==v.value?h=d:d(),v.value=s},D=()=>e.readonly||!e.options.length,a=g=>{c||D()||(h=null,y.value=ve,T(g),n("clickOption",e.options[g]))},i=g=>Q(Math.round(-g/e.optionHeight),0,k()-1),b=P(()=>i(v.value)),O=(g,o)=>{const s=Math.abs(g/o);g=v.value+s/.003*(g<0?-1:1);const d=i(g);y.value=+e.swipeDuration,T(d)},x=()=>{c=!1,y.value=0,h&&(h(),h=null)},H=g=>{if(!D()){if(C.start(g),c){const o=Qe(w.value);v.value=Math.min(0,o-p())}y.value=0,l=v.value,r=Date.now(),u=l,h=null}},R=g=>{if(D())return;C.move(g),C.isVertical()&&(c=!0,ye(g,!0));const o=Q(l+C.deltaY.value,-(k()*e.optionHeight),e.optionHeight),s=i(o);s!==b.value&&n("scrollInto",e.options[s]),v.value=o;const d=Date.now();d-r>he&&(r=d,u=o)},M=()=>{if(D())return;const g=v.value-u,o=Date.now()-r;if(o<he&&Math.abs(g)>et){O(g,o);return}const d=i(v.value);y.value=ve,T(d),setTimeout(()=>{c=!1},0)},Y=()=>{const g={height:`${e.optionHeight}px`};return e.options.map((o,s)=>{const d=o[e.fields.text],{disabled:E}=o,L=o[e.fields.value],Me={role:"button",style:g,tabindex:E?-1:0,class:[te("item",{disabled:E,selected:L===e.value}),o.className],onClick:()=>a(s)},Se={class:"van-ellipsis",[e.allowHtml?"innerHTML":"textContent"]:d};return m("li",Me,[t.option?t.option(o,s):m("div",Se,null)])})};return le(pe),X({stopMomentum:x}),_e(()=>{const g=c?Math.floor(-v.value/e.optionHeight):e.options.findIndex(d=>d[e.fields.value]===e.value),o=J(e.options,g),s=-o*e.optionHeight;c&&o<g&&x(),v.value=s}),ce("touchmove",R,{target:f}),()=>m("div",{ref:f,class:te(),onTouchstartPassive:H,onTouchend:M,onTouchcancel:M},[m("ul",{ref:w,style:{transform:`translate3d(0, ${v.value+p()}px, 0)`,transitionDuration:`${y.value}ms`,transitionProperty:y.value?"all":"none"},class:te("wrapper"),onTransitionend:x},[Y()])])}});const[nt]=V("picker-toolbar"),ee={title:String,cancelButtonText:String,confirmButtonText:String},at=["cancel","confirm","title","toolbar"],ot=Object.keys(ee);var lt=_({name:nt,props:ee,emits:["confirm","cancel"],setup(e,{emit:n,slots:t}){const c=()=>{if(t.title)return t.title();if(e.title)return m("div",{class:[$("title"),"van-ellipsis"]},[e.title])},l=()=>n("cancel"),r=()=>n("confirm"),u=()=>{const f=e.cancelButtonText||me("cancel");return m("button",{type:"button",class:[$("cancel"),W],onClick:l},[t.cancel?t.cancel():f])},h=()=>{const f=e.confirmButtonText||me("confirm");return m("button",{type:"button",class:[$("confirm"),W],onClick:r},[t.confirm?t.confirm():f])};return()=>m("div",{class:$("toolbar")},[t.toolbar?t.toolbar():[u(),c(),h()]])}});const[ct,Nt]=V("picker-group"),it=Symbol(ct);B({tabs:z(),activeTab:K(0),nextStepText:String},ee);const se=B({loading:Boolean,readonly:Boolean,allowHtml:Boolean,optionHeight:K(44),showToolbar:N,swipeDuration:K(1e3),visibleOptionNum:K(6)},ee),st=B({},se,{columns:z(),modelValue:z(),toolbarPosition:xe("top"),columnsFieldNames:Object});var rt=_({name:Ze,props:st,emits:["confirm","cancel","change","scrollInto","clickOption","update:modelValue"],setup(e,{emit:n,slots:t}){const c=I(),l=I(e.modelValue.slice(0)),{parent:r}=le(it),{children:u,linkChildren:h}=we(pe);h();const f=P(()=>Xe(e.columnsFieldNames)),w=P(()=>$e(e.optionHeight)),v=P(()=>qe(e.columns,f.value)),y=P(()=>{const{columns:o}=e;switch(v.value){case"multiple":return o;case"cascade":return Je(o,f.value,l);default:return[o]}}),C=P(()=>y.value.some(o=>o.length)),k=P(()=>y.value.map((o,s)=>oe(o,l.value[s],f.value))),p=P(()=>y.value.map((o,s)=>o.findIndex(d=>d[f.value.value]===l.value[s]))),T=(o,s)=>{if(l.value[o]!==s){const d=l.value.slice(0);d[o]=s,l.value=d}},D=()=>({selectedValues:l.value.slice(0),selectedOptions:k.value,selectedIndexes:p.value}),a=(o,s)=>{T(s,o),v.value==="cascade"&&l.value.forEach((d,E)=>{const L=y.value[E];fe(L,d,f.value)||T(E,L.length?L[0][f.value.value]:void 0)}),de(()=>{n("change",B({columnIndex:s},D()))})},i=(o,s)=>{const d={columnIndex:s,currentOption:o};n("clickOption",B(D(),d)),n("scrollInto",d)},b=()=>{u.forEach(s=>s.stopMomentum());const o=D();return de(()=>{n("confirm",o)}),o},O=()=>n("cancel",D()),x=()=>y.value.map((o,s)=>m(tt,{value:l.value[s],fields:f.value,options:o,readonly:e.readonly,allowHtml:e.allowHtml,optionHeight:w.value,swipeDuration:e.swipeDuration,visibleOptionNum:e.visibleOptionNum,onChange:d=>a(d,s),onClickOption:d=>i(d,s),onScrollInto:d=>{n("scrollInto",{currentOption:d,columnIndex:s})}},{option:t.option})),H=o=>{if(C.value){const s={height:`${w.value}px`},d={backgroundSize:`100% ${(o-w.value)/2}px`};return[m("div",{class:$("mask"),style:d},null),m("div",{class:[Le,$("frame")],style:s},null)]}},R=()=>{const o=w.value*+e.visibleOptionNum,s={height:`${o}px`};return m("div",{ref:c,class:$("columns"),style:s},[x(),H(o)])},M=()=>{if(e.showToolbar&&!r)return m(lt,ie(ae(e,ot),{onConfirm:b,onCancel:O}),ae(t,at))};U(y,o=>{o.forEach((s,d)=>{s.length&&!fe(s,l.value[d],f.value)&&T(d,ke(s)[f.value.value])})},{immediate:!0});let Y;return U(()=>e.modelValue,o=>{!F(o,l.value)&&!F(o,Y)&&(l.value=o.slice(0),Y=o.slice(0))},{deep:!0}),U(l,o=>{F(o,e.modelValue)||(Y=o.slice(0),n("update:modelValue",Y))},{immediate:!0}),ce("touchmove",ye,{target:c}),X({confirm:b,getSelectedOptions:()=>k.value}),()=>{var o,s;return m("div",{class:$()},[e.toolbarPosition==="top"?M():null,e.loading?m(Re,{class:$("loading")},null):null,(o=t["columns-top"])==null?void 0:o.call(t),R(),(s=t["columns-bottom"])==null?void 0:s.call(t),e.toolbarPosition==="bottom"?M():null])}}});const ut=j(rt),dt=B({},se,{modelValue:z(),filter:Function,formatter:{type:Function,default:(e,n)=>n}}),mt=Object.keys(se);function ft(e,n){if(e<0)return[];const t=Array(e);let c=-1;for(;++c<e;)t[c]=n(c);return t}const vt=(e,n)=>32-new Date(e,n-1,32).getDate(),ne=(e,n,t,c,l,r)=>{const u=ft(n-e+1,h=>{const f=De(e+h);return c(t,{text:f,value:f})});return l?l(t,u,r):u},ht=(e,n)=>e.map((t,c)=>{const l=n[c];if(l.length){const r=+l[0].value,u=+l[l.length-1].value;return De(Q(+t,r,u))}return t}),ge=new Date().getFullYear(),[gt]=V("date-picker"),bt=B({},dt,{columnsType:{type:Array,default:()=>["year","month","day"]},minDate:{type:Date,default:()=>new Date(ge-10,0,1),validator:re},maxDate:{type:Date,default:()=>new Date(ge+10,11,31),validator:re}});var yt=_({name:gt,props:bt,emits:["confirm","cancel","change","update:modelValue"],setup(e,{emit:n,slots:t}){const c=I(e.modelValue),l=I(!1),r=()=>{const a=e.minDate.getFullYear(),i=e.maxDate.getFullYear();return ne(a,i,"year",e.formatter,e.filter)},u=a=>a===e.minDate.getFullYear(),h=a=>a===e.maxDate.getFullYear(),f=a=>a===e.minDate.getMonth()+1,w=a=>a===e.maxDate.getMonth()+1,v=a=>{const{minDate:i,columnsType:b}=e,O=b.indexOf(a),x=l.value?e.modelValue[O]:c.value[O];if(x)return+x;switch(a){case"year":return i.getFullYear();case"month":return i.getMonth()+1;case"day":return i.getDate()}},y=()=>{const a=v("year"),i=u(a)?e.minDate.getMonth()+1:1,b=h(a)?e.maxDate.getMonth()+1:12;return ne(i,b,"month",e.formatter,e.filter)},C=()=>{const a=v("year"),i=v("month"),b=u(a)&&f(i)?e.minDate.getDate():1,O=h(a)&&w(i)?e.maxDate.getDate():vt(a,i);return ne(b,O,"day",e.formatter,e.filter)},k=P(()=>e.columnsType.map(a=>{switch(a){case"year":return r();case"month":return y();case"day":return C();default:return[]}}));U(c,a=>{F(a,e.modelValue)||n("update:modelValue",a)}),U(()=>e.modelValue,(a,i)=>{l.value=F(i,c.value),a=ht(a,k.value),F(a,c.value)||(c.value=a),l.value=!1},{immediate:!0});const p=(...a)=>n("change",...a),T=(...a)=>n("cancel",...a),D=(...a)=>n("confirm",...a);return()=>m(ut,ie({modelValue:c.value,"onUpdate:modelValue":a=>c.value=a,columns:k.value,onChange:p,onCancel:T,onConfirm:D},ae(e,mt)),t)}});const _t=j(yt),[Pe,Z]=V("dropdown-menu"),xt={overlay:N,zIndex:A,duration:K(.2),direction:xe("down"),activeColor:String,closeOnClickOutside:N,closeOnClickOverlay:N,swipeThreshold:A},Ie=Symbol(Pe);var wt=_({name:Pe,props:xt,setup(e,{slots:n}){const t=je(),c=I(),l=I(),r=I(0),{children:u,linkChildren:h}=we(Ie),f=Ee(c),w=P(()=>u.some(i=>i.state.showWrapper)),v=P(()=>e.swipeThreshold&&u.length>+e.swipeThreshold),y=P(()=>{if(w.value&&be(e.zIndex))return{zIndex:+e.zIndex+1}}),C=()=>{u.forEach(i=>{i.toggle(!1)})},k=()=>{e.closeOnClickOutside&&C()},p=()=>{if(l.value){const i=Ve(l);e.direction==="down"?r.value=i.bottom:r.value=He.value-i.top}},T=()=>{w.value&&p()},D=i=>{u.forEach((b,O)=>{O===i?b.toggle():b.state.showPopup&&b.toggle(!1,{immediate:!0})})},a=(i,b)=>{const{showPopup:O}=i.state,{disabled:x,titleClass:H}=i;return m("div",{id:`${t}-${b}`,role:"button",tabindex:x?void 0:0,class:[Z("item",{disabled:x,grow:v.value}),{[W]:!x}],onClick:()=>{x||D(b)}},[m("span",{class:[Z("title",{down:O===(e.direction==="down"),active:O}),H],style:{color:O?e.activeColor:""}},[m("div",{class:"van-ellipsis"},[i.renderTitle()])])])};return X({close:C}),h({id:t,props:e,offset:r,updateOffset:p}),Be(c,k),ce("scroll",T,{target:f,passive:!0}),()=>{var i;return m("div",{ref:c,class:Z()},[m("div",{ref:l,style:y.value,class:Z("bar",{opened:w.value,scrollable:v.value})},[u.map(a)]),(i=n.default)==null?void 0:i.call(n)])}}});const[Dt,q]=V("dropdown-item"),Ot={title:String,options:z(),disabled:Boolean,teleport:[String,Object],lazyRender:N,modelValue:ue,titleClass:ue};var Ct=_({name:Dt,inheritAttrs:!1,props:Ot,emits:["open","opened","close","closed","change","update:modelValue"],setup(e,{emit:n,slots:t,attrs:c}){const l=Ye({showPopup:!1,transition:!0,showWrapper:!1}),{parent:r,index:u}=le(Ie);if(!r)return;const h=a=>()=>n(a),f=h("open"),w=h("close"),v=h("opened"),y=()=>{l.showWrapper=!1,n("closed")},C=a=>{e.teleport&&a.stopPropagation()},k=(a=!l.showPopup,i={})=>{a!==l.showPopup&&(l.showPopup=a,l.transition=!i.immediate,a&&(r.updateOffset(),l.showWrapper=!0))},p=()=>{if(t.title)return t.title();if(e.title)return e.title;const a=e.options.find(i=>i.value===e.modelValue);return a?a.text:""},T=a=>{const{activeColor:i}=r.props,b=a.value===e.modelValue,O=()=>{l.showPopup=!1,a.value!==e.modelValue&&(n("update:modelValue",a.value),n("change",a.value))},x=()=>{if(b)return m(Ce,{class:q("icon"),color:i,name:"success"},null)};return m(Ue,{role:"menuitem",key:String(a.value),icon:a.icon,title:a.text,class:q("option",{active:b}),style:{color:b?i:""},tabindex:b?0:-1,clickable:!0,onClick:O},{value:x})},D=()=>{const{offset:a}=r,{zIndex:i,overlay:b,duration:O,direction:x,closeOnClickOverlay:H}=r.props,R=Oe(i);return x==="down"?R.top=`${a.value}px`:R.bottom=`${a.value}px`,Fe(m("div",ie({style:R,class:q([x]),onClick:C},c),[m(We,{show:l.showPopup,"onUpdate:show":M=>l.showPopup=M,role:"menu",class:q("content"),overlay:b,position:x==="down"?"top":"bottom",duration:l.transition?O:0,lazyRender:e.lazyRender,overlayStyle:{position:"absolute"},"aria-labelledby":`${r.id}-${u.value}`,closeOnClickOverlay:H,onOpen:f,onClose:w,onOpened:v,onClosed:y},{default:()=>{var M;return[e.options.map(T),(M=t.default)==null?void 0:M.call(t)]}})]),[[ze,l.showWrapper]])};return X({state:l,toggle:k,renderTitle:p}),()=>e.teleport?m(Ae,{to:e.teleport},{default:()=>[D()]}):D()}});const Yt=j(Ct),At=j(wt),[kt,S]=V("nav-bar"),Tt={title:String,fixed:Boolean,zIndex:A,border:N,leftText:String,rightText:String,leftDisabled:Boolean,rightDisabled:Boolean,leftArrow:Boolean,placeholder:Boolean,safeAreaInsetTop:Boolean,clickable:N};var pt=_({name:kt,props:Tt,emits:["clickLeft","clickRight"],setup(e,{emit:n,slots:t}){const c=I(),l=Ge(c,S),r=v=>{e.leftDisabled||n("clickLeft",v)},u=v=>{e.rightDisabled||n("clickRight",v)},h=()=>t.left?t.left():[e.leftArrow&&m(Ce,{class:S("arrow"),name:"arrow-left"},null),e.leftText&&m("span",{class:S("text")},[e.leftText])],f=()=>t.right?t.right():m("span",{class:S("text")},[e.rightText]),w=()=>{const{title:v,fixed:y,border:C,zIndex:k}=e,p=Oe(k),T=e.leftArrow||e.leftText||t.left,D=e.rightText||t.right;return m("div",{ref:c,style:p,class:[S({fixed:y}),{[Ke]:C,"van-safe-area-top":e.safeAreaInsetTop}]},[m("div",{class:S("content")},[T&&m("div",{class:[S("left",{disabled:e.leftDisabled}),e.clickable&&!e.leftDisabled?W:""],onClick:r},[h()]),m("div",{class:[S("title"),"van-ellipsis"]},[t.title?t.title():v]),D&&m("div",{class:[S("right",{disabled:e.rightDisabled}),e.clickable&&!e.rightDisabled?W:""],onClick:u},[f()])])])};return()=>e.fixed&&e.placeholder?l(w):w()}});const Ft=j(pt);const zt=function(e){const n=new Date;let t=n.getFullYear(),c=n.getMonth(),l=n.getDate(),r=0,u=0,h=Math.trunc(e/12),f=e%12;return f<c?(r=t-h,u=c-f):(r=t-h-1,u=c+12-f),new Date(r,u,l)};export{_t as D,Ft as N,At as a,Yt as b,zt as g};
|