util-f84da12a.js 7.6 KB

1
  1. import{p as U,P as ne}from"./index-18bc03a8.js";import{e as Z,o as q,q as G,s as oe,c as R,v as W,x as z,y as le,w as $,t as M,n as _,m as re,z as se,u as ce,A as ie,k as ue,C as de,D as fe,E as J,F as me,H as L,a as he,G as K,g as Q,J as ve,I as X,K as ge}from"./index-e9453d64.js";import{u as N}from"./use-scope-id-7611483c.js";import{d as A,r as C,a as B,w as H,c as u,m as ee,n as ye,T as De,h as we,v as xe}from"./index-ddf66cb5.js";import{C as be}from"./index-e270b3af.js";import{P as ke}from"./index-c1d3cef3.js";import{u as Ce}from"./index-a7cc295e.js";import{u as Pe}from"./use-placeholder-1196d982.js";const pe=Z({},U,{modelValue:q(),filter:Function,formatter:{type:Function,default:(e,l)=>l}}),Oe=Object.keys(U);function Te(e,l){if(e<0)return[];const o=Array(e);let r=-1;for(;++r<e;)o[r]=l(r);return o}const Me=(e,l)=>32-new Date(e,l-1,32).getDate(),F=(e,l,o,r,n,i)=>{const s=Te(l-e+1,m=>{const d=G(e+m);return r(o,{text:d,value:d})});return n?n(o,s,i):s},Ie=(e,l)=>e.map((o,r)=>{const n=l[r];if(n.length){const i=+n[0].value,s=+n[n.length-1].value;return G(oe(+o,i,s))}return o}),j=new Date().getFullYear(),[Se]=R("date-picker"),Ve=Z({},pe,{columnsType:{type:Array,default:()=>["year","month","day"]},minDate:{type:Date,default:()=>new Date(j-10,0,1),validator:W},maxDate:{type:Date,default:()=>new Date(j+10,11,31),validator:W}});var Be=A({name:Se,props:Ve,emits:["confirm","cancel","change","update:modelValue"],setup(e,{emit:l,slots:o}){const r=C(e.modelValue),n=C(!1),i=C(),s=()=>{const t=e.minDate.getFullYear(),c=e.maxDate.getFullYear();return F(t,c,"year",e.formatter,e.filter)},m=t=>t===e.minDate.getFullYear(),d=t=>t===e.maxDate.getFullYear(),g=t=>t===e.minDate.getMonth()+1,h=t=>t===e.maxDate.getMonth()+1,D=t=>{const{minDate:c,columnsType:v}=e,y=v.indexOf(t),I=n.value?e.modelValue[y]:r.value[y];if(I)return+I;switch(t){case"year":return c.getFullYear();case"month":return c.getMonth()+1;case"day":return c.getDate()}},x=()=>{const t=D("year"),c=m(t)?e.minDate.getMonth()+1:1,v=d(t)?e.maxDate.getMonth()+1:12;return F(c,v,"month",e.formatter,e.filter)},P=()=>{const t=D("year"),c=D("month"),v=m(t)&&g(c)?e.minDate.getDate():1,y=d(t)&&h(c)?e.maxDate.getDate():Me(t,c);return F(v,y,"day",e.formatter,e.filter)},b=()=>{var t;return(t=i.value)==null?void 0:t.confirm()},p=()=>r.value,k=B(()=>e.columnsType.map(t=>{switch(t){case"year":return s();case"month":return x();case"day":return P();default:return[]}}));H(r,t=>{z(t,e.modelValue)||l("update:modelValue",t)}),H(()=>e.modelValue,(t,c)=>{n.value=z(c,r.value),t=Ie(t,k.value),z(t,r.value)||(r.value=t),n.value=!1},{immediate:!0});const T=(...t)=>l("change",...t),a=(...t)=>l("cancel",...t),f=(...t)=>l("confirm",...t);return N({confirm:b,getSelectedDate:p}),()=>u(ne,ee({ref:i,modelValue:r.value,"onUpdate:modelValue":t=>r.value=t,columns:k.value,onChange:T,onCancel:a,onConfirm:f},le(e,Oe)),o)}});const qe=$(Be),[te,S]=R("dropdown-menu"),Re={overlay:M,zIndex:_,duration:re(.2),direction:se("down"),activeColor:String,autoLocate:Boolean,closeOnClickOutside:M,closeOnClickOverlay:M,swipeThreshold:_},ae=Symbol(te);var $e=A({name:te,props:Re,setup(e,{slots:l}){const o=Ce(),r=C(),n=C(),i=C(0),{children:s,linkChildren:m}=ce(ae),d=ie(r),g=B(()=>s.some(a=>a.state.showWrapper)),h=B(()=>e.swipeThreshold&&s.length>+e.swipeThreshold),D=B(()=>{if(g.value&&ue(e.zIndex))return{zIndex:+e.zIndex+1}}),x=()=>{s.forEach(a=>{a.toggle(!1)})},P=()=>{e.closeOnClickOutside&&x()},b=()=>{if(n.value){const a=J(n);e.direction==="down"?i.value=a.bottom:i.value=me.value-a.top}},p=()=>{g.value&&b()},k=a=>{s.forEach((f,t)=>{t===a?f.toggle():f.state.showPopup&&f.toggle(!1,{immediate:!0})})},T=(a,f)=>{const{showPopup:t}=a.state,{disabled:c,titleClass:v}=a;return u("div",{id:`${o}-${f}`,role:"button",tabindex:c?void 0:0,class:[S("item",{disabled:c,grow:h.value}),{[L]:!c}],onClick:()=>{c||k(f)}},[u("span",{class:[S("title",{down:t===(e.direction==="down"),active:t}),v],style:{color:t?e.activeColor:""}},[u("div",{class:"van-ellipsis"},[a.renderTitle()])])])};return N({close:x}),m({id:o,props:e,offset:i,updateOffset:b}),de(r,P),fe("scroll",p,{target:d,passive:!0}),()=>{var a;return u("div",{ref:r,class:S()},[u("div",{ref:n,style:D.value,class:S("bar",{opened:g.value,scrollable:h.value})},[s.map(T)]),(a=l.default)==null?void 0:a.call(l)])}}});const[Ae,V]=R("dropdown-item"),Ye={title:String,options:q(),disabled:Boolean,teleport:[String,Object],lazyRender:M,modelValue:K,titleClass:K};var Ee=A({name:Ae,inheritAttrs:!1,props:Ye,emits:["open","opened","close","closed","change","update:modelValue"],setup(e,{emit:l,slots:o,attrs:r}){const n=ye({showPopup:!1,transition:!0,showWrapper:!1}),i=C(),{parent:s,index:m}=he(ae);if(!s)return;const d=a=>()=>l(a),g=d("open"),h=d("close"),D=d("opened"),x=()=>{n.showWrapper=!1,l("closed")},P=a=>{e.teleport&&a.stopPropagation()},b=(a=!n.showPopup,f={})=>{a!==n.showPopup&&(n.showPopup=a,n.transition=!f.immediate,a&&(s.updateOffset(),n.showWrapper=!0))},p=()=>{if(o.title)return o.title();if(e.title)return e.title;const a=e.options.find(f=>f.value===e.modelValue);return a?a.text:""},k=a=>{const{activeColor:f}=s.props,{disabled:t}=a,c=a.value===e.modelValue,v=()=>{t||(n.showPopup=!1,a.value!==e.modelValue&&(l("update:modelValue",a.value),l("change",a.value)))},y=()=>{if(c)return u(X,{class:V("icon"),color:t?void 0:f,name:"success"},null)};return u(be,{role:"menuitem",key:String(a.value),icon:a.icon,title:a.text,class:V("option",{active:c,disabled:t}),style:{color:c?f:""},tabindex:c?0:-1,clickable:!t,onClick:v},{value:y})},T=()=>{const{offset:a}=s,{autoLocate:f,zIndex:t,overlay:c,duration:v,direction:y,closeOnClickOverlay:I}=s.props,Y=Q(t);let E=a.value;if(f&&i.value){const O=ve(i.value);O&&(E-=J(O).top)}return y==="down"?Y.top=`${E}px`:Y.bottom=`${E}px`,we(u("div",ee({ref:i,style:Y,class:V([y]),onClick:P},r),[u(ke,{show:n.showPopup,"onUpdate:show":O=>n.showPopup=O,role:"menu",class:V("content"),overlay:c,position:y==="down"?"top":"bottom",duration:n.transition?v:0,lazyRender:e.lazyRender,overlayStyle:{position:"absolute"},"aria-labelledby":`${s.id}-${m.value}`,closeOnClickOverlay:I,onOpen:g,onClose:h,onOpened:D,onClosed:x},{default:()=>{var O;return[e.options.map(k),(O=o.default)==null?void 0:O.call(o)]}})]),[[xe,n.showWrapper]])};return N({state:n,toggle:b,renderTitle:p}),()=>e.teleport?u(De,{to:e.teleport},{default:()=>[T()]}):T()}});const Ge=$(Ee),Je=$($e),[ze,w]=R("nav-bar"),Fe={title:String,fixed:Boolean,zIndex:_,border:M,leftText:String,rightText:String,leftDisabled:Boolean,rightDisabled:Boolean,leftArrow:Boolean,placeholder:Boolean,safeAreaInsetTop:Boolean,clickable:M};var _e=A({name:ze,props:Fe,emits:["clickLeft","clickRight"],setup(e,{emit:l,slots:o}){const r=C(),n=Pe(r,w),i=h=>{e.leftDisabled||l("clickLeft",h)},s=h=>{e.rightDisabled||l("clickRight",h)},m=()=>o.left?o.left():[e.leftArrow&&u(X,{class:w("arrow"),name:"arrow-left"},null),e.leftText&&u("span",{class:w("text")},[e.leftText])],d=()=>o.right?o.right():u("span",{class:w("text")},[e.rightText]),g=()=>{const{title:h,fixed:D,border:x,zIndex:P}=e,b=Q(P),p=e.leftArrow||e.leftText||o.left,k=e.rightText||o.right;return u("div",{ref:r,style:b,class:[w({fixed:D}),{[ge]:x,"van-safe-area-top":e.safeAreaInsetTop}]},[u("div",{class:w("content")},[p&&u("div",{class:[w("left",{disabled:e.leftDisabled}),e.clickable&&!e.leftDisabled?L:""],onClick:i},[m()]),u("div",{class:[w("title"),"van-ellipsis"]},[o.title?o.title():h]),k&&u("div",{class:[w("right",{disabled:e.rightDisabled}),e.clickable&&!e.rightDisabled?L:""],onClick:s},[d()])])])};return()=>e.fixed&&e.placeholder?n(g):g()}});const Qe=$(_e);const Xe=function(e){const l=new Date;let o=l.getFullYear(),r=l.getMonth(),n=l.getDate(),i=0,s=0,m=Math.trunc(e/12),d=e%12;return d<r?(i=o-m,s=r-d):(i=o-m-1,s=r+12-d),new Date(i,s,n)};export{qe as D,Qe as N,Je as a,Ge as b,Xe as g};