11import { defineComponent , PropType , computed } from 'vue' ;
2+ import { isArray } from 'lodash-es' ;
23import TDatePickerCell from './Cell' ;
34import { useConfig , usePrefixClass } from '../../hooks/useConfig' ;
4- import type { TdDatePickerProps } from '../type' ;
5+ import type { TdDatePickerProps , DateMultipleValue } from '../type' ;
56import { parseToDayjs } from '../../_common/js/date-picker/format' ;
67
78export default defineComponent ( {
@@ -12,6 +13,7 @@ export default defineComponent({
1213 default : 'date' ,
1314 } ,
1415 firstDayOfWeek : Number ,
16+ multiple : Boolean ,
1517 data : Array ,
1618 time : String ,
1719 value : [ String , Number , Array , Date ] ,
@@ -42,18 +44,18 @@ export default defineComponent({
4244 const showThead = computed ( ( ) => props . mode === 'date' || props . mode === 'week' ) ;
4345
4446 // 高亮周区间
45- const weekRowClass = ( value : any , format : string , targetValue : Date ) => {
47+ const weekRowClass = ( value : any , targetValue : Date ) => {
4648 if ( props . mode !== 'week' || ! value ) return { } ;
4749
48- if ( Array . isArray ( value ) ) {
50+ if ( isArray ( value ) ) {
4951 if ( ! value . length ) return { } ;
50- const [ startObj , endObj ] = value . map ( ( v ) => v && parseToDayjs ( v , format ) ) ;
52+ const [ startObj , endObj ] = value . map ( ( v ) => v && parseToDayjs ( v , props . format ) ) ;
5153 const startYear = startObj && startObj . year ( ) ;
5254 const startWeek = startObj ?. locale ?.( dayjsLocale ) ?. week ?.( ) ;
5355 const endYear = endObj && endObj . year ( ) ;
5456 const endWeek = endObj ?. locale ?.( dayjsLocale ) ?. week ?.( ) ;
5557
56- const targetObj = parseToDayjs ( targetValue , format ) ;
58+ const targetObj = parseToDayjs ( targetValue , props . format ) ;
5759 const targetYear = targetObj . year ( ) ;
5860 const targetWeek = targetObj . week ( ) ;
5961 const isActive = ( targetYear === startYear && targetWeek === startWeek ) || ( targetYear === endYear && targetWeek === endWeek ) ;
@@ -67,21 +69,34 @@ export default defineComponent({
6769
6870 return {
6971 [ `${ COMPONENT_NAME . value } -${ props . mode } -row--active` ] :
70- parseToDayjs ( value , format ) . locale ( dayjsLocale ) . week ( )
71- === parseToDayjs ( targetValue , format ) . locale ( dayjsLocale ) . week ( ) ,
72+ parseToDayjs ( value , props . format ) . locale ( dayjsLocale ) . week ( )
73+ === parseToDayjs ( targetValue , props . format ) . locale ( dayjsLocale ) . week ( ) ,
7274 } ;
7375 } ;
7476
77+ const multipleWeekRowClass = ( value : DateMultipleValue , targetValue : Date ) => {
78+ const targetDayjs = parseToDayjs ( targetValue , props . format ) ;
79+ if ( props . mode !== 'week' || ( Array . isArray ( value ) && ! value . length ) ) return { } ;
80+ const isSomeYearWeek = value
81+ . map ?.( ( v ) => parseToDayjs ( v , props . format ) )
82+ . some ( ( item ) => item . week ( ) === targetDayjs . week ( ) && item . year ( ) === targetDayjs . year ( ) ) ;
83+ return {
84+ [ `${ COMPONENT_NAME . value } -${ props . mode } -row--active` ] : isSomeYearWeek ,
85+ } ;
86+ } ;
87+
88+ const activeRowCss = props . multiple ? multipleWeekRowClass : weekRowClass ;
89+
7590 return {
7691 COMPONENT_NAME ,
7792 weekArr,
7893 showThead,
79- weekRowClass ,
94+ activeRowCss ,
8095 } ;
8196 } ,
8297 render ( ) {
8398 const {
84- COMPONENT_NAME , weekArr, showThead, weekRowClass ,
99+ COMPONENT_NAME , weekArr, showThead, activeRowCss ,
85100 } = this ;
86101
87102 return (
@@ -102,7 +117,7 @@ export default defineComponent({
102117 key = { i }
103118 class = { {
104119 [ `${ COMPONENT_NAME } -${ this . mode } -row` ] : true ,
105- ...weekRowClass ( this . value , this . format , row [ 0 ] . value ) ,
120+ ...activeRowCss ( this . value as any | DateMultipleValue [ ] , row [ 0 ] . value ) ,
106121 } }
107122 >
108123 { row . map ( ( col : any , j : number ) => (
0 commit comments