Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
时间选择器
2019-11-14 07:46:48
7
0
0
admin
## 只能选今天或者今天以后的日期 ``` disabledDate = (current) => { return current && current < moment().startOf('day').subtract(0, 'days'); } ``` ## 只能选今天或者今天以后的小时 ``` disabledRangeTime = (_, type) => { const { form: { getFieldValue } } = this.props if (type === 'start') { const nowHours = moment().hours() const time = getFieldValue("time") if (time && moment(time[0].format("YYYY-MM-DD")).valueOf() <= moment(moment().format("YYYY-MM-DD")).valueOf()) { return { disabledHours: () => this.range(0, nowHours), }; } } } ``` ## 在关闭选择时间面板的时候判断是否小于(当前时间 + 10s) ``` onOpenChange = (status) => { const { form: { getFieldValue, setFields } } = this.props const time = getFieldValue("time") if (!status) { if (time && (moment(time[0]).valueOf() + 10000) < moment().valueOf()) { setFields({ time: { value: null, errors: [new Error("开始时间不能小于当前时间")] } }) } } } ``` ## render ``` render() { return ( ) } ``` ## 时间选中后前后30天禁用, 范围为30天, 今天以后不能选择 ``` pickerOptions: { disabledDate: (current, aa) => { let flag = false const { minDate, maxDate } = this.datePickObj if (minDate) { const dateRange = 30 flag = current < moment(minDate).subtract(dateRange, 'days') || current > moment(minDate).startOf('day').add(dateRange, 'days') if (maxDate) this.datePickObj = {} } // 今天以后不能选择 if (current.getTime() > Date.now()) { flag = true } return flag }, onPick: (obj) => { this.datePickObj = obj } } ```
Pre:
antd table使用总结
Next:
社区精选组件(富文本...)
0
likes
7
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.