You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/date-picker/demo/disabled-date.md

79 lines
2.0 KiB

7 years ago
<cn>
#### 不可选择日期和时间
7 years ago
可用 `disabledDate``disabledTime` 分别禁止选择部分日期和时间,其中 `disabledTime` 需要和 `showTime` 一起使用。
</cn>
7 years ago
<us>
#### Disabled Date & Time
7 years ago
Disabled part of dates and time by `disabledDate` and `disabledTime` respectively, and `disabledTime` only works with `showTime`.
</us>
7 years ago
```html
<template>
7 years ago
<div>
<a-date-picker
7 years ago
format="YYYY-MM-DD HH:mm:ss"
:disabledDate="disabledDate"
:disabledTime="disabledDateTime"
:showTime="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
7 years ago
/>
<br />
<a-month-picker :disabledDate="disabledDate" placeholder="Select month" />
7 years ago
<br />
<a-range-picker
:disabledDate="disabledDate"
:disabledTime="disabledRangeTime"
:showTime="{
hideDisabledOptions: true,
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('11:59:59', 'HH:mm:ss')]
}"
7 years ago
format="YYYY-MM-DD HH:mm:ss"
/>
</div>
</template>
<script>
import moment from 'moment';
export default {
methods: {
moment,
range(start, end) {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
},
disabledDate(current) {
// Can not select days before today and today
return current && current < moment().endOf('day');
},
disabledDateTime() {
return {
disabledHours: () => this.range(0, 24).splice(4, 20),
disabledMinutes: () => this.range(30, 60),
disabledSeconds: () => [55, 56],
};
},
disabledRangeTime(_, type) {
if (type === 'start') {
return {
disabledHours: () => this.range(0, 60).splice(4, 20),
disabledMinutes: () => this.range(30, 60),
disabledSeconds: () => [55, 56],
};
}
return {
disabledHours: () => this.range(0, 60).splice(20, 4),
disabledMinutes: () => this.range(0, 31),
disabledSeconds: () => [55, 56],
};
},
}
}
</script>
```