1 |
- import{A as S,d as E,I as K,aa as I,S as b,V as C,U as J,W as f,a2 as g,aj as p,j as B,a7 as U,aA as W,aP as h,ar as N,$ as te,b5 as j,N as ae}from"./index.e6d6174e.js";import{s as L,t as Q,p as R,a as X,g as z,b as ne}from"./utils.5fa3f1eb.js";import{P as A}from"./index.00bf6672.js";const[ue]=S("time-picker");var Z=E({name:ue,props:K({},L,{minHour:I(0),maxHour:I(23),minMinute:I(0),maxMinute:I(59),modelValue:String}),emits:["confirm","cancel","change","update:modelValue"],setup(t,{emit:c,slots:$}){const d=u=>{const{minHour:e,maxHour:a,maxMinute:n,minMinute:r}=t;u||(u=`${h(e)}:${h(r)}`);let[i,m]=u.split(":");return i=h(N(+i,+e,+a)),m=h(N(+m,+r,+n)),`${i}:${m}`},l=b(),o=b(d(t.modelValue)),M=C(()=>[{type:"hour",range:[+t.minHour,+t.maxHour]},{type:"minute",range:[+t.minMinute,+t.maxMinute]}]),Y=C(()=>M.value.map(({type:u,range:e})=>{let a=Q(e[1]-e[0]+1,n=>h(e[0]+n));return t.filter&&(a=t.filter(u,a)),{type:u,values:a}})),x=C(()=>Y.value.map(u=>({values:u.values.map(e=>t.formatter(u.type,e))}))),k=()=>{const u=o.value.split(":"),e=[t.formatter("hour",u[0]),t.formatter("minute",u[1])];f(()=>{var a;(a=l.value)==null||a.setValues(e)})},D=()=>{const[u,e]=l.value.getIndexes(),[a,n]=Y.value,r=a.values[u]||a.values[0],i=n.values[e]||n.values[0];o.value=d(`${r}:${i}`),k()},V=()=>c("confirm",o.value),O=()=>c("cancel"),_=()=>{D(),f(()=>{f(()=>c("change",o.value))})};return J(()=>{k(),f(D)}),g(x,k),g(()=>[t.filter,t.maxHour,t.minMinute,t.maxMinute],D),g(()=>t.minHour,()=>{f(D)}),g(o,u=>c("update:modelValue",u)),g(()=>t.modelValue,u=>{u=d(u),u!==o.value&&(o.value=u,k())}),p({getPicker:()=>l.value&&R(l.value,D)}),()=>B(A,U({ref:l,columns:x.value,onChange:_,onCancel:O,onConfirm:V},W(t,X)),$)}});const G=new Date().getFullYear(),[oe]=S("date-picker");var q=E({name:oe,props:K({},L,{type:te("datetime"),modelValue:Date,minDate:{type:Date,default:()=>new Date(G-10,0,1),validator:j},maxDate:{type:Date,default:()=>new Date(G+10,11,31),validator:j}}),emits:["confirm","cancel","change","update:modelValue"],setup(t,{emit:c,slots:$}){const d=e=>{if(j(e)){const a=N(e.getTime(),t.minDate.getTime(),t.maxDate.getTime());return new Date(a)}},l=b(),o=b(d(t.modelValue)),M=(e,a)=>{const n=t[`${e}Date`],r=n.getFullYear();let i=1,m=1,v=0,y=0;return e==="max"&&(i=12,m=z(a.getFullYear(),a.getMonth()+1),v=23,y=59),a.getFullYear()===r&&(i=n.getMonth()+1,a.getMonth()+1===i&&(m=n.getDate(),a.getDate()===m&&(v=n.getHours(),a.getHours()===v&&(y=n.getMinutes())))),{[`${e}Year`]:r,[`${e}Month`]:i,[`${e}Date`]:m,[`${e}Hour`]:v,[`${e}Minute`]:y}},Y=C(()=>{const{maxYear:e,maxDate:a,maxMonth:n,maxHour:r,maxMinute:i}=M("max",o.value||t.minDate),{minYear:m,minDate:v,minMonth:y,minHour:w,minMinute:F}=M("min",o.value||t.minDate);let s=[{type:"year",range:[m,e]},{type:"month",range:[y,n]},{type:"day",range:[v,a]},{type:"hour",range:[w,r]},{type:"minute",range:[F,i]}];switch(t.type){case"date":s=s.slice(0,3);break;case"year-month":s=s.slice(0,2);break;case"month-day":s=s.slice(1,3);break;case"datehour":s=s.slice(0,4);break}if(t.columnsOrder){const P=t.columnsOrder.concat(s.map(H=>H.type));s.sort((H,T)=>P.indexOf(H.type)-P.indexOf(T.type))}return s}),x=C(()=>Y.value.map(({type:e,range:a})=>{let n=Q(a[1]-a[0]+1,r=>h(a[0]+r));return t.filter&&(n=t.filter(e,n)),{type:e,values:n}})),k=C(()=>x.value.map(e=>({values:e.values.map(a=>t.formatter(e.type,a))}))),D=()=>{const e=o.value||t.minDate,{formatter:a}=t,n=x.value.map(r=>{switch(r.type){case"year":return a("year",`${e.getFullYear()}`);case"month":return a("month",h(e.getMonth()+1));case"day":return a("day",h(e.getDate()));case"hour":return a("hour",h(e.getHours()));case"minute":return a("minute",h(e.getMinutes()));default:return""}});f(()=>{var r;(r=l.value)==null||r.setValues(n)})},V=()=>{const{type:e}=t,a=l.value.getIndexes(),n=s=>{let P=0;x.value.forEach((T,ee)=>{s===T.type&&(P=ee)});const{values:H}=x.value[P];return ne(H[a[P]])};let r,i,m;e==="month-day"?(r=(o.value||t.minDate).getFullYear(),i=n("month"),m=n("day")):(r=n("year"),i=n("month"),m=e==="year-month"?1:n("day"));const v=z(r,i);m=m>v?v:m;let y=0,w=0;e==="datehour"&&(y=n("hour")),e==="datetime"&&(y=n("hour"),w=n("minute"));const F=new Date(r,i-1,m,y,w);o.value=d(F)},O=()=>{c("update:modelValue",o.value),c("confirm",o.value)},_=()=>c("cancel"),u=()=>{V(),f(()=>{f(()=>c("change",o.value))})};return J(()=>{D(),f(V)}),g(k,D),g(o,(e,a)=>c("update:modelValue",a?e:null)),g(()=>[t.filter,t.maxDate],V),g(()=>t.minDate,()=>{f(V)}),g(()=>t.modelValue,e=>{var a;e=d(e),e&&e.valueOf()!==((a=o.value)==null?void 0:a.valueOf())&&(o.value=e)}),p({getPicker:()=>l.value&&R(l.value,V)}),()=>B(A,U({ref:l,columns:k.value,onChange:u,onCancel:_,onConfirm:O},W(t,X)),$)}});const[re,le]=S("datetime-picker"),ie=Object.keys(Z.props),me=Object.keys(q.props),se=K({},Z.props,q.props,{modelValue:[String,Date]});var ce=E({name:re,props:se,setup(t,{attrs:c,slots:$}){const d=b();return p({getPicker:()=>{var l;return(l=d.value)==null?void 0:l.getPicker()}}),()=>{const l=t.type==="time",o=l?Z:q,M=W(t,l?ie:me);return B(o,U({ref:d,class:le()},M,c),$)}}});const he=ae(ce);export{he as D};
|