@zw-team/react-lib 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -0
- package/dist/components/AccessReport/index.d.ts +29 -0
- package/dist/components/AccessReport/index.js +129 -0
- package/dist/components/Avatar/Avatar.d.ts +3 -0
- package/dist/components/Avatar/Avatar.js +58 -0
- package/dist/components/Avatar/index.d.ts +2 -0
- package/dist/components/Avatar/index.js +2 -0
- package/dist/components/Avatar/types.d.ts +9 -0
- package/dist/components/Avatar/types.js +0 -0
- package/dist/components/Block/Block.css +8 -0
- package/dist/components/Block/Block.d.ts +4 -0
- package/dist/components/Block/Block.js +11 -0
- package/dist/components/Block/index.d.ts +2 -0
- package/dist/components/Block/index.js +2 -0
- package/dist/components/Block/types.d.ts +3 -0
- package/dist/components/Block/types.js +0 -0
- package/dist/components/ConfigProvider/ConfigContext.d.ts +4 -0
- package/dist/components/ConfigProvider/ConfigContext.js +19 -0
- package/dist/components/ConfigProvider/ConfigProvider.d.ts +4 -0
- package/dist/components/ConfigProvider/ConfigProvider.js +57 -0
- package/dist/components/ConfigProvider/index.d.ts +2 -0
- package/dist/components/ConfigProvider/index.js +2 -0
- package/dist/components/ConfigProvider/types.d.ts +19 -0
- package/dist/components/ConfigProvider/types.js +0 -0
- package/dist/components/CustomColumn/CustomColumn.d.ts +4 -0
- package/dist/components/CustomColumn/CustomColumn.js +388 -0
- package/dist/components/CustomColumn/CustomColumn.scss +135 -0
- package/dist/components/CustomColumn/index.d.ts +2 -0
- package/dist/components/CustomColumn/index.js +2 -0
- package/dist/components/CustomColumn/types.d.ts +19 -0
- package/dist/components/CustomColumn/types.js +0 -0
- package/dist/components/DatePicker/DatePicker.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.js +89 -0
- package/dist/components/DatePicker/datePickerOption.d.ts +14 -0
- package/dist/components/DatePicker/datePickerOption.js +149 -0
- package/dist/components/DatePicker/index.d.ts +2 -0
- package/dist/components/DatePicker/index.js +2 -0
- package/dist/components/DatePicker/types.d.ts +12 -0
- package/dist/components/DatePicker/types.js +0 -0
- package/dist/components/DatePickerPanel/DatePickerPanel.d.ts +6 -0
- package/dist/components/DatePickerPanel/DatePickerPanel.js +397 -0
- package/dist/components/DatePickerPanel/datePickerPanel.scss +362 -0
- package/dist/components/DatePickerPanel/index.d.ts +2 -0
- package/dist/components/DatePickerPanel/index.js +2 -0
- package/dist/components/DatePickerPanel/type.d.ts +23 -0
- package/dist/components/DatePickerPanel/type.js +0 -0
- package/dist/components/DownloadCenter/DownloadCenter.d.ts +5 -0
- package/dist/components/DownloadCenter/DownloadCenter.js +367 -0
- package/dist/components/DownloadCenter/index.css +54 -0
- package/dist/components/DownloadCenter/index.d.ts +2 -0
- package/dist/components/DownloadCenter/index.js +2 -0
- package/dist/components/DownloadCenter/types.d.ts +27 -0
- package/dist/components/DownloadCenter/types.js +0 -0
- package/dist/components/Fireworks/Fireworks.d.ts +11 -0
- package/dist/components/Fireworks/Fireworks.js +415 -0
- package/dist/components/Fireworks/imgs/birthday-cake.svg +180 -0
- package/dist/components/Fireworks/imgs/hb.png +0 -0
- package/dist/components/Fireworks/imgs/sd.png +0 -0
- package/dist/components/Fireworks/imgs/xc.png +0 -0
- package/dist/components/Fireworks/imgs/yd.png +0 -0
- package/dist/components/Fireworks/index.d.ts +2 -0
- package/dist/components/Fireworks/index.js +2 -0
- package/dist/components/Fireworks/index.scss +9 -0
- package/dist/components/Fireworks/types.d.ts +6 -0
- package/dist/components/Fireworks/types.js +0 -0
- package/dist/components/Form/Form.css +4 -0
- package/dist/components/Form/Form.d.ts +9 -0
- package/dist/components/Form/Form.js +18 -0
- package/dist/components/Form/index.d.ts +1 -0
- package/dist/components/Form/index.js +2 -0
- package/dist/components/FormItem/FormItem.css +38 -0
- package/dist/components/FormItem/FormItem.d.ts +9 -0
- package/dist/components/FormItem/FormItem.js +25 -0
- package/dist/components/FormItem/index.d.ts +1 -0
- package/dist/components/FormItem/index.js +2 -0
- package/dist/components/HomeData/HomeData.d.ts +6 -0
- package/dist/components/HomeData/HomeData.js +364 -0
- package/dist/components/HomeData/HomeData.scss +161 -0
- package/dist/components/HomeData/index.d.ts +1 -0
- package/dist/components/HomeData/index.js +2 -0
- package/dist/components/Icon/Icon.d.ts +4 -0
- package/dist/components/Icon/Icon.js +34 -0
- package/dist/components/Icon/index.d.ts +2 -0
- package/dist/components/Icon/index.js +2 -0
- package/dist/components/Icon/types.d.ts +8 -0
- package/dist/components/Icon/types.js +0 -0
- package/dist/components/Log/index.d.ts +2 -0
- package/dist/components/Log/index.js +2 -0
- package/dist/components/Log/src/Detail.d.ts +7 -0
- package/dist/components/Log/src/Detail.js +71 -0
- package/dist/components/Log/src/Detail.scss +27 -0
- package/dist/components/Log/src/Log.d.ts +5 -0
- package/dist/components/Log/src/Log.js +335 -0
- package/dist/components/Log/src/Log.scss +50 -0
- package/dist/components/Log/src/useLogTableColumns.d.ts +2 -0
- package/dist/components/Log/src/useLogTableColumns.js +141 -0
- package/dist/components/Log/types.d.ts +5 -0
- package/dist/components/Log/types.js +0 -0
- package/dist/components/LogButton/LogButton.d.ts +4 -0
- package/dist/components/LogButton/LogButton.js +30 -0
- package/dist/components/LogButton/index.d.ts +2 -0
- package/dist/components/LogButton/index.js +2 -0
- package/dist/components/LogButton/logbutton.css +15 -0
- package/dist/components/LogButton/types.d.ts +10 -0
- package/dist/components/LogButton/types.js +0 -0
- package/dist/components/LogDialog/BiLogManager.d.ts +29 -0
- package/dist/components/LogDialog/BiLogManager.js +78 -0
- package/dist/components/LogDialog/LogDialog.d.ts +8 -0
- package/dist/components/LogDialog/LogDialog.js +106 -0
- package/dist/components/LogDialog/LogDialog.scss +29 -0
- package/dist/components/LogDialog/index.d.ts +3 -0
- package/dist/components/LogDialog/index.js +3 -0
- package/dist/components/LogDialog/types.d.ts +8 -0
- package/dist/components/LogDialog/types.js +0 -0
- package/dist/components/MediaPreview/MediaPreview.d.ts +5 -0
- package/dist/components/MediaPreview/MediaPreview.js +124 -0
- package/dist/components/MediaPreview/hook.d.ts +26 -0
- package/dist/components/MediaPreview/hook.js +174 -0
- package/dist/components/MediaPreview/index.css +202 -0
- package/dist/components/MediaPreview/index.d.ts +2 -0
- package/dist/components/MediaPreview/index.js +2 -0
- package/dist/components/MediaPreview/types.d.ts +24 -0
- package/dist/components/MediaPreview/types.js +0 -0
- package/dist/components/Modal/Modal.d.ts +3 -0
- package/dist/components/Modal/Modal.js +31 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/index.js +2 -0
- package/dist/components/Modal/types.d.ts +8 -0
- package/dist/components/Modal/types.js +0 -0
- package/dist/components/ModalStore/ModalProvider.d.ts +11 -0
- package/dist/components/ModalStore/ModalProvider.js +15 -0
- package/dist/components/ModalStore/ModalStore.d.ts +78 -0
- package/dist/components/ModalStore/ModalStore.js +188 -0
- package/dist/components/ModalStore/index.d.ts +3 -0
- package/dist/components/ModalStore/index.js +4 -0
- package/dist/components/ModalStore/types.d.ts +73 -0
- package/dist/components/ModalStore/types.js +0 -0
- package/dist/components/MoreButton/MoreButton.d.ts +3 -0
- package/dist/components/MoreButton/MoreButton.js +50 -0
- package/dist/components/MoreButton/index.d.ts +2 -0
- package/dist/components/MoreButton/index.js +2 -0
- package/dist/components/MoreButton/types.d.ts +15 -0
- package/dist/components/MoreButton/types.js +0 -0
- package/dist/components/NavbarTool/NavbarTool.d.ts +5 -0
- package/dist/components/NavbarTool/NavbarTool.js +143 -0
- package/dist/components/NavbarTool/components/index.css +49 -0
- package/dist/components/NavbarTool/components/index.d.ts +5 -0
- package/dist/components/NavbarTool/components/index.js +98 -0
- package/dist/components/NavbarTool/index.css +14 -0
- package/dist/components/NavbarTool/index.d.ts +2 -0
- package/dist/components/NavbarTool/index.js +2 -0
- package/dist/components/NavbarTool/types.d.ts +40 -0
- package/dist/components/NavbarTool/types.js +0 -0
- package/dist/components/NoticeCenter/NoticeCenter.d.ts +4 -0
- package/dist/components/NoticeCenter/NoticeCenter.js +334 -0
- package/dist/components/NoticeCenter/assets/notice.png +0 -0
- package/dist/components/NoticeCenter/assets/tongzhi.png +0 -0
- package/dist/components/NoticeCenter/index.d.ts +2 -0
- package/dist/components/NoticeCenter/index.js +2 -0
- package/dist/components/NoticeCenter/noticeCenter.scss +232 -0
- package/dist/components/NoticeCenter/types.d.ts +6 -0
- package/dist/components/NoticeCenter/types.js +0 -0
- package/dist/components/Pagination/BiPagination.css +152 -0
- package/dist/components/Pagination/Pagination.d.ts +5 -0
- package/dist/components/Pagination/Pagination.js +67 -0
- package/dist/components/Pagination/index.d.ts +2 -0
- package/dist/components/Pagination/index.js +2 -0
- package/dist/components/Pagination/types.d.ts +14 -0
- package/dist/components/Pagination/types.js +0 -0
- package/dist/components/ResponseInterceptor/index.d.ts +17 -0
- package/dist/components/ResponseInterceptor/index.js +43 -0
- package/dist/components/SuperDate/SuperDate.d.ts +6 -0
- package/dist/components/SuperDate/SuperDate.js +113 -0
- package/dist/components/SuperDate/SuperDate.scss +42 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.d.ts +5 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.js +87 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.scss +52 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.d.ts +6 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.js +129 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/dynamicTimeCom.scss +70 -0
- package/dist/components/SuperDate/constant.d.ts +35 -0
- package/dist/components/SuperDate/constant.js +27 -0
- package/dist/components/SuperDate/index.d.ts +2 -0
- package/dist/components/SuperDate/index.js +2 -0
- package/dist/components/SuperDate/store.d.ts +68 -0
- package/dist/components/SuperDate/store.js +254 -0
- package/dist/components/SuperDate/types.d.ts +34 -0
- package/dist/components/SuperDate/types.js +0 -0
- package/dist/components/SuperDate/utils.d.ts +18 -0
- package/dist/components/SuperDate/utils.js +14 -0
- package/dist/components/SystemLink/SystemLink.d.ts +4 -0
- package/dist/components/SystemLink/SystemLink.js +85 -0
- package/dist/components/SystemLink/index.d.ts +1 -0
- package/dist/components/SystemLink/index.js +2 -0
- package/dist/components/SystemLink/index.scss +142 -0
- package/dist/components/Table/ResizableTitle.d.ts +3 -0
- package/dist/components/Table/ResizableTitle.js +43 -0
- package/dist/components/Table/Table.d.ts +9 -0
- package/dist/components/Table/Table.js +189 -0
- package/dist/components/Table/index.d.ts +2 -0
- package/dist/components/Table/index.js +2 -0
- package/dist/components/Table/index.scss +42 -0
- package/dist/components/Table/types.d.ts +24 -0
- package/dist/components/Table/types.js +0 -0
- package/dist/components/Table/useHeaderPopper.d.ts +8 -0
- package/dist/components/Table/useHeaderPopper.js +95 -0
- package/dist/components/TableHeaderPopper/EditBox.d.ts +6 -0
- package/dist/components/TableHeaderPopper/EditBox.js +208 -0
- package/dist/components/TableHeaderPopper/Popover.d.ts +6 -0
- package/dist/components/TableHeaderPopper/Popover.js +85 -0
- package/dist/components/TableHeaderPopper/index.d.ts +3 -0
- package/dist/components/TableHeaderPopper/index.js +3 -0
- package/dist/components/TableHeaderPopper/index.scss +96 -0
- package/dist/components/TaskCenter/TaskCenter.d.ts +4 -0
- package/dist/components/TaskCenter/TaskCenter.js +257 -0
- package/dist/components/TaskCenter/TaskCenter.scss +44 -0
- package/dist/components/TaskCenter/api.d.ts +13 -0
- package/dist/components/TaskCenter/api.js +13 -0
- package/dist/components/TaskCenter/index.d.ts +2 -0
- package/dist/components/TaskCenter/index.js +2 -0
- package/dist/components/TaskCenter/types.d.ts +29 -0
- package/dist/components/TaskCenter/types.js +0 -0
- package/dist/components/TooltipIcon/TooltipIcon.d.ts +3 -0
- package/dist/components/TooltipIcon/TooltipIcon.js +43 -0
- package/dist/components/TooltipIcon/index.d.ts +2 -0
- package/dist/components/TooltipIcon/index.js +2 -0
- package/dist/components/TooltipIcon/types.d.ts +14 -0
- package/dist/components/TooltipIcon/types.js +0 -0
- package/dist/components/Verification/content.d.ts +11 -0
- package/dist/components/Verification/content.js +223 -0
- package/dist/components/Verification/index.css +43 -0
- package/dist/components/Verification/index.d.ts +1 -0
- package/dist/components/Verification/index.js +37 -0
- package/dist/components/index.d.ts +32 -0
- package/dist/components/index.js +29 -0
- package/dist/config/index.d.ts +83 -0
- package/dist/config/index.js +115 -0
- package/dist/config/theme/index.d.ts +368 -0
- package/dist/config/theme/index.js +369 -0
- package/dist/hooks/createAlive.d.ts +11 -0
- package/dist/hooks/createAlive.js +22 -0
- package/dist/hooks/createGlobalState.d.ts +7 -0
- package/dist/hooks/createGlobalState.js +28 -0
- package/dist/hooks/index.d.ts +26 -0
- package/dist/hooks/index.js +25 -0
- package/dist/hooks/useAsync.d.ts +27 -0
- package/dist/hooks/useAsync.js +76 -0
- package/dist/hooks/useClickOther.d.ts +10 -0
- package/dist/hooks/useClickOther.js +30 -0
- package/dist/hooks/useCopyToClipboard.d.ts +7 -0
- package/dist/hooks/useCopyToClipboard.js +32 -0
- package/dist/hooks/useCreate.d.ts +7 -0
- package/dist/hooks/useCreate.js +21 -0
- package/dist/hooks/useEventListener.d.ts +22 -0
- package/dist/hooks/useEventListener.js +33 -0
- package/dist/hooks/useHistoryStore.d.ts +16 -0
- package/dist/hooks/useHistoryStore.js +106 -0
- package/dist/hooks/useIntersectionObserver.d.ts +8 -0
- package/dist/hooks/useIntersectionObserver.js +23 -0
- package/dist/hooks/useInterval.d.ts +8 -0
- package/dist/hooks/useInterval.js +19 -0
- package/dist/hooks/useLatest.d.ts +2 -0
- package/dist/hooks/useLatest.js +12 -0
- package/dist/hooks/useLockAsyncFn.d.ts +7 -0
- package/dist/hooks/useLockAsyncFn.js +24 -0
- package/dist/hooks/useLockFn.d.ts +7 -0
- package/dist/hooks/useLockFn.js +17 -0
- package/dist/hooks/useMergedState.d.ts +10 -0
- package/dist/hooks/useMergedState.js +30 -0
- package/dist/hooks/useMountedState.d.ts +4 -0
- package/dist/hooks/useMountedState.js +13 -0
- package/dist/hooks/usePermission.d.ts +8 -0
- package/dist/hooks/usePermission.js +21 -0
- package/dist/hooks/usePersistFn.d.ts +8 -0
- package/dist/hooks/usePersistFn.js +13 -0
- package/dist/hooks/useReactive.d.ts +7 -0
- package/dist/hooks/useReactive.js +34 -0
- package/dist/hooks/useRefresh.d.ts +5 -0
- package/dist/hooks/useRefresh.js +8 -0
- package/dist/hooks/useToggle.d.ts +16 -0
- package/dist/hooks/useToggle.js +20 -0
- package/dist/hooks/useUnmount.d.ts +6 -0
- package/dist/hooks/useUnmount.js +10 -0
- package/dist/hooks/useUpdateEffect.d.ts +9 -0
- package/dist/hooks/useUpdateEffect.js +10 -0
- package/dist/hooks/useWindowSize.d.ts +6 -0
- package/dist/hooks/useWindowSize.js +15 -0
- package/dist/hooks/util.d.ts +9 -0
- package/dist/hooks/util.js +6 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/utils/array.d.ts +12 -0
- package/dist/utils/array.js +15 -0
- package/dist/utils/classNames.d.ts +4 -0
- package/dist/utils/classNames.js +19 -0
- package/dist/utils/date.d.ts +98 -0
- package/dist/utils/date.js +101 -0
- package/dist/utils/debounce.d.ts +8 -0
- package/dist/utils/debounce.js +38 -0
- package/dist/utils/deepClone.d.ts +6 -0
- package/dist/utils/deepClone.js +10 -0
- package/dist/utils/empty.d.ts +16 -0
- package/dist/utils/empty.js +24 -0
- package/dist/utils/formatPrice.d.ts +2 -0
- package/dist/utils/formatPrice.js +15 -0
- package/dist/utils/getUUID.d.ts +1 -0
- package/dist/utils/getUUID.js +17 -0
- package/dist/utils/getUrlParams.d.ts +11 -0
- package/dist/utils/getUrlParams.js +10 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/listToTree.d.ts +12 -0
- package/dist/utils/listToTree.js +14 -0
- package/dist/utils/object.d.ts +6 -0
- package/dist/utils/object.js +5 -0
- package/dist/utils/ossUpload.d.ts +45 -0
- package/dist/utils/ossUpload.js +88 -0
- package/dist/utils/parseTo.d.ts +6 -0
- package/dist/utils/parseTo.js +9 -0
- package/dist/utils/request/accessReport.d.ts +2 -0
- package/dist/utils/request/accessReport.js +27 -0
- package/dist/utils/request/defaultRequest.d.ts +9 -0
- package/dist/utils/request/defaultRequest.js +33 -0
- package/dist/utils/request/exportDownload.d.ts +2 -0
- package/dist/utils/request/exportDownload.js +28 -0
- package/dist/utils/request/index.d.ts +29 -0
- package/dist/utils/request/index.js +40 -0
- package/dist/utils/request/noticeCenter.d.ts +2 -0
- package/dist/utils/request/noticeCenter.js +28 -0
- package/dist/utils/svgIcon/index.d.ts +47 -0
- package/dist/utils/svgIcon/index.js +76 -0
- package/dist/utils/throttle.d.ts +10 -0
- package/dist/utils/throttle.js +21 -0
- package/dist/utils/time/index.d.ts +7 -0
- package/dist/utils/time/index.js +12 -0
- package/dist/utils/tools.d.ts +43 -0
- package/dist/utils/tools.js +57 -0
- package/package.json +116 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./dynamicTimeCom.scss";
|
|
3
|
+
import { Button, Input, InputNumber } from "antd";
|
|
4
|
+
import dayjs from "dayjs";
|
|
5
|
+
import { BiDatePickerPanel } from "../../../index.js";
|
|
6
|
+
import { isNotNull } from "../../../../utils/index.js";
|
|
7
|
+
import { CONSTANT_DATA, TIME_CONSTANTS } from "../../constant.js";
|
|
8
|
+
import { useSuperDateStore } from "../../store.js";
|
|
9
|
+
import { checkHasTime } from "../../utils.js";
|
|
10
|
+
const DynamicTimeCom_DynamicTimeCom = ({ needTime })=>{
|
|
11
|
+
const { timeRange, setTimeRange, leftButtonActive, setLeftButtonActive, leftPastNDays, setLeftPastNDays, rightPastNDays, setRightPastNDays, rightButtonActive, setRightButtonActive } = useSuperDateStore();
|
|
12
|
+
const handleSpecificChange = (date)=>{
|
|
13
|
+
if (date) timeRange?.[1] ? setTimeRange([
|
|
14
|
+
date,
|
|
15
|
+
timeRange?.[1]
|
|
16
|
+
]) : setTimeRange([
|
|
17
|
+
date,
|
|
18
|
+
null
|
|
19
|
+
]);
|
|
20
|
+
};
|
|
21
|
+
const handleLeftPastNDaysChange = (e)=>{
|
|
22
|
+
const value = Number(e.target.value) || 0;
|
|
23
|
+
if (isNotNull(value)) {
|
|
24
|
+
setLeftPastNDays?.(value);
|
|
25
|
+
let day = dayjs().add(-value, 'day');
|
|
26
|
+
if (needTime) {
|
|
27
|
+
const origin = timeRange?.[0];
|
|
28
|
+
day = origin && checkHasTime(origin) ? day.hour(origin.hour()).minute(origin.minute()).second(origin.second()) : day.hour(0).minute(0).second(0);
|
|
29
|
+
}
|
|
30
|
+
setTimeRange([
|
|
31
|
+
day,
|
|
32
|
+
timeRange?.[1] ?? null
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const handleRightPastNDaysChange = (value)=>{
|
|
37
|
+
const _value = value ?? 2;
|
|
38
|
+
const day = needTime ? dayjs().add(-_value, 'day').hour(TIME_CONSTANTS.END_HOUR).minute(TIME_CONSTANTS.END_MINUTE).second(TIME_CONSTANTS.END_SECOND) : dayjs().add(-_value, 'day');
|
|
39
|
+
setTimeRange([
|
|
40
|
+
timeRange?.[0] ?? null,
|
|
41
|
+
day
|
|
42
|
+
]);
|
|
43
|
+
setRightPastNDays?.(_value);
|
|
44
|
+
};
|
|
45
|
+
const handleRightPastNDaysButtonChange = (type)=>{
|
|
46
|
+
setRightButtonActive?.(type);
|
|
47
|
+
if ('today' === type) setTimeRange([
|
|
48
|
+
timeRange?.[0],
|
|
49
|
+
needTime ? dayjs().hour(TIME_CONSTANTS.END_HOUR).minute(TIME_CONSTANTS.END_MINUTE).second(TIME_CONSTANTS.END_SECOND) : dayjs()
|
|
50
|
+
]);
|
|
51
|
+
else if ('yesterday' === type) setTimeRange([
|
|
52
|
+
timeRange?.[0],
|
|
53
|
+
needTime ? dayjs().add(-1, 'day').hour(TIME_CONSTANTS.END_HOUR).minute(TIME_CONSTANTS.END_MINUTE).second(TIME_CONSTANTS.END_SECOND) : dayjs().add(-1, 'day')
|
|
54
|
+
]);
|
|
55
|
+
};
|
|
56
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
57
|
+
className: "super-date-dynamic-time-container",
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ jsxs("div", {
|
|
60
|
+
className: "left-container",
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ jsxs("div", {
|
|
63
|
+
children: [
|
|
64
|
+
/*#__PURE__*/ jsx(Button, {
|
|
65
|
+
className: `dynamic-time-com-button ${leftButtonActive === CONSTANT_DATA.SPECIFIC ? 'active' : ''}`,
|
|
66
|
+
onClick: ()=>setLeftButtonActive?.(CONSTANT_DATA.SPECIFIC),
|
|
67
|
+
children: "具体时间"
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ jsx(Button, {
|
|
70
|
+
className: `dynamic-time-com-button ${leftButtonActive === CONSTANT_DATA.PAST ? 'active' : ''}`,
|
|
71
|
+
onClick: ()=>setLeftButtonActive?.(CONSTANT_DATA.PAST),
|
|
72
|
+
children: "过去N天"
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
}),
|
|
76
|
+
/*#__PURE__*/ jsx("div", {
|
|
77
|
+
className: "left-container-content",
|
|
78
|
+
children: leftButtonActive === CONSTANT_DATA.SPECIFIC ? /*#__PURE__*/ jsx(BiDatePickerPanel, {
|
|
79
|
+
value: timeRange?.[0],
|
|
80
|
+
mode: "single",
|
|
81
|
+
disabledDateAfterToday: true,
|
|
82
|
+
onChange: handleSpecificChange,
|
|
83
|
+
needTime: needTime
|
|
84
|
+
}) : /*#__PURE__*/ jsx(Input, {
|
|
85
|
+
className: "past-time-input",
|
|
86
|
+
value: leftPastNDays,
|
|
87
|
+
onChange: handleLeftPastNDaysChange
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
}),
|
|
92
|
+
/*#__PURE__*/ jsxs("div", {
|
|
93
|
+
className: "right-container",
|
|
94
|
+
children: [
|
|
95
|
+
/*#__PURE__*/ jsxs("div", {
|
|
96
|
+
children: [
|
|
97
|
+
/*#__PURE__*/ jsx(Button, {
|
|
98
|
+
className: `dynamic-time-com-button ${rightButtonActive === CONSTANT_DATA.TODAY ? 'active' : ''}`,
|
|
99
|
+
onClick: ()=>handleRightPastNDaysButtonChange(CONSTANT_DATA.TODAY),
|
|
100
|
+
children: "今日"
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ jsx(Button, {
|
|
103
|
+
className: `dynamic-time-com-button ${rightButtonActive === CONSTANT_DATA.YESTERDAY ? 'active' : ''}`,
|
|
104
|
+
onClick: ()=>handleRightPastNDaysButtonChange(CONSTANT_DATA.YESTERDAY),
|
|
105
|
+
children: "昨日"
|
|
106
|
+
}),
|
|
107
|
+
/*#__PURE__*/ jsx(Button, {
|
|
108
|
+
className: `dynamic-time-com-button ${rightButtonActive === CONSTANT_DATA.PAST_N_DAYS ? 'active' : ''}`,
|
|
109
|
+
onClick: ()=>setRightButtonActive?.(CONSTANT_DATA.PAST_N_DAYS),
|
|
110
|
+
children: "过去N天"
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
}),
|
|
114
|
+
/*#__PURE__*/ jsx("div", {
|
|
115
|
+
className: "right-container-content",
|
|
116
|
+
children: rightButtonActive === CONSTANT_DATA.PAST_N_DAYS && /*#__PURE__*/ jsx(InputNumber, {
|
|
117
|
+
onChange: handleRightPastNDaysChange,
|
|
118
|
+
className: "past-time-input",
|
|
119
|
+
value: rightPastNDays,
|
|
120
|
+
min: 2
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const DynamicTimeCom = DynamicTimeCom_DynamicTimeCom;
|
|
129
|
+
export { DynamicTimeCom as default };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.super-date-dynamic-time-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
width: 556px;
|
|
4
|
+
height: 300px;
|
|
5
|
+
padding: 10px 10px 0;
|
|
6
|
+
|
|
7
|
+
.left-container {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
justify-content: flex-start;
|
|
11
|
+
align-items: flex-start;
|
|
12
|
+
width: 50%;
|
|
13
|
+
height: 100%;
|
|
14
|
+
|
|
15
|
+
.dynamic-time-com-button {
|
|
16
|
+
border-radius: 3px;
|
|
17
|
+
|
|
18
|
+
&:nth-child(2) {
|
|
19
|
+
margin-left: 10px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&.active {
|
|
23
|
+
background-color: #00b781;
|
|
24
|
+
color: #fff;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.left-container-content {
|
|
29
|
+
width: calc(100% - 10px);
|
|
30
|
+
|
|
31
|
+
.past-time-input {
|
|
32
|
+
margin-top: 10px;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.right-container {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
justify-content: flex-start;
|
|
43
|
+
align-items: flex-start;
|
|
44
|
+
width: 50%;
|
|
45
|
+
height: 100%;
|
|
46
|
+
|
|
47
|
+
.dynamic-time-com-button {
|
|
48
|
+
border-radius: 3px;
|
|
49
|
+
|
|
50
|
+
&:nth-child(2),
|
|
51
|
+
&:nth-child(3) {
|
|
52
|
+
margin-left: 10px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&.active {
|
|
56
|
+
background-color: #00b781;
|
|
57
|
+
color: #fff;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.right-container-content {
|
|
62
|
+
width: 100%;
|
|
63
|
+
|
|
64
|
+
.past-time-input {
|
|
65
|
+
width: 100%;
|
|
66
|
+
margin-top: 10px;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const TAB_ACTIVE_KEY: {
|
|
2
|
+
STATIC: string;
|
|
3
|
+
DYNAMIC: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const CONSTANT_DATA: {
|
|
6
|
+
SPECIFIC: string;
|
|
7
|
+
PAST: string;
|
|
8
|
+
TODAY: string;
|
|
9
|
+
YESTERDAY: string;
|
|
10
|
+
PAST_N_DAYS: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const PANEL_HEIGHT: {
|
|
13
|
+
readonly STATIC: 340;
|
|
14
|
+
readonly DYNAMIC: 380;
|
|
15
|
+
};
|
|
16
|
+
/** 日期格式常量 */
|
|
17
|
+
export declare const DATE_FORMAT: {
|
|
18
|
+
/** 日期格式:YYYY-MM-DD */
|
|
19
|
+
readonly DATE: "YYYY-MM-DD";
|
|
20
|
+
/** 日期时间格式:YYYY-MM-DD HH:mm:ss */
|
|
21
|
+
readonly DATETIME: "YYYY-MM-DD HH:mm:ss";
|
|
22
|
+
/** 时间格式:HH:mm:ss */
|
|
23
|
+
readonly TIME: "HH:mm:ss";
|
|
24
|
+
};
|
|
25
|
+
/** 时间常量 */
|
|
26
|
+
export declare const TIME_CONSTANTS: {
|
|
27
|
+
/** 一天结束的小时 */
|
|
28
|
+
readonly END_HOUR: 23;
|
|
29
|
+
/** 一天结束的分钟 */
|
|
30
|
+
readonly END_MINUTE: 59;
|
|
31
|
+
/** 一天结束的秒 */
|
|
32
|
+
readonly END_SECOND: 59;
|
|
33
|
+
/** 默认右侧过去天数 */
|
|
34
|
+
readonly DEFAULT_RIGHT_PAST_DAYS: 2;
|
|
35
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const TAB_ACTIVE_KEY = {
|
|
2
|
+
STATIC: '1',
|
|
3
|
+
DYNAMIC: '2'
|
|
4
|
+
};
|
|
5
|
+
const CONSTANT_DATA = {
|
|
6
|
+
SPECIFIC: 'specific',
|
|
7
|
+
PAST: 'past',
|
|
8
|
+
TODAY: 'today',
|
|
9
|
+
YESTERDAY: 'yesterday',
|
|
10
|
+
PAST_N_DAYS: 'pastNDays'
|
|
11
|
+
};
|
|
12
|
+
const PANEL_HEIGHT = {
|
|
13
|
+
STATIC: 340,
|
|
14
|
+
DYNAMIC: 380
|
|
15
|
+
};
|
|
16
|
+
const DATE_FORMAT = {
|
|
17
|
+
DATE: 'YYYY-MM-DD',
|
|
18
|
+
DATETIME: 'YYYY-MM-DD HH:mm:ss',
|
|
19
|
+
TIME: 'HH:mm:ss'
|
|
20
|
+
};
|
|
21
|
+
const TIME_CONSTANTS = {
|
|
22
|
+
END_HOUR: 23,
|
|
23
|
+
END_MINUTE: 59,
|
|
24
|
+
END_SECOND: 59,
|
|
25
|
+
DEFAULT_RIGHT_PAST_DAYS: 2
|
|
26
|
+
};
|
|
27
|
+
export { CONSTANT_DATA, DATE_FORMAT, PANEL_HEIGHT, TAB_ACTIVE_KEY, TIME_CONSTANTS };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Dayjs } from 'dayjs';
|
|
2
|
+
import type { DateRangeValue } from '../DatePickerPanel';
|
|
3
|
+
import type { LeftButtonActive, RightButtonActive, SuperDateReturnValues } from './types';
|
|
4
|
+
interface SuperDateState {
|
|
5
|
+
/**
|
|
6
|
+
* 标签激活状态
|
|
7
|
+
*/
|
|
8
|
+
tabActiveKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* 日期范围
|
|
11
|
+
*/
|
|
12
|
+
timeRange: DateRangeValue;
|
|
13
|
+
/**
|
|
14
|
+
* 动态时间-左侧切换tab(具体时间(specific)/过去N天(past))
|
|
15
|
+
*/
|
|
16
|
+
leftButtonActive: LeftButtonActive;
|
|
17
|
+
/**
|
|
18
|
+
* 左侧过去N天的值
|
|
19
|
+
*/
|
|
20
|
+
leftPastNDays: number;
|
|
21
|
+
/**
|
|
22
|
+
* 动态时间-右侧切换tab(今日(today)/昨日(yesterday)/过去N天(pastNDays))
|
|
23
|
+
*/
|
|
24
|
+
rightButtonActive: RightButtonActive;
|
|
25
|
+
/**
|
|
26
|
+
* 右侧过去N天的值
|
|
27
|
+
*/
|
|
28
|
+
rightPastNDays: number;
|
|
29
|
+
/**
|
|
30
|
+
* 是否需要时间
|
|
31
|
+
*/
|
|
32
|
+
needTime: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 设置标签激活状态
|
|
35
|
+
*/
|
|
36
|
+
setTabActiveKey: (tabActiveKey: string) => void;
|
|
37
|
+
setTimeRange: (timeRange: DateRangeValue | Dayjs) => void;
|
|
38
|
+
setLeftButtonActive: (leftButtonActive: LeftButtonActive) => void;
|
|
39
|
+
setLeftPastNDays: (day: number) => void;
|
|
40
|
+
setRightButtonActive: (rightButtonActive: RightButtonActive) => void;
|
|
41
|
+
setRightPastNDays: (day: number) => void;
|
|
42
|
+
setNeedTime: (needTime: boolean) => void;
|
|
43
|
+
/**
|
|
44
|
+
* 处理标签切换
|
|
45
|
+
* 如果为动态时间(DYNAMIC),判断 timeRange 的结尾时间(右端)和当天的关系,设置右侧按钮状态
|
|
46
|
+
*/
|
|
47
|
+
handleTabChange: (tabActiveKey: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* 处理日期清除
|
|
50
|
+
*/
|
|
51
|
+
handleCalendarChange: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* 处理RangePicker Change时候的回调
|
|
54
|
+
* 主要用于配制了rangePresets属性(最近一周、最近一个月、最近三个月等场景)
|
|
55
|
+
*/
|
|
56
|
+
handleRangeChange: (value: DateRangeValue) => void;
|
|
57
|
+
/**
|
|
58
|
+
* 初始化RangePicker的值
|
|
59
|
+
*/
|
|
60
|
+
initRangePickerValue: (value: SuperDateReturnValues & {
|
|
61
|
+
needTime?: boolean;
|
|
62
|
+
}) => void;
|
|
63
|
+
/** 计算标题 */
|
|
64
|
+
calcTitle: () => string;
|
|
65
|
+
calcReturnValues: () => SuperDateReturnValues;
|
|
66
|
+
}
|
|
67
|
+
export declare const useSuperDateStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SuperDateState>>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { create } from "zustand";
|
|
3
|
+
import { isNotEmpty } from "../../utils/index.js";
|
|
4
|
+
import { CONSTANT_DATA, DATE_FORMAT, TAB_ACTIVE_KEY, TIME_CONSTANTS } from "./constant.js";
|
|
5
|
+
import { checkHasTime, getDateFormat, getTodayStart, isToday, setEndOfDay } from "./utils.js";
|
|
6
|
+
const calculateDaysDiffFromToday = (date)=>{
|
|
7
|
+
if (!date) return 0;
|
|
8
|
+
const today = getTodayStart();
|
|
9
|
+
const targetDate = dayjs(date).startOf('day');
|
|
10
|
+
const diff = today.diff(targetDate, 'day');
|
|
11
|
+
return diff >= 0 ? diff : 0;
|
|
12
|
+
};
|
|
13
|
+
const useSuperDateStore = create((set, get)=>({
|
|
14
|
+
tabActiveKey: TAB_ACTIVE_KEY.STATIC,
|
|
15
|
+
timeRange: null,
|
|
16
|
+
leftButtonActive: CONSTANT_DATA.SPECIFIC,
|
|
17
|
+
leftPastNDays: 0,
|
|
18
|
+
rightButtonActive: CONSTANT_DATA.TODAY,
|
|
19
|
+
rightPastNDays: TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS,
|
|
20
|
+
needTime: false,
|
|
21
|
+
setTabActiveKey: (tabActiveKey)=>set({
|
|
22
|
+
tabActiveKey
|
|
23
|
+
}),
|
|
24
|
+
setTimeRange: (timeRange)=>set({
|
|
25
|
+
timeRange: timeRange
|
|
26
|
+
}),
|
|
27
|
+
setLeftButtonActive: (leftButtonActive)=>{
|
|
28
|
+
const { timeRange } = get();
|
|
29
|
+
const updates = {
|
|
30
|
+
leftButtonActive
|
|
31
|
+
};
|
|
32
|
+
if (leftButtonActive === CONSTANT_DATA.PAST) updates.leftPastNDays = calculateDaysDiffFromToday(timeRange?.[0] ?? null);
|
|
33
|
+
set(updates);
|
|
34
|
+
},
|
|
35
|
+
setLeftPastNDays: (day)=>set({
|
|
36
|
+
leftPastNDays: day
|
|
37
|
+
}),
|
|
38
|
+
setRightButtonActive: (rightButtonActive)=>{
|
|
39
|
+
const { timeRange, needTime } = get();
|
|
40
|
+
const updates = {
|
|
41
|
+
rightButtonActive
|
|
42
|
+
};
|
|
43
|
+
if (rightButtonActive === CONSTANT_DATA.PAST_N_DAYS) {
|
|
44
|
+
const end = timeRange?.[1];
|
|
45
|
+
const diff = end ? calculateDaysDiffFromToday(end) : 0;
|
|
46
|
+
const rightPastNDays = diff >= TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS ? diff : TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS;
|
|
47
|
+
updates.rightPastNDays = rightPastNDays;
|
|
48
|
+
const endDate = dayjs().add(-rightPastNDays, 'day');
|
|
49
|
+
updates.timeRange = [
|
|
50
|
+
timeRange?.[0],
|
|
51
|
+
needTime ? setEndOfDay(endDate) : endDate
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
set(updates);
|
|
55
|
+
},
|
|
56
|
+
setRightPastNDays: (day)=>set({
|
|
57
|
+
rightPastNDays: day
|
|
58
|
+
}),
|
|
59
|
+
setNeedTime: (needTime)=>set({
|
|
60
|
+
needTime
|
|
61
|
+
}),
|
|
62
|
+
handleTabChange: (tabActiveKey)=>{
|
|
63
|
+
set({
|
|
64
|
+
tabActiveKey
|
|
65
|
+
});
|
|
66
|
+
if (tabActiveKey === TAB_ACTIVE_KEY.DYNAMIC) {
|
|
67
|
+
const state = get();
|
|
68
|
+
let { timeRange } = state;
|
|
69
|
+
timeRange = timeRange?.[0] && timeRange?.[1] ? [
|
|
70
|
+
...timeRange
|
|
71
|
+
] : timeRange?.[0] && !timeRange?.[1] ? [
|
|
72
|
+
timeRange[0],
|
|
73
|
+
null
|
|
74
|
+
] : !timeRange?.[0] && timeRange?.[1] ? [
|
|
75
|
+
null,
|
|
76
|
+
timeRange[1]
|
|
77
|
+
] : [
|
|
78
|
+
dayjs(),
|
|
79
|
+
dayjs()
|
|
80
|
+
];
|
|
81
|
+
const end = timeRange?.[1] ? dayjs(timeRange[1]) : null;
|
|
82
|
+
if (end) {
|
|
83
|
+
const today = getTodayStart();
|
|
84
|
+
const endDay = end.startOf('day');
|
|
85
|
+
const diff = today.diff(endDay, 'day');
|
|
86
|
+
const updates = {
|
|
87
|
+
timeRange
|
|
88
|
+
};
|
|
89
|
+
if (0 === diff) {
|
|
90
|
+
updates.rightButtonActive = CONSTANT_DATA.TODAY;
|
|
91
|
+
updates.rightPastNDays = TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS;
|
|
92
|
+
} else if (1 === diff) {
|
|
93
|
+
updates.rightButtonActive = CONSTANT_DATA.YESTERDAY;
|
|
94
|
+
updates.rightPastNDays = TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS;
|
|
95
|
+
} else if (diff > 1) {
|
|
96
|
+
updates.rightButtonActive = CONSTANT_DATA.PAST_N_DAYS;
|
|
97
|
+
updates.rightPastNDays = diff;
|
|
98
|
+
} else if (diff < 0) {
|
|
99
|
+
updates.timeRange = [
|
|
100
|
+
timeRange?.[0] ?? null,
|
|
101
|
+
dayjs()
|
|
102
|
+
];
|
|
103
|
+
updates.rightButtonActive = CONSTANT_DATA.TODAY;
|
|
104
|
+
updates.rightPastNDays = TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS;
|
|
105
|
+
}
|
|
106
|
+
set(updates);
|
|
107
|
+
timeRange = get().timeRange;
|
|
108
|
+
} else set({
|
|
109
|
+
rightButtonActive: CONSTANT_DATA.TODAY,
|
|
110
|
+
rightPastNDays: TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS,
|
|
111
|
+
timeRange: [
|
|
112
|
+
timeRange?.[0] ?? null,
|
|
113
|
+
dayjs()
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
const start = timeRange?.[0] ? dayjs(timeRange[0]) : null;
|
|
117
|
+
if (start) {
|
|
118
|
+
const today = getTodayStart();
|
|
119
|
+
const startDay = start.startOf('day');
|
|
120
|
+
const diff = today.diff(startDay, 'day');
|
|
121
|
+
if (diff < 0) {
|
|
122
|
+
set({
|
|
123
|
+
timeRange: [
|
|
124
|
+
today,
|
|
125
|
+
timeRange?.[1] ?? null
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
timeRange = get().timeRange;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const { leftButtonActive } = get();
|
|
132
|
+
if (leftButtonActive === CONSTANT_DATA.PAST) if (timeRange?.[0]) {
|
|
133
|
+
const today = getTodayStart();
|
|
134
|
+
const start = dayjs(timeRange[0]).startOf('day');
|
|
135
|
+
const leftDiff = today.diff(start, 'day');
|
|
136
|
+
leftDiff >= 0 ? set({
|
|
137
|
+
leftPastNDays: leftDiff
|
|
138
|
+
}) : set({
|
|
139
|
+
timeRange: [
|
|
140
|
+
today,
|
|
141
|
+
timeRange?.[1] ?? null
|
|
142
|
+
],
|
|
143
|
+
leftPastNDays: 0
|
|
144
|
+
});
|
|
145
|
+
} else set({
|
|
146
|
+
leftPastNDays: 0
|
|
147
|
+
});
|
|
148
|
+
else set({
|
|
149
|
+
leftPastNDays: 0
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
handleCalendarChange: ()=>{
|
|
154
|
+
set({
|
|
155
|
+
timeRange: null,
|
|
156
|
+
leftPastNDays: 0,
|
|
157
|
+
rightPastNDays: TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS,
|
|
158
|
+
rightButtonActive: CONSTANT_DATA.TODAY,
|
|
159
|
+
leftButtonActive: CONSTANT_DATA.SPECIFIC,
|
|
160
|
+
tabActiveKey: TAB_ACTIVE_KEY.STATIC
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
handleRangeChange: (value)=>set({
|
|
164
|
+
timeRange: value
|
|
165
|
+
}),
|
|
166
|
+
initRangePickerValue: (value)=>{
|
|
167
|
+
const needTime = value.needTime ?? false;
|
|
168
|
+
let timeRange;
|
|
169
|
+
if (needTime) {
|
|
170
|
+
const startDate = value.date[0];
|
|
171
|
+
const endDate = value.date[1];
|
|
172
|
+
if (isNotEmpty(startDate) && isNotEmpty(endDate)) {
|
|
173
|
+
const startDayjs = dayjs(startDate);
|
|
174
|
+
const endDayjs = dayjs(endDate);
|
|
175
|
+
const hasStartTime = checkHasTime(startDayjs);
|
|
176
|
+
const hasEndTime = checkHasTime(endDayjs);
|
|
177
|
+
timeRange = [
|
|
178
|
+
hasStartTime ? startDayjs : startDayjs.startOf('day'),
|
|
179
|
+
hasEndTime ? endDayjs : setEndOfDay(endDayjs)
|
|
180
|
+
];
|
|
181
|
+
} else {
|
|
182
|
+
const today = dayjs();
|
|
183
|
+
timeRange = [
|
|
184
|
+
today.startOf('day'),
|
|
185
|
+
setEndOfDay(today)
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
} else timeRange = [
|
|
189
|
+
dayjs(value.date[0]),
|
|
190
|
+
dayjs(value.date[1])
|
|
191
|
+
];
|
|
192
|
+
const tabActiveKey = 'dynamic' === value.type ? TAB_ACTIVE_KEY.DYNAMIC : TAB_ACTIVE_KEY.STATIC;
|
|
193
|
+
const leftButtonActive = 'string' == typeof value.dynamicRange[0] ? CONSTANT_DATA.SPECIFIC : 'number' == typeof value.dynamicRange[0] ? CONSTANT_DATA.PAST : CONSTANT_DATA.SPECIFIC;
|
|
194
|
+
const leftPastNDays = 'number' == typeof value.dynamicRange[0] ? value.dynamicRange[0] : 0;
|
|
195
|
+
let rightButtonActive;
|
|
196
|
+
rightButtonActive = 'number' == typeof value.dynamicRange[1] ? 0 === value.dynamicRange[1] ? CONSTANT_DATA.TODAY : 1 === value.dynamicRange[1] ? CONSTANT_DATA.YESTERDAY : CONSTANT_DATA.PAST_N_DAYS : CONSTANT_DATA.TODAY;
|
|
197
|
+
const rightPastNDays = 'number' == typeof value.dynamicRange[1] ? value.dynamicRange[1] : TIME_CONSTANTS.DEFAULT_RIGHT_PAST_DAYS;
|
|
198
|
+
set({
|
|
199
|
+
needTime,
|
|
200
|
+
timeRange,
|
|
201
|
+
tabActiveKey,
|
|
202
|
+
leftButtonActive,
|
|
203
|
+
leftPastNDays,
|
|
204
|
+
rightButtonActive,
|
|
205
|
+
rightPastNDays
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
calcTitle: ()=>{
|
|
209
|
+
const state = get();
|
|
210
|
+
let title = '';
|
|
211
|
+
const dateFormat = getDateFormat(state.needTime);
|
|
212
|
+
title = state.leftButtonActive === CONSTANT_DATA.SPECIFIC ? state.timeRange?.[0]?.format(dateFormat) ?? '' : isToday(state.timeRange?.[0]) ? '今日' : `过去 ${state.leftPastNDays} 天`;
|
|
213
|
+
if (state.rightButtonActive === CONSTANT_DATA.TODAY || isToday(state.timeRange?.[1])) title += ' - 今日';
|
|
214
|
+
else if (state.rightButtonActive === CONSTANT_DATA.YESTERDAY) title += ' - 昨日';
|
|
215
|
+
else title += ` - 过去 ${state.rightPastNDays} 天`;
|
|
216
|
+
return title;
|
|
217
|
+
},
|
|
218
|
+
calcReturnValues: ()=>{
|
|
219
|
+
const state = get();
|
|
220
|
+
if (state.timeRange?.[0] && state.timeRange?.[1]) {
|
|
221
|
+
const dateFormat = getDateFormat(state.needTime);
|
|
222
|
+
const todayStart = getTodayStart();
|
|
223
|
+
let startDiff = -1 * state.timeRange[0].startOf('day').diff(todayStart, 'day');
|
|
224
|
+
let endDiff = -1 * state.timeRange[1].startOf('day').diff(todayStart, 'day');
|
|
225
|
+
if (Object.is(startDiff, -0)) startDiff = 0;
|
|
226
|
+
if (Object.is(endDiff, -0)) endDiff = 0;
|
|
227
|
+
if (state.leftButtonActive === CONSTANT_DATA.SPECIFIC) startDiff = state.timeRange[0].format(dateFormat);
|
|
228
|
+
const startTime = state.needTime ? state.timeRange[0].format(DATE_FORMAT.TIME) : state.timeRange[0].startOf('day').format(DATE_FORMAT.TIME);
|
|
229
|
+
const endTime = state.needTime ? state.timeRange[1].format(DATE_FORMAT.TIME) : state.timeRange[1].endOf('day').format(DATE_FORMAT.TIME);
|
|
230
|
+
return {
|
|
231
|
+
date: [
|
|
232
|
+
state.timeRange[0].format(dateFormat),
|
|
233
|
+
state.timeRange[1].format(dateFormat)
|
|
234
|
+
],
|
|
235
|
+
dynamicRange: [
|
|
236
|
+
startDiff,
|
|
237
|
+
endDiff
|
|
238
|
+
],
|
|
239
|
+
time: [
|
|
240
|
+
startTime,
|
|
241
|
+
endTime
|
|
242
|
+
],
|
|
243
|
+
type: state.tabActiveKey === TAB_ACTIVE_KEY.DYNAMIC ? 'dynamic' : 'static'
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
date: [],
|
|
248
|
+
dynamicRange: [],
|
|
249
|
+
time: [],
|
|
250
|
+
type: 'static'
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}));
|
|
254
|
+
export { useSuperDateStore };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Dayjs } from 'dayjs';
|
|
2
|
+
export interface SuperDateReturnValues {
|
|
3
|
+
date: string[];
|
|
4
|
+
dynamicRange: (number | string)[];
|
|
5
|
+
time: string[];
|
|
6
|
+
type: 'dynamic' | 'static';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* SuperDate 组件 Props
|
|
10
|
+
*/
|
|
11
|
+
export interface SuperDateProps {
|
|
12
|
+
/** 受控模式:当前选中的日期范围 */
|
|
13
|
+
value?: SuperDateReturnValues;
|
|
14
|
+
/** 弹窗浮窗类名 */
|
|
15
|
+
popupClassName?: string;
|
|
16
|
+
/** 自定义类名 */
|
|
17
|
+
className?: string;
|
|
18
|
+
/** 是否需要确认按钮 */
|
|
19
|
+
needConfirm?: boolean;
|
|
20
|
+
/** 是否需要时分秒选择 */
|
|
21
|
+
needTime?: boolean;
|
|
22
|
+
/** 日期变化回调 */
|
|
23
|
+
onChange?: (value: SuperDateReturnValues) => void;
|
|
24
|
+
/** 面板打开关闭回调 */
|
|
25
|
+
onOpenChange?: (open: boolean) => void;
|
|
26
|
+
/** 日历清除变化回调 */
|
|
27
|
+
onCalendarChange?: (value: DateRangeValue) => void;
|
|
28
|
+
}
|
|
29
|
+
/** 日期范围值 */
|
|
30
|
+
export type DateRangeValue = [Dayjs | null, Dayjs | null] | null;
|
|
31
|
+
/** 动态时间左侧Button type */
|
|
32
|
+
export type LeftButtonActive = 'specific' | 'past';
|
|
33
|
+
/** 动态时间右侧Button type */
|
|
34
|
+
export type RightButtonActive = 'today' | 'yesterday' | 'pastNDays';
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Dayjs } from 'dayjs';
|
|
2
|
+
export declare const isToday: (date: Dayjs | null | undefined) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* 检测有没有时分秒
|
|
5
|
+
*/
|
|
6
|
+
export declare const checkHasTime: (date: Dayjs | null | undefined) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* 获取今天的开始时间(00:00:00)
|
|
9
|
+
*/
|
|
10
|
+
export declare const getTodayStart: () => Dayjs;
|
|
11
|
+
/**
|
|
12
|
+
* 设置日期为一天的结束时间(23:59:59)
|
|
13
|
+
*/
|
|
14
|
+
export declare const setEndOfDay: (date: Dayjs) => Dayjs;
|
|
15
|
+
/**
|
|
16
|
+
* 获取日期格式字符串(根据是否需要时间)
|
|
17
|
+
*/
|
|
18
|
+
export declare const getDateFormat: (needTime: boolean) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { DATE_FORMAT, TIME_CONSTANTS } from "./constant.js";
|
|
3
|
+
const isToday = (date)=>{
|
|
4
|
+
if (!date) return false;
|
|
5
|
+
return date.isSame(dayjs(), 'day');
|
|
6
|
+
};
|
|
7
|
+
const checkHasTime = (date)=>{
|
|
8
|
+
if (!date) return false;
|
|
9
|
+
return date.hour() > 0 || date.minute() > 0 || date.second() > 0;
|
|
10
|
+
};
|
|
11
|
+
const getTodayStart = ()=>dayjs().startOf('day');
|
|
12
|
+
const setEndOfDay = (date)=>date.hour(TIME_CONSTANTS.END_HOUR).minute(TIME_CONSTANTS.END_MINUTE).second(TIME_CONSTANTS.END_SECOND);
|
|
13
|
+
const getDateFormat = (needTime)=>needTime ? DATE_FORMAT.DATETIME : DATE_FORMAT.DATE;
|
|
14
|
+
export { checkHasTime, getDateFormat, getTodayStart, isToday, setEndOfDay };
|