前端-a-date-picker如何设置禁选时间段

想要做到如图所示的效果,代码如下:

第一个是只能选择某一天,第二个是只能选择某一个时间段

<a-date-picker
                  v-model:value="record.onTimeStr"
                  :show-time="{ format: 'HH:mm' }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :disabled="record.onTimeStatus === 'delivered'"
                  :disabled-date="disableDate"
                />

    disableDate(current) {
      // console.log('time', this.where.workDateStr, current);
      const res = dayjs(this.where.workDateStr).toISOString();
      const date = dayjs();
      const day = date.date();
      const year = date.year();
      const month = date.month();
      return current.isBefore(res, 'day') || current.isAfter(res, 'day');
      // return current.date() !== day || current.year() !== year || current.month() !== month;
    },
<template #time2="{ record }">
              <a-space
                ><a-date-picker
                  v-model:value="record.offTimeStr"
                  :show-time="{ format: 'HH:mm' }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :disabled="record.offTimeStatus === 'delivered'"
                  :disabled-date="current => disableDate2(current, record)"
                />
              </a-space>
            </template>

disableDate2(current) {
      // const today = dayjs();
      // const tomorrow = today.add(1, 'day');
      // return current.isBefore(today, 'day') || current.isAfter(tomorrow, 'day');
      const res = dayjs(this.where.workDateStr);
      const tomorrow = res.add(1, 'day');
      return current.isBefore(res, 'day') || current.isAfter(tomorrow, 'day');
    },

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是react-native-common-date-picker的介绍: react-native-common-date-picker是一个React Native的日期择器组件,支持年月日格式的日期择。该组件适用于iOS和Android平台,并且可以自定义样式和参数。 使用react-native-common-date-picker,你可以轻松地在你的React Native应用程序中添加日期择器功能。该组件提供了多种可参数,例如日期格式、最小日期、最大日期、默认日期等等,以便你根据自己的需求进行自定义。 以下是一个使用react-native-common-date-picker的例子: ```javascript import React, { useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import DatePicker from 'react-native-common-date-picker'; const App = () => { const [date, setDate] = useState(new Date()); const handleDateChange = (newDate) => { setDate(newDate); }; return ( <View> <TouchableOpacity onPress={() => this.datePicker.onPressDate()}> <Text>{date.toLocaleDateString()}</Text> </TouchableOpacity> <DatePicker ref={(picker) => { this.datePicker = picker; }} style={{ width: 0, height: 0 }} mode="date" date={date} onDateChange={handleDateChange} /> </View> ); }; export default App; ``` 在上面的例子中,我们首先导入了react-native-common-date-picker组件,并在组件中使用useState钩子来管理日期状态。然后,我们在TouchableOpacity组件中渲染了当前日期,并在用户点击该组件时打开了日期择器。最后,我们将DatePicker组件添加到了视图中,并将其隐藏在了一个看不见的位置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值