index-da1851f9.js 2.3 KB

1
  1. import{ad as Y,ac as E,bF as k,a0 as S,c as T,bG as x,d as I,r as v,e as N,w as M,bC as f,a as j,h as B,af as G,k as K}from"./index-869d77fb.js";import{p as P,P as R}from"./index-6f985828.js";const U=Y({},P,{modelValue:E(),filter:Function,formatter:{type:Function,default:(t,n)=>n}}),Z=Object.keys(P);function _(t,n){if(t<0)return[];const c=Array(t);let a=-1;for(;++a<t;)c[a]=n(a);return c}const $=(t,n)=>32-new Date(t,n-1,32).getDate(),D=(t,n,c,a,r,s)=>{const l=_(n-t+1,m=>{const i=k(t+m);return a(c,{text:i,value:i})});return r?r(c,l,s):l},q=(t,n)=>t.map((c,a)=>{const r=n[a];if(r.length){const s=+r[0].value,l=+r[r.length-1].value;return k(S(+c,s,l))}return c}),V=new Date().getFullYear(),[z]=T("date-picker"),H=Y({},U,{columnsType:{type:Array,default:()=>["year","month","day"]},minDate:{type:Date,default:()=>new Date(V-10,0,1),validator:x},maxDate:{type:Date,default:()=>new Date(V+10,11,31),validator:x}});var J=I({name:z,props:H,emits:["confirm","cancel","change","update:modelValue"],setup(t,{emit:n,slots:c}){const a=v(t.modelValue),r=v(!1),s=()=>{const e=t.minDate.getFullYear(),o=t.maxDate.getFullYear();return D(e,o,"year",t.formatter,t.filter)},l=e=>e===t.minDate.getFullYear(),m=e=>e===t.maxDate.getFullYear(),i=e=>e===t.minDate.getMonth()+1,F=e=>e===t.maxDate.getMonth()+1,h=e=>{const{minDate:o,columnsType:u}=t,d=u.indexOf(e),y=r.value?t.modelValue[d]:a.value[d];if(y)return+y;switch(e){case"year":return o.getFullYear();case"month":return o.getMonth()+1;case"day":return o.getDate()}},w=()=>{const e=h("year"),o=l(e)?t.minDate.getMonth()+1:1,u=m(e)?t.maxDate.getMonth()+1:12;return D(o,u,"month",t.formatter,t.filter)},C=()=>{const e=h("year"),o=h("month"),u=l(e)&&i(o)?t.minDate.getDate():1,d=m(e)&&F(o)?t.maxDate.getDate():$(e,o);return D(u,d,"day",t.formatter,t.filter)},g=N(()=>t.columnsType.map(e=>{switch(e){case"year":return s();case"month":return w();case"day":return C();default:throw new Error(`[Vant] DatePicker: unsupported columns type: ${e}`)}}));M(a,e=>{f(e,t.modelValue)||n("update:modelValue",e)}),M(()=>t.modelValue,(e,o)=>{r.value=f(o,a.value),e=q(e,g.value),f(e,a.value)||(a.value=e),r.value=!1},{immediate:!0});const O=(...e)=>n("change",...e),b=(...e)=>n("cancel",...e),A=(...e)=>n("confirm",...e);return()=>j(R,B({modelValue:a.value,"onUpdate:modelValue":e=>a.value=e,columns:g.value,onChange:O,onCancel:b,onConfirm:A},G(t,Z)),c)}});const W=K(J);export{W as D};