From 12f752178b1357eef6a659dcf76594acb6af53d6 Mon Sep 17 00:00:00 2001 From: linhf123 Date: Tue, 5 Mar 2024 16:00:54 +0800 Subject: [PATCH] style: update --- packages/ui/src/DateRanger/PickerPanel.tsx | 4 +- packages/ui/src/DateRanger/Ranger.tsx | 508 +++++++++++---------- packages/ui/src/DateRanger/demo/basic.tsx | 8 +- packages/ui/src/DateRanger/demo/basic2.tsx | 8 +- packages/ui/src/DateRanger/index.less | 2 +- 5 files changed, 272 insertions(+), 258 deletions(-) diff --git a/packages/ui/src/DateRanger/PickerPanel.tsx b/packages/ui/src/DateRanger/PickerPanel.tsx index 9e575787a..88e858dd3 100644 --- a/packages/ui/src/DateRanger/PickerPanel.tsx +++ b/packages/ui/src/DateRanger/PickerPanel.tsx @@ -177,7 +177,7 @@ const InternalPickerPanel = (props: PickerPanelProps) => { }, ]} > - + @@ -210,7 +210,7 @@ const InternalPickerPanel = (props: PickerPanelProps) => { }, ]} > - + diff --git a/packages/ui/src/DateRanger/Ranger.tsx b/packages/ui/src/DateRanger/Ranger.tsx index 1981098dd..fbed31823 100644 --- a/packages/ui/src/DateRanger/Ranger.tsx +++ b/packages/ui/src/DateRanger/Ranger.tsx @@ -85,9 +85,9 @@ const Ranger = (props: DateRangerProps) => { defaultValue, defaultQuickValue, hasRewind = true, - hasPlay = true, + hasPlay = false, hasForward = true, - hasZoomOut = true, + hasZoomOut = false, pastOnly = false, onChange = noop, disabledDate, @@ -264,16 +264,20 @@ const Ranger = (props: DateRangerProps) => { return `近 ${differenceSeconds} 秒`; }; + const setNow = () => { + const selected = NEAR_TIME_LIST.find(item => item.name === rangeName); + if (selected?.range) { + rangeChange(selected.range(isMoment ? moment() : dayjs()) as RangeValue); + } + if (rangeName === CUSTOMIZE) { + const eTime = isMoment ? moment() : dayjs(); + rangeChange([(eTime as Dayjs)?.subtract(differenceMs), eTime] as RangeValue); + } + }; + useInterval( () => { - const selected = NEAR_TIME_LIST.find(item => item.name === rangeName); - if (selected?.range) { - rangeChange(selected.range(isMoment ? moment() : dayjs()) as RangeValue); - } - if (rangeName === CUSTOMIZE) { - const eTime = isMoment ? moment() : dayjs(); - rangeChange([(eTime as Dayjs)?.subtract(differenceMs), eTime] as RangeValue); - } + setNow(); }, isPlay ? 1000 : null ); @@ -303,261 +307,271 @@ const Ranger = (props: DateRangerProps) => { : selects[rangeNameIndex + 1]; return ( - -
- { - if ( - o === false && - (refState.current.tooltipOpen || refState.current.step === STEP_CUSTOMIZE) - ) { - return; - } + + +
+ { + if ( + o === false && + (refState.current.tooltipOpen || refState.current.step === STEP_CUSTOMIZE) + ) { + return; + } - setOpen(o); - }} - dropdownRender={menu => { - if (step === STEP_CUSTOMIZE) { - return ( -
- { - setStep(STEP_QUICK); + setOpen(o); + }} + dropdownRender={menu => { + if (step === STEP_CUSTOMIZE) { + return ( +
- 返回上一层 - - { - setIsPlay(false); - rangeChange( - vList.map(v => { - return isMoment ? moment(v) : dayjs(v); - }) as RangeValue - ); - setStep(STEP_QUICK); - closeTooltip(); - }} - onCancel={() => { - setStep(STEP_QUICK); - closeTooltip(); - }} - /> -
- ); - } - return menu; - }} - menu={{ - items: [ - ...selects, - { - name: CUSTOMIZE, - rangeLabel: '自定义', - label: '自定义时间', - }, - ] - .filter(item => { - return !!item; - }) - .map(item => { - return { - key: item.name, - label: - item.name === CUSTOMIZE && !isStepMode ? ( - { - if (o) { - setTooltipOpen(true); + { + setStep(STEP_QUICK); + }} + > + 返回上一层 + + { + setIsPlay(false); + rangeChange( + vList.map(v => { + return isMoment ? moment(v) : dayjs(v); + }) as RangeValue + ); + setStep(STEP_QUICK); + closeTooltip(); + }} + onCancel={() => { + setStep(STEP_QUICK); + closeTooltip(); + }} + /> +
+ ); + } + return menu; + }} + menu={{ + items: [ + ...selects, + { + name: CUSTOMIZE, + rangeLabel: '自定义', + label: '自定义时间', + }, + ] + .filter(item => { + return !!item; + }) + .map(item => { + return { + key: item.name, + label: + item.name === CUSTOMIZE && !isStepMode ? ( + { + if (o) { + setTooltipOpen(true); + } + }} + placement="right" + overlayStyle={{ + maxWidth: 'none', + }} + overlayInnerStyle={{ + background: '#fff', + }} + title={ + { + setIsPlay(false); + rangeChange( + vList.map(v => { + return isMoment ? moment(v) : dayjs(v); + }) as RangeValue + ); + + closeTooltip(); + }} + onCancel={() => { + closeTooltip(); + }} + /> } - }} - placement="right" - overlayStyle={{ - maxWidth: 'none', - }} - overlayInnerStyle={{ - background: '#fff', - }} - title={ - { - setIsPlay(false); + > + + {item.rangeLabel} + {/* @ts-ignore */} + {locale[item.label] || item.label} + + + ) : ( + { + const rName = item.name; + handleNameChange(rName); + + if (rName === CUSTOMIZE && isStepMode) { + // 阻止冒泡事件,不触发 Dropdown 的默认关闭 + e.stopPropagation(); + return setStep(STEP_CUSTOMIZE); + } + + const selected = NEAR_TIME_LIST.find(_item => _item.name === rName); + // 存在快捷选项切换为极简模式 + if (selected?.range) { + setIsPlay(true); rangeChange( - vList.map(v => { - return isMoment ? moment(v) : dayjs(v); - }) as RangeValue + selected.range(isMoment ? moment() : dayjs()) as RangeValue ); - - closeTooltip(); - }} - onCancel={() => { - closeTooltip(); - }} - /> - } - > - + } + }} + > {item.rangeLabel} {/* @ts-ignore */} {locale[item.label] || item.label} - - ) : ( - { - const rName = item.name; - handleNameChange(rName); - - if (rName === CUSTOMIZE && isStepMode) { - // 阻止冒泡事件,不触发 Dropdown 的默认关闭 - e.stopPropagation(); - return setStep(STEP_CUSTOMIZE); - } - - const selected = NEAR_TIME_LIST.find(_item => _item.name === rName); - // 存在快捷选项切换为极简模式 - if (selected?.range) { - setIsPlay(true); - rangeChange( - selected.range(isMoment ? moment() : dayjs()) as RangeValue - ); - } - }} - > - {item.rangeLabel} - {/* @ts-ignore */} - {locale[item.label] || item.label} - - ), - }; - }), - }} - > - + ), + }; + }), + }} + > + + + {rangeLabel} + + {isPlay &&
{label}
} +
+
+ {!isPlay && ( { + setOpen(true); }} > - {rangeLabel} + {/* @ts-ignore */} + { + // format 会影响布局,原先采用 v.year() === new Date().getFullYear() 进行判断,value 一共会传入三次(range0 range1 now), 会传入最新的时间导致判断异常 + return isThisYear ? v.format(DATE_TIME_FORMAT) : v.format(YEAR_DATE_TIME_FORMAT); + }} + // @ts-ignore + defaultValue={defaultValue} + // @ts-ignore + value={innerValue || defaultInternalValue} + onChange={datePickerChange} + showTime={true} + allowClear={false} + size={size} + // 透传 props 到 antd Ranger + {...omit(rest, 'value', 'onChange')} + /> - {isPlay &&
{label}
} - - - {!isPlay && ( - { - setOpen(true); - }} - > - {/* @ts-ignore */} - { - // format 会影响布局,原先采用 v.year() === new Date().getFullYear() 进行判断,value 一共会传入三次(range0 range1 now), 会传入最新的时间导致判断异常 - return isThisYear ? v.format(DATE_TIME_FORMAT) : v.format(YEAR_DATE_TIME_FORMAT); - }} - // @ts-ignore - defaultValue={defaultValue} - // @ts-ignore - value={innerValue || defaultInternalValue} - onChange={datePickerChange} - showTime={true} - allowClear={false} - size={size} - // 透传 props 到 antd Ranger - {...omit(rest, 'value', 'onChange')} - /> - - )} -
- - {hasRewind && ( - { - if (isPlay) { - setIsPlay(false); - } + )} +
+ + {hasRewind && ( + { + if (isPlay) { + setIsPlay(false); + } - if (startTime && endTime) { - const newStartTime = (startTime as Dayjs).subtract(differenceMs); - const newEndTime = startTime?.clone() as Dayjs; + if (startTime && endTime) { + const newStartTime = (startTime as Dayjs).subtract(differenceMs); + const newEndTime = startTime?.clone() as Dayjs; - rangeChange([newStartTime, newEndTime]); - } - }} - > - - - )} - {hasPlay && ( - { - const newPlay = !isPlay; - setIsPlay(newPlay); - }} - > - {isPlay ? : } - - )} - {hasForward && ( - { - if (startTime && endTime) { - const newStartTime = endTime.clone() as Dayjs; - const newEndTime = (endTime as Dayjs).add(differenceMs); - - if (newEndTime.isBefore(new Date())) { rangeChange([newStartTime, newEndTime]); - } else { - setIsPlay(true); } - } - }} - > - - - )} - + }} + > + + + )} + {hasPlay && ( + { + const newPlay = !isPlay; + setIsPlay(newPlay); + }} + > + {isPlay ? : } + + )} + {hasForward && ( + { + if (startTime && endTime) { + const newStartTime = endTime.clone() as Dayjs; + const newEndTime = (endTime as Dayjs).add(differenceMs); + + if (newEndTime.isBefore(new Date())) { + rangeChange([newStartTime, newEndTime]); + } else { + setIsPlay(true); + } + } + }} + > + + + )} + +
+ {hasZoomOut && (