From a77a6bef534d867233da8b1c1259b638a0d6ffc9 Mon Sep 17 00:00:00 2001 From: zhouyun1 Date: Mon, 28 Nov 2022 16:39:15 +0800 Subject: [PATCH] fix(date-picker): #2328 --- components/date-picker/BasePicker.jsx | 11 +++- components/date-picker/components/Time.jsx | 59 +++++++++++++++------- package-lock.json | 2 +- package.json | 5 +- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/components/date-picker/BasePicker.jsx b/components/date-picker/BasePicker.jsx index 262923368..8e647eac1 100644 --- a/components/date-picker/BasePicker.jsx +++ b/components/date-picker/BasePicker.jsx @@ -98,7 +98,16 @@ const BasePicker = ({ const inputChangeEvent = (val, dir) => { if (val.isValid()) { const oData = _.cloneDeep(outDate) - oData[dir] = val + + // 如果是范围的修改,则校准下时间范围的值 + if (outDate.length === 2) { + if ((dir === 0 && moment(val) < moment(outDate[1])) || (dir === 1 && moment(val) > moment(outDate[0]))) { + oData[dir] = val + } + } else { + oData[dir] = val + } + changeOutDate(oData) } } diff --git a/components/date-picker/components/Time.jsx b/components/date-picker/components/Time.jsx index 25cffa689..36701896c 100644 --- a/components/date-picker/components/Time.jsx +++ b/components/date-picker/components/Time.jsx @@ -33,26 +33,51 @@ const Time = ({ date, onChange, timeRangePanelType, startDate, currentDate }) => if (timeRangePanelType === 'right') { const { hour, minute, second } = deconstructDate(startDate) const { hour: endHour, minute: endMinute } = date ? deconstructDate(date) : deconstructDate(new Date()) + const dateDiff = moment(date).diff(moment(startDate), 'days') + const hourDiff = moment(date).diff(moment(startDate), 'hour') + const minuteDiff = moment(date).diff(moment(startDate), 'minutes') - isDisabled = type === 'hour' && hour > i - if (type === 'minute') { - if (endHour === hour) { - isDisabled = minute > i - } - if (endHour < hour) { - isDisabled = true - } + // 不在同一天 + if (dateDiff !== 0) { + isDisabled = dateDiff < 0 } - - if (type === 'second') { - if (endHour === hour) { - isDisabled = endMinute === minute && second > i - if (endMinute < minute) { - isDisabled = true + // 在同一天,则比较小时 + else { + if (type === 'hour') { + isDisabled = hour > i + } else { + // 不在同一小时 + if (hourDiff !== 0) { + isDisabled = hourDiff < 0 + } + // 在同一小时,则比较分钟 + else { + if (type === 'minute') { + if (endHour === hour) { + isDisabled = minute > i + } + if (endHour < hour) { + isDisabled = true + } + } else { + // 不在同一分 + if (minuteDiff !== 0) { + isDisabled = minuteDiff < 0 + } + // 在同一分钟,则比较秒 + else { + if (endHour === hour) { + isDisabled = endMinute === minute && second > i + if (endMinute < minute) { + isDisabled = true + } + } + if (endHour < hour) { + isDisabled = true + } + } + } } - } - if (endHour < hour) { - isDisabled = true } } } diff --git a/package-lock.json b/package-lock.json index 85eb54a1f..1fc1e28ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@hi-ui/hiui", - "version": "3.9.3", + "version": "3.9.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index be6f85ca2..dfa0657c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hi-ui/hiui", - "version": "3.9.4-beta.0", + "version": "3.9.4", "description": "HIUI for React", "scripts": { "test": "node_modules/.bin/standard && node_modules/.bin/stylelint --config .stylelintrc 'components/**/*.scss'", @@ -48,6 +48,9 @@ "es/lib/*", "es/_util/*" ], + "engines": { + "node": "~11.0.0" + }, "peerDependencies": { "react": ">=16.13.0", "react-dom": ">=16.13.0"