index-703ac3ab.js 2.3 KB

1
  1. import{ac as Y,ab as A,b5 as k,$ as E,c as T,bH as x,d as I,r as v,e as N,w as M,aS as f,a as $,h as j,ae as B,k as H}from"./index-5e5e4ebc.js";import{p as P,P as K}from"./index-06479965.js";const R=Y({},P,{modelValue:A(),filter:Function,formatter:{type:Function,default:(t,n)=>n}}),U=Object.keys(P);function Z(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=Z(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(E(+c,s,l))}return c}),V=new Date().getFullYear(),[z]=T("date-picker"),G=Y({},R,{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:G,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,w=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()}},F=()=>{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)&&w(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 F();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),S=(...e)=>n("confirm",...e);return()=>$(K,j({modelValue:a.value,"onUpdate:modelValue":e=>a.value=e,columns:g.value,onChange:O,onCancel:b,onConfirm:S},B(t,U)),c)}});const W=H(J);export{W as D};