modify(date-picker&time-picker): modify disabledTime documation &fix select the hour of timepicker is not correct & fix disabledTime of dateTimeRange

This commit is contained in:
songwanli2025@163.com 2019-11-29 15:24:37 +08:00
parent 8b104563be
commit da45bc7450
10 changed files with 140 additions and 3 deletions

View File

@ -21,6 +21,7 @@ export default {
methods: {
disabledTime (current) {
return (current >= 1574092800000) && (current < 1576771200000)
}
}
}

View File

@ -5,7 +5,6 @@
type="datetime"
:disabledTime= "disabledTime"
/>
{{timestamp}}
<n-date-picker v-model="timestamp2" type="datetime" />
```
```js

View File

@ -0,0 +1,48 @@
# Disabled Time
```html
<n-date-picker
v-model="timestamp1"
type="date"
:disabledTime= "disabledTime"
/>
<n-date-picker
v-model="timestamp2"
type="datetime"
:disabledTime= "disabledTime"
/>
<n-date-picker
v-model="timestamp3"
type="daterange"
:disabledTime= "disabledTime"
/>
{{timestamp3}}
<n-date-picker
v-model="timestamp4"
type="datetimerange"
:disabledTime= "disabledTime"
/>
```
```js
export default {
data () {
return {
timestamp1: null,
timestamp2: null,
timestamp3: null,
timestamp4: null,
}
},
methods: {
disabledTime (current) {
return current > 1573552182000 && current < 1573811382000
// Tue Nov 12 2019 17:49:42 GMT+0800 (China Standard Time) -
// Fri Nov 15 2019 17:49:42 GMT+0800 (China Standard Time)
}
}
}
```
```css
.n-date-picker {
margin: 0 12px 8px 0;
}
```

View File

@ -5,6 +5,7 @@ datetime
daterange
datetimerange
disabled
disabledTime
actions
events
```

View File

@ -6,7 +6,6 @@
:disabledMinutes="disabledMinutes"
:disabledSeconds="disabledSeconds"
/>
{{time0}}
<n-time-picker v-model="time1" />
```
```js

View File

@ -0,0 +1,40 @@
# Disabled Time
```html
<n-time-picker
v-model="time0"
:disabledHours="disabledHours"
:disabledMinutes="disabledMinutes"
:disabledSeconds="disabledSeconds"
/>
```
```js
export default {
data () {
return {
time0: null,
time1: 1563937380000
}
},
methods: {
disabledHours (hour) {
return hour>13 && hour<16
},
disabledMinutes (minute, selectedHour) {
if(Number(selectedHour) === 17) {
return minute > 13 && minute < 40
}
},
disabledSeconds (second, selectedHour, selectedMinute) {
if(Number(selectedHour) === 17 && Number(selectedMinute) === 10) {
return second > 13 && second < 40
}
}
}
}
```
```css
.n-time-picker {
margin: 0 12px 8px 0;
}
```

View File

@ -1,4 +1,5 @@
# Time Picker
```demo
basic
disabledTime
```

View File

@ -25,6 +25,9 @@
position-mode="absolute"
class="n-date-picker-panel__time-input"
:value="startTimeValue"
:disabled-hours="disabledHours(startTimeValue)"
:disabled-minutes="disabledMinutes(startTimeValue)"
:disabled-seconds="disabledSeconds(startTimeValue)"
stop-selector-bubble
@input="handleStartTimePickerInput"
/>
@ -45,6 +48,9 @@
position-mode="absolute"
class="n-date-picker-panel__time-input"
:value="endTimeValue"
:disabled-hours="disabledHours(endTimeValue)"
:disabled-minutes="disabledMinutes(endTimeValue)"
:disabled-seconds="disabledSeconds(endTimeValue)"
stop-selector-bubble
@input="handleEndTimePickerInput"
/>

View File

@ -7,6 +7,12 @@ import getMonth from 'date-fns/getMonth'
import startOfMonth from 'date-fns/startOfMonth'
import isValid from 'date-fns/isValid'
import { dateArray } from '../../../../utils/dateUtils'
import startOfSecond from 'date-fns/startOfSecond'
import startOfMinute from 'date-fns/startOfMinute'
import startOfHour from 'date-fns/startOfHour'
import setHours from 'date-fns/setHours'
import setMinutes from 'date-fns/setMinutes'
import setSeconds from 'date-fns/setSeconds'
import commonCalendarMixin from './commonCalendarMixin'
@ -253,6 +259,42 @@ export default {
endCalendarPrevMonth () {
this.endCalendarDateTime = addMonths(this.endCalendarDateTime, -1)
this.adjustCalendarTimes(false)
},
disabledHours (value) {
let self = this
return function (hour) {
let newVal = null
if (value === null) {
newVal = getTime(startOfHour(new Date()))
} else {
newVal = getTime(setHours(value, hour))
}
return self.disabledTime(newVal)
}
},
disabledMinutes (value) {
let self = this
return function (minute) {
let newVal = null
if (value === null) {
newVal = getTime(startOfMinute(new Date()))
} else {
newVal = getTime(setMinutes(value, minute))
}
return self.disabledTime(newVal)
}
},
disabledSeconds (value) {
let self = this
return function (second) {
let newVal = null
if (value === null) {
newVal = getTime(startOfSecond(new Date()))
} else {
newVal = getTime(setSeconds(value, second))
}
return self.disabledTime(newVal)
}
}
}
}

View File

@ -320,7 +320,7 @@ export default {
return
}
if (this.value === null) {
this.$emit('input', getTime(startOfHour(new Date())))
this.$emit('input', getTime(setHours(startOfHour(new Date()), hour)))
} else {
this.$emit('input', getTime(setHours(this.value, hour)))
}