index.cdab6a82.js 10 KB

1
  1. import{A as U,d as q,aw as j,aZ as de,V as M,j as c,bf as me,S as $,a1 as he,aj as ue,E as p,X as ee,au as ge,aA as z,$ as le,G as P,aa as ve,b5 as ie,a2 as K,a9 as ye,aR as De,at as Q,ag as be,a7 as we,T as se,B as ke,N as Te}from"./index.e6d6174e.js";import{u as Se}from"./use-refs.eb803454.js";import{g as xe}from"./utils.5fa3f1eb.js";import{u as Me}from"./use-height.8140ea04.js";const[Re,f,H]=U("calendar"),Oe=e=>H("monthTitle",e.getFullYear(),e.getMonth()+1);function te(e,s){const l=e.getFullYear(),d=s.getFullYear();if(l===d){const D=e.getMonth(),T=s.getMonth();return D===T?0:D>T?1:-1}return l>d?1:-1}function R(e,s){const l=te(e,s);if(l===0){const d=e.getDate(),D=s.getDate();return d===D?0:d>D?1:-1}return l}const V=e=>new Date(e),ce=e=>Array.isArray(e)?e.map(V):V(e);function oe(e,s){const l=V(e);return l.setDate(l.getDate()+s),l}const ne=e=>oe(e,-1),fe=e=>oe(e,1),ae=()=>{const e=new Date;return e.setHours(0,0,0,0),e};function Ce(e){const s=e[0].getTime();return(e[1].getTime()-s)/(1e3*60*60*24)+1}const[Ae]=U("calendar-day");var Pe=q({name:Ae,props:{item:j(Object),color:String,index:Number,offset:de(0),rowHeight:String},emits:["click"],setup(e,{emit:s,slots:l}){const d=M(()=>{const{item:a,index:h,color:k,offset:B,rowHeight:C}=e,S={height:C};if(a.type==="placeholder")return S.width="100%",S;if(h===0&&(S.marginLeft=`${100*B/7}%`),k)switch(a.type){case"end":case"start":case"start-end":case"multiple-middle":case"multiple-selected":S.background=k;break;case"middle":S.color=k;break}return S}),D=()=>{e.item.type!=="disabled"&&s("click",e.item)},T=()=>{const{topInfo:a}=e.item;if(a||l["top-info"])return c("div",{class:f("top-info")},[l["top-info"]?l["top-info"](e.item):a])},O=()=>{const{bottomInfo:a}=e.item;if(a||l["bottom-info"])return c("div",{class:f("bottom-info")},[l["bottom-info"]?l["bottom-info"](e.item):a])},b=()=>{const{item:a,color:h,rowHeight:k}=e,{type:B,text:C}=a,S=[T(),C,O()];return B==="selected"?c("div",{class:f("selected-day"),style:{width:k,height:k,background:h}},[S]):S};return()=>{const{type:a,className:h}=e.item;return a==="placeholder"?c("div",{class:f("day"),style:d.value},null):c("div",{role:"gridcell",style:d.value,class:[f("day",a),h],tabindex:a==="disabled"?void 0:-1,onClick:D},[b()])}}});const[Be]=U("calendar-month"),Ie={date:j(Date),type:String,color:String,minDate:j(Date),maxDate:j(Date),showMark:Boolean,rowHeight:p,formatter:Function,lazyRender:Boolean,currentDate:[Date,Array],allowSameDay:Boolean,showSubtitle:Boolean,showMonthTitle:Boolean,firstDayOfWeek:Number};var He=q({name:Be,props:Ie,emits:["click","update-height"],setup(e,{emit:s,slots:l}){const[d,D]=me(),T=$(),O=$(),b=Me(O),a=M(()=>Oe(e.date)),h=M(()=>he(e.rowHeight)),k=M(()=>{const o=e.date.getDay();return e.firstDayOfWeek?(o+7-e.firstDayOfWeek)%7:o}),B=M(()=>xe(e.date.getFullYear(),e.date.getMonth()+1)),C=M(()=>d.value||!e.lazyRender),S=()=>a.value,N=o=>{const m=g=>e.currentDate.some(u=>R(u,g)===0);if(m(o)){const g=ne(o),u=fe(o),t=m(g),n=m(u);return t&&n?"multiple-middle":t?"end":n?"start":"multiple-selected"}return""},_=o=>{const[m,g]=e.currentDate;if(!m)return"";const u=R(o,m);if(!g)return u===0?"start":"";const t=R(o,g);return e.allowSameDay&&u===0&&t===0?"start-end":u===0?"start":t===0?"end":u>0&&t<0?"middle":""},W=o=>{const{type:m,minDate:g,maxDate:u,currentDate:t}=e;if(R(o,g)<0||R(o,u)>0)return"disabled";if(t===null)return"";if(Array.isArray(t)){if(m==="multiple")return N(o);if(m==="range")return _(o)}else if(m==="single")return R(o,t)===0?"selected":"";return""},Y=o=>{if(e.type==="range"){if(o==="start"||o==="end")return H(o);if(o==="start-end")return`${H("start")}/${H("end")}`}},E=()=>{if(e.showMonthTitle)return c("div",{class:f("month-title")},[a.value])},G=()=>{if(e.showMark&&C.value)return c("div",{class:f("month-mark")},[e.date.getMonth()+1])},F=M(()=>{const o=Math.ceil((B.value+k.value)/7);return Array(o).fill({type:"placeholder"})}),x=M(()=>{const o=[],m=e.date.getFullYear(),g=e.date.getMonth();for(let u=1;u<=B.value;u++){const t=new Date(m,g,u),n=W(t);let r={date:t,type:n,text:u,bottomInfo:Y(n)};e.formatter&&(r=e.formatter(r)),o.push(r)}return o}),L=M(()=>x.value.filter(o=>o.type==="disabled")),X=(o,m)=>{if(T.value){const g=ee(T.value),u=F.value.length,n=(Math.ceil((m.getDate()+k.value)/7)-1)*g.height/u;ge(o,g.top+n+o.scrollTop-ee(o).top)}},Z=(o,m)=>c(Pe,{item:o,index:m,color:e.color,offset:k.value,rowHeight:h.value,onClick:g=>s("click",g)},z(l,["top-info","bottom-info"])),J=()=>c("div",{ref:T,role:"grid",class:f("days")},[G(),(C.value?x:F).value.map(Z)]);return ue({getTitle:S,getHeight:()=>b.value,setVisible:D,scrollToDate:X,disabledDays:L}),()=>c("div",{class:f("month"),ref:O},[E(),J()])}});const[Ne]=U("calendar-header");var We=q({name:Ne,props:{title:String,subtitle:String,showTitle:Boolean,showSubtitle:Boolean,firstDayOfWeek:Number},emits:["click-subtitle"],setup(e,{slots:s,emit:l}){const d=()=>{if(e.showTitle){const b=e.title||H("title"),a=s.title?s.title():b;return c("div",{class:f("header-title")},[a])}},D=b=>l("click-subtitle",b),T=()=>{if(e.showSubtitle){const b=s.subtitle?s.subtitle():e.subtitle;return c("div",{class:f("header-subtitle"),onClick:D},[b])}},O=()=>{const{firstDayOfWeek:b}=e,a=H("weekdays"),h=[...a.slice(b,7),...a.slice(0,b)];return c("div",{class:f("weekdays")},[h.map(k=>c("span",{class:f("weekday")},[k]))])};return()=>c("div",{class:f("header")},[d(),T(),O()])}});const Fe={show:Boolean,type:le("single"),title:String,color:String,round:P,readonly:Boolean,poppable:P,maxRange:ve(null),position:le("bottom"),teleport:[String,Object],showMark:P,showTitle:P,formatter:Function,rowHeight:p,confirmText:String,rangePrompt:String,lazyRender:P,showConfirm:P,defaultDate:[Date,Array],allowSameDay:Boolean,showSubtitle:P,closeOnPopstate:P,showRangePrompt:P,confirmDisabledText:String,closeOnClickOverlay:P,safeAreaInsetTop:Boolean,safeAreaInsetBottom:P,minDate:{type:Date,validator:ie,default:ae},maxDate:{type:Date,validator:ie,default:()=>{const e=ae();return new Date(e.getFullYear(),e.getMonth()+6,e.getDate())}},firstDayOfWeek:{type:p,default:0,validator:e=>e>=0&&e<=6}};var $e=q({name:Re,props:Fe,emits:["select","confirm","unselect","month-show","over-range","update:show","click-subtitle"],setup(e,{emit:s,slots:l}){const d=(t,n=e.minDate,r=e.maxDate)=>R(t,n)===-1?n:R(t,r)===1?r:t,D=(t=e.defaultDate)=>{const{type:n,minDate:r,maxDate:i}=e;if(t===null)return t;const v=ae();if(n==="range"){Array.isArray(t)||(t=[]);const w=d(t[0]||v,r,ne(i)),I=d(t[1]||v,fe(r));return[w,I]}return n==="multiple"?Array.isArray(t)?t.map(w=>d(w)):[d(v)]:((!t||Array.isArray(t))&&(t=v),d(t))};let T;const O=$(),b=$(""),a=$(D()),[h,k]=Se(),B=M(()=>e.firstDayOfWeek?+e.firstDayOfWeek%7:0),C=M(()=>{const t=[],n=new Date(e.minDate);n.setDate(1);do t.push(new Date(n)),n.setMonth(n.getMonth()+1);while(te(n,e.maxDate)!==1);return t}),S=M(()=>{if(a.value){if(e.type==="range")return!a.value[0]||!a.value[1];if(e.type==="multiple")return!a.value.length}return!a.value}),N=()=>{const t=be(O.value),n=t+T,r=C.value.map((y,A)=>h.value[A].getHeight()),i=r.reduce((y,A)=>y+A,0);if(n>i&&t>0)return;let v=0,w;const I=[-1,-1];for(let y=0;y<C.value.length;y++){const A=h.value[y];v<=n&&v+r[y]>=t&&(I[1]=y,w||(w=A,I[0]=y),h.value[y].showed||(h.value[y].showed=!0,s("month-show",{date:A.date,title:A.getTitle()}))),v+=r[y]}C.value.forEach((y,A)=>{const re=A>=I[0]-1&&A<=I[1]+1;h.value[A].setVisible(re)}),w&&(b.value=w.getTitle())},_=t=>{Q(()=>{C.value.some((n,r)=>te(n,t)===0?(O.value&&h.value[r].scrollToDate(O.value,t),!0):!1),N()})},W=()=>{if(!(e.poppable&&!e.show))if(a.value){const t=e.type==="single"?a.value:a.value[0];_(t)}else Q(N)},Y=()=>{e.poppable&&!e.show||Q(()=>{T=Math.floor(ee(O).height),W()})},E=(t=D())=>{a.value=t,W()},G=t=>{const{maxRange:n,rangePrompt:r,showRangePrompt:i}=e;return n&&Ce(t)>n?(i&&se(r||H("rangePrompt",n)),s("over-range"),!1):!0},F=()=>{var t;return s("confirm",(t=a.value)!=null?t:ce(a.value))},x=(t,n)=>{const r=i=>{a.value=i,s("select",ce(i))};if(n&&e.type==="range"&&!G(t)){r([t[0],oe(t[0],+e.maxRange-1)]);return}r(t),n&&!e.showConfirm&&F()},L=(t,n,r)=>{var i;return(i=t.find(v=>R(n,v.date)===-1&&R(v.date,r)===-1))==null?void 0:i.date},X=M(()=>h.value.reduce((t,n)=>{var r,i;return t.push(...(i=(r=n.disabledDays)==null?void 0:r.value)!=null?i:[]),t},[])),Z=t=>{if(e.readonly||!t.date)return;const{date:n}=t,{type:r}=e;if(r==="range"){if(!a.value){x([n]);return}const[i,v]=a.value;if(i&&!v){const w=R(n,i);if(w===1){const I=L(X.value,i,n);if(I){const y=ne(I);R(i,y)===-1?x([i,y]):x([n])}else x([i,n],!0)}else w===-1?x([n]):e.allowSameDay&&x([n,n],!0)}else x([n])}else if(r==="multiple"){if(!a.value){x([n]);return}const i=a.value,v=i.findIndex(w=>R(w,n)===0);if(v!==-1){const[w]=i.splice(v,1);s("unselect",V(w))}else e.maxRange&&i.length>=e.maxRange?se(e.rangePrompt||H("rangePrompt",e.maxRange)):x([...i,n])}else x(n,!0)},J=t=>s("update:show",t),o=(t,n)=>{const r=n!==0||!e.showSubtitle;return c(He,we({ref:k(n),date:t,currentDate:a.value,showMonthTitle:r,firstDayOfWeek:B.value},z(e,["type","color","minDate","maxDate","showMark","formatter","rowHeight","lazyRender","showSubtitle","allowSameDay"]),{onClick:Z}),z(l,["top-info","bottom-info"]))},m=()=>{if(l.footer)return l.footer();if(e.showConfirm){const t=l["confirm-text"],n=S.value,r=n?e.confirmDisabledText:e.confirmText;return c(ke,{round:!0,block:!0,type:"danger",color:e.color,class:f("confirm"),disabled:n,nativeType:"button",onClick:F},{default:()=>[t?t({disabled:n}):r||H("confirm")]})}},g=()=>c("div",{class:[f("footer"),{"van-safe-area-bottom":e.safeAreaInsetBottom}]},[m()]),u=()=>c("div",{class:f()},[c(We,{title:e.title,subtitle:b.value,showTitle:e.showTitle,showSubtitle:e.showSubtitle,firstDayOfWeek:B.value,"onClick-subtitle":t=>s("click-subtitle",t)},z(l,["title","subtitle"])),c("div",{ref:O,class:f("body"),onScroll:N},[C.value.map(o)]),g()]);return K(()=>e.show,Y),K(()=>[e.type,e.minDate,e.maxDate],()=>E(D(a.value))),K(()=>e.defaultDate,(t=null)=>{a.value=t,W()}),ue({reset:E,scrollToDate:_}),ye(Y),()=>e.poppable?c(De,{show:e.show,class:f("popup"),round:e.round,position:e.position,closeable:e.showTitle||e.showSubtitle,teleport:e.teleport,closeOnPopstate:e.closeOnPopstate,safeAreaInsetTop:e.safeAreaInsetTop,closeOnClickOverlay:e.closeOnClickOverlay,"onUpdate:show":J},{default:u}):u()}});const ze=Te($e);export{ze as C};