当前位置: 首页 > news >正文

uniapp+vue3预约时间和日期

picker组件

预约时间和日期,不能选择过去的日期时间

<view class="whiteBox paddingBottom"><view class="title">预约上门时间</view><picker mode="date" :value="nowDate" @change="bindDateChange" fields="day"style="border-bottom: 1rpx solid #E7E7E7;" :start="minDate"><view class="row"><view class="label">日期选择</view><view class="value">{{nowDate ? nowDate : '请选择'}}</view></view></picker><picker mode="time" :value="nowTime" @change="onTime" :start="minTime"><view class="row"><view class="label">时间选择</view><view class="value">{{nowTime ? nowTime : '请选择'}}</view></view></picker>
</view>
<script setup>import {ref,reactive,shallowRef} from 'vue'import {onLoad,onShow,onReachBottom} from '@dcloudio/uni-app'import i from '@/libs/common/index.js'import api from '@/request/api.js'import throttle from '@/libs/function/throttle.js'import config from '@/libs/config/index.js'import {userStore} from '@/store/userStore.js'import {commonStore} from '@/store/commonStore.js'const user = userStore()const common = commonStore()const nowDate = ref(getDate({format: true})); // 当前日期const nowTime = ref(getTime({format: true})); // 当前时间const minDate = ref(getDate({format: true})); // 最小可选日期const minTime = ref(getTime({format: true})); // 最小可选时间function getTime({format} = {format: false}) {const date = new Date();let hours = date.getHours().toString().padStart(2, '0');let minutes = date.getMinutes().toString().padStart(2, '0');return format ? `${hours}:${minutes}` : date;}function getDate({format} = {format: false}) {const d = new Date();const year = d.getFullYear();const month = String(d.getMonth() + 1).padStart(2, '0');const day = String(d.getDate()).padStart(2, '0');return format ? `${year}-${month}-${day}` : d;}function bindDateChange(e) {const selectedDate = new Date(e.detail.value);selectedDate.setHours(0, 0, 0, 0); // 将选择的日期设置为当天的开始时间const today = new Date();today.setHours(0, 0, 0, 0);if (selectedDate.getTime() === today.getTime()) {// 选择的是今天,设置时间选择器的起始时间为当前时间,并重置当前时间为当前时间const currentTime = getTime({format: true});minTime.value = currentTime;nowTime.value = currentTime;} else {// 选择的是未来日期,时间选择器不限制,设置为00:00,并重置当前时间为00:00minTime.value = '00:00';nowTime.value = '00:00';}nowDate.value = e.detail.value;}function onTime(e) {const selectedTime = e.detail.value;nowTime.value = selectedTime;}</script>
.whiteBox {background: #FFFFFF;box-shadow: 0rpx 5rpx 15rpx 10rpx rgba(80, 80, 80, 0.0322);border-radius: 16rpx;margin: 0 30rpx 30rpx;padding-bottom: 40rpx;.title {padding-top: 30rpx;padding-left: 30rpx;font-weight: bold;font-size: 30rpx;color: #3D3D3D;}.row {display: flex;justify-content: space-between;align-items: center;border-bottom: 1rpx solid #E4E4E4;margin: 0 30rpx;padding: 30rpx 0;.label {font-size: 28rpx;color: #606266;}.value {font-size: 28rpx;color: #3D3D3D;}}.row:last-child {border: none;}
}.paddingBottom {padding-bottom: 0;
}
http://www.lryc.cn/news/594997.html

相关文章:

  • 布局AI +文化新赛道,浙江省文化产业投资集团赴景联文科技调研交流
  • 算法-比较排序
  • 广播(Broadcast)和组播(Multicast)对比
  • 简单讲解HTTPS如何保证安全性和可靠性
  • https正向代理 GoProxy
  • 计算机发展史:电子管时代的辉煌与局限
  • ubuntu远程桌面不好使
  • Consumer<T>
  • 华为云Stack交付流程
  • cs336 Lecture2
  • iOS打开开发者模式
  • Django Ninja
  • WebkitSpeechRecognition 语音识别
  • 苹果最新系统iOS 17的调试和适配方法 - Xcode 14.3.1 真机调试指南
  • Django实战:基于Django和openpyxl实现Excel导入导出功能
  • 笼子在寻找一只鸟:解读生活的隐形陷阱
  • 第11天 |openGauss逻辑结构:数据库管理
  • Redis的五大基本数据类型
  • Elasticsearch、Solr 与 OpenSearch 搜索引擎方案对比分析及选型建议
  • 神经网络——非线性激活
  • Rk3568驱动开发_非阻塞IO_16
  • Linux下SPI设备驱动开发
  • WPF实现加载初始页面后跳转到主界面并销毁初始页面资源
  • docker磁盘空间不足解决办法
  • Linux驱动15 --- buildroot杂项驱动开发方法
  • windows内核研究(驱动开发-多核同步之临界区和自旋锁)
  • 【Linux内核】Linux驱动开发
  • 智慧场景:定制开发开源AI智能名片S2B2C商城小程序赋能零售新体验
  • 莘默曹工-Cd Automation半导体调功器 RS2300-
  • Mac安装Typescript报错