效果图

如何使用


<template><view><button @click="pickerTime(0)">预约时间0</button><button @click="pickerTime(1)">预约时间1</button><button @click="pickerTime(2)">预约时间2</button><button @click="pickerTime(2)">预约时间3</button><hbxwTimepicker v-model:isShow="showTimePicker0" :isBtn="false" @change="pickerChange"></hbxwTimepicker><hbxwTimepicker v-model:isShow="showTimePicker1" :maxHour="16" :isBtn="false" @change="pickerChange"></hbxwTimepicker><hbxwTimepicker v-model:isShow="showTimePicker2" :dayRange="7" :minHour="8" :maxHour="20" @change="pickerChange"></hbxwTimepicker><hbxwTimepicker v-model:isShow="showTimePicker3" @change="pickerChange"><template #title="{title}"><view>{{title}}</view></template><template #btn="{result}"><button style="font-size: 24rpx;">{{result}}</button></template></hbxwTimepicker></view>
</template><script>import hbxwTimepicker from "../hbxwTimepicker.vue";export default {components: {hbxwTimepicker},data() {return {showTimePicker0: false,showTimePicker1: false,showTimePicker2: false,showTimePicker3: false}},methods: {pickerTime(index) {this['showTimePicker'+index] = true;},pickerChange(result) {console.log('---- pickerChange ----:',  result);}}}
</script><style></style>

组件内容

<template><view class="hbxw-timepicker" :class="{'hbxw-timepicker-ani': isAni}":style="{'z-index': zIndex, '--opacity': maskOpacity}"v-if="isShow"><view class="hbxw-timepicker-mask" @click="close"></view><view class="hbxw-timepicker-main" :class="{'hbxw-timepicker-main-ani': isAni}"><!-- 标题 --><view class="hbxw-timepicker-title"><slot name="title" :title="title" :subTitle="subTitle"><view class="hbxw-timepicker-title-main">{{title}}</view><view class="hbxw-timepicker-title-subtitle">{{subTitle}}</view></slot><image :src="closeImgSrc" class="hbxw-timepicker-close" @click="close"></image></view><!-- 主内容,日期和时间选择区 --><view class="hbxw-timepicker-content"><view class="hbxw-timepicker-day"><view class="hbxw-timepicker-day-item":class="{'hbxw-timepicker-day-item-active': dayActiveIndex === index}"v-for="(day, index) in days":key="index"@click="toggleDay(index)">{{anotherNames[index] ? anotherNames[index].replace('month', day.month).replace('day', day.day) : day.value}}</view></view><view class="hbxw-timepicker-time"><viewv-if="hours.length > 0"class="hbxw-timepicker-time-item" v-for="(hour, index) in hours" :key="index" :class="{'hbxw-timepicker-time-item-active': hourActiveIndex === index}"@click="toggleHour(index)"><text class="hbxw-timepicker-time-val">{{hour.hoursStr}}</text><view class="hbxw-timepicker-time-icon"><image :src="selectImgSrc" class="hbxw-timepicker-time-img"></image></view></view><view class="hbxw-timepicker-notime" v-else><text class="hbxw-timerpicker-nodata">{{noDateTips}}</text></view></view></view><!-- 底部按钮 --><slot name="btn" :result="result" v-if="isBtn"><view class="hbxw-timerpicker-btn-wrap"><view class="hbxw-timerpicker-sure" @click="sure" v-if="btnStr">{{btnStr}}</view></view></slot></view></view>
</template>
<script>
//   import guanbi from '../../static/guanbi.png'
//   import gougou from '../../static/gougou.png'export default {props: {isShow: {type: Boolean,default: false},title: {type: String,default: '请选择快递上门取件时间'},subTitle: {type: String,default: '快递1小时内上门取件,请自行做好数据备份'},// 是否显示1小时内isFast: {type: Boolean,default: true},// 日期别名,用于一些特殊场景,如需要显示今天明天后天...anotherNames: {type: Array,default() {return ['今天','明天','后天']}},dayRange: {type: Number,default: 3},minHour: {type: Number,default: 9},maxHour: {type: Number,default: 19},isBtn: {type: Boolean,default: true},isAni: {type: Boolean,default: true},zIndex: {type: Number,default: 9999},maskOpacity: {type: Number,default: .76},noDateTips: {type: String,default: '今日已暂无服务'},isTwo: {type: Boolean,default: true},isAutoClose: {type: Boolean,default: false},emitEventName: {type: String,default: 'timepicker'},closeImgSrc: {type: String,// default: guanbi// default: this.$imgBaseWebUrl+'/image/guanbi.png',default:''},selectImgSrc: {type: String,// default: gougou// default: this.$imgBaseWebUrl+'/image/gougou.png'default:''},},model: {prop: 'isShow',event: 'update'},watch: {isShow: {handler(newVal, oldVal) {if(newVal) {this.init();}},immediate: true}},mounted() {uni.$on(this.emitEventName, (type) => {this[type] && this[type]();})},// #ifdef VUE3unmounted() {uni.$off(this.emitEventName);},// #endif// #ifdef VUE2destroyed() {uni.$off(this.emitEventName);},// #endifdata() {return {days: [],dayActiveIndex: 0,hourActiveIndex: 0,}},computed: {// 可选时间列表hours() {let nowDate = new Date();let hoursResult = [];let firstHour = this.minHour;if (this.dayActiveIndex === 0) {firstHour = nowDate.getHours() > firstHour ? nowDate.getHours() : firstHour;if (firstHour >= this.maxHour) {return [];}if (this.isFast) {hoursResult.push({start: firstHour,end: firstHour,hoursStr: '1小时内'})firstHour = firstHour + 1;}}for(let i = firstHour; i<this.maxHour; i++) {hoursResult.push({start: i,end: i+1,hoursStr: `${this.isTwo ? ('0'+i).slice(-2) : i}:00~${this.isTwo ? ('0'+(i+1)).slice(-2) : i+1}:00`})}return hoursResult;},// 当前选中结果result() {if (this.days.length === 0 || this.hours.length === 0) {return null;}const {year,month,day} = this.days[this.dayActiveIndex];const {start, end, hoursStr} = this.hours[this.hourActiveIndex] || {};// console.log('---- result ----:',  year,month,day, start, end, hoursStr);return {year: year,month: this.isTwo ? ('0'+month).slice(-2) : month,day: this.isTwo ? ('0'+day).slice(-2) : day,hourStart: this.isTwo ? ('0'+start).slice(-2) : start,hourEnd: this.isTwo ? ('0'+end).slice(-2) : end,hoursStr: hoursStr,anotherName: this.anotherNames[this.dayActiveIndex] || ''}},btnStr() {let hoursStr = '';if (!this.result) {return '待选择';}if (this.result.hourStart === this.result.hourEnd) {hoursStr = `${this.result.hourStart}:00(${this.result.hoursStr})`} else {hoursStr = this.result.hoursStr;}return `预约${this.result.year}年${this.result.month}月${this.result.day}日 ${hoursStr}`}},methods: {// 插件初如化init() {let firstDate = new Date();this.days = [];for(let i = 0; i<this.dayRange; i++) {const dateItem = new Date(firstDate.setDate(firstDate.getDate() + (i === 0 ? 0 : 1)));this.days.push({year: dateItem.getFullYear(),month: dateItem.getMonth() + 1,day: dateItem.getDate(),value: `${dateItem.getMonth() + 1}月${dateItem.getDate()}日`})// console.log('---- dateItem ----:init',  dateItem, dateItem.getFullYear(),dateItem.getMonth() + 1,dateItem.getDate());}// console.log('---- hbxw-timepicker ----:',  this.days);},// 切换月份toggleDay(index) {this.dayActiveIndex = index;this.hourActiveIndex = 0;this.$nextTick(() => {this.$emit('change', {result: this.result,form: 'day'});});},// 切换时间toggleHour(index) {this.hourActiveIndex = index;this.$nextTick(() => {this.$emit('change', {result: this.result,form: 'hour'});if (this.isAutoClose) {this.$emit('update:isShow', false);}});},// 确认按钮sure() {this.$emit('change', {result: this.result,form: 'sure'});},// 关闭弹窗方法close() {this.$emit('change', {result: this.result,form: 'close'});this.$emit('update:isShow', false);}}}
</script>
<style lang="scss" scoped>@keyframes showAni {0%{opacity: 0;transform: translateY(40%);}100%{transform: translateY(0);opacity: 1;}}.hbxw-timepicker{width: 100%;height: 100%;position: fixed;top:0;left:0;right:0;bottom: 0;z-index: 9999}.hbxw-timepicker-mask{// background-color: rgba(0,0,0, var(--opacity));background-color: rgba(0,0,0, 0.3);position: absolute;top:0;left:0;right:0;bottom: 0;z-index: 9998;}.hbxw-timepicker-main{position: absolute;left:0;bottom: 0;z-index: 9999;width: 100%;display: flex;flex-direction: column;align-items: center;border-radius: 40rpx 40rpx 0 0;// background-color: #F7F9FA;background-color: white;transform-origin: center bottom;opacity: 0;&.hbxw-timepicker-main-ani{opacity: 0;}}.hbxw-timepicker-ani{.hbxw-timepicker-main-ani{animation: showAni .3s linear 0.1s 1 forwards;}}.hbxw-timepicker-title{width: 100%;display: flex;flex-direction: column;position: relative;padding: 39rpx 32rpx 27rpx 32rpx;box-sizing: border-box;border-bottom: 1px solid #DCDFE0;.hbxw-timepicker-title-main{font-size: 32rpx;font-weight: bold;line-height: 54rpx;color: #000;}.hbxw-timepicker-title-subtitle{font-size: 25rpx;line-height:48rpx;color: #000;}.hbxw-timepicker-close{width: 24rpx;height: 24rpx;position: absolute;top: 27rpx;right: 27rpx;}}.hbxw-timepicker-content{display: flex;flex-direction: row;width: 100%;border-radius: 40rpx;height: 740rpx;overflow: hidden;background-color: white;}.hbxw-timerpicker-btn-wrap{width: 100%;height: 160rpx;display: flex;justify-content: center;align-items: center;box-shadow: 0px -10rpx 36rpx 0px rgba(165,165,165,0.12);background-color: white;}.hbxw-timerpicker-sure{width: 686rpx;height: 100rpx;background-color: #AAF24E;border-radius: 50rpx;text-align: center;font-size: 32rpx;line-height:100rpx; font-weight: bold;color: #000;}.hbxw-timepicker-day{width: 200rpx;height: 100%;overflow-y: auto;background-color: #F7F9FA;.hbxw-timepicker-day-item{width: 100%;height: 110rpx;font-size: 26rpx;text-align: center;line-height: 110rpx;box-sizing: border-box;border-bottom: 1px solid #DCDFE0;color: #737E85;&:nth-last-of-type(1){border-bottom-color: transparent;}}.hbxw-timepicker-day-item-active{font-weight: bold;border-bottom: 1px solid white;background-color: white;color: #000000;}}.hbxw-timepicker-time{flex: 1;padding:0 32rpx;height: 100%;overflow-y: auto;.hbxw-timepicker-time-item{height: 110rpx;flex: none;box-sizing: border-box;width: 100%;display: flex;flex-direction: row;justify-content: space-between;align-items: center;border-bottom: 1px solid #EBEDF0;}.hbxw-timepicker-time-item-active{.hbxw-timepicker-time-val{color:#549204;}.hbxw-timepicker-time-icon{background-color: #AAF24E;.hbxw-timepicker-time-img{opacity: 1;}}}.hbxw-timepicker-time-val{font-size: 28rpx;color: #000;}.hbxw-timepicker-time-icon{width: 32rpx;height: 32rpx;box-sizing: border-box;border-radius: 50%;display: flex;flex-direction: row;justify-content: center;align-items: center;border:1px solid #A2A4A6;.hbxw-timepicker-time-img{width: 22rpx;height: 22rpx;opacity: 0;}}}.hbxw-timepicker-notime{width: 100%;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: center;}.hbxw-timerpicker-nodata{font-size: 24rpx;color:#737E85;}
</style>

组件内的默认图片,开启解除注释部分,默认没有,不会报错

js逻辑判断

pickerChange(result) {console.log('---- pickerChange ----:',  result);// console.log('1111')if(result.form=='close'){console.log('222')this.showTimePicker2=!this.showTimePicker2;}if(result.form=='sure'){this.selectedOption=result.result.year+"-"+result.result.month+"-"+result.result.day;if(result.result.hourStart==result.result.hourEnd){this.selectedOption=this.selectedOption+" "+result.result.hourStart+":00"+"~"+(Number(result.result.hourEnd)+1)+":00";}else{this.selectedOption=this.selectedOption+" "+result.result.hourStart+":00"+"~"+result.result.hourEnd+":00";}this.showTimePicker2=!this.showTimePicker2;console.log("888888888",result,this.selectedOption)}},

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/92215.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/92215.shtml
英文地址,请注明出处:http://en.pswp.cn/pingmian/92215.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 开发 - Service、Camera、Layout Design 自定义设备类型和大小

一、Service 启动 1、基本介绍 &#xff08;1&#xff09;startService()其他组件通过调用 startService() 启动 Service 后&#xff0c;Service 可在后台无限期运行&#xff0c;即使启动 Service 的组件被销毁也不受影响&#xff0c;一般情况下 startService() 是执行单一操作…

Qwen Image:开源中文渲染SOTA,重塑文生图技术边界

1. Qwen Image的技术定位与行业痛点1.1 文本渲染&#xff1a;文生图领域的长期技术瓶颈传统文生图模型在图像美学与真实感优化上已取得显著进展&#xff0c;但多语言文本渲染始终是行业难以突破的瓶颈。主流模型在处理中文等非字母语言时&#xff0c;常出现字符断裂、布局错位、…

Docker入门教程:在腾讯云轻量服务器上部署你的第一个容器化应用 (2025)

更多云服务器知识&#xff0c;尽在hostol.com“在我电脑上明明是好的啊&#xff01;”这句话&#xff0c;是不是堪称程序员“甩锅”排行榜第一名的金句&#xff1f;当你辛辛苦苦开发完一个应用&#xff0c;把它交给同事或者部署到服务器上时&#xff0c;却发现因为它依赖的某个…

DevOps平台结合Gradle实现打包流水线

在现代软件开发中,持续集成与持续交付(CI/CD)已成为团队提速、降本增效的核心实践。Gradle作为强大的自动化构建工具,常被用于Android与Java项目的构建打包任务。而将Gradle集成进企业的DevOps平台中,不仅可以标准化构建过程,还能自动化打包、测试、发布的全流程,大幅提…

Node.js 操作 MySQL

目录 一、什么是 MySQL&#xff1f; 二、MySQL 的功能概览 三、MySQL 的安装与启动 安装 MySQL 启动服务 四、Node.js 如何连接 MySQL&#xff1f; 使用 mysql2 模块&#xff08;推荐&#xff09; 建立连接 五、创建数据表和插入数据&#xff08;SQL 初始化&#xff09…

解锁高效敏捷:2025年Scrum项目管理工具的核心应用解析

一、为什么Scrum团队需要专业项目管理工具&#xff1f;在敏捷开发实践中&#xff0c;Scrum框架虽然提供了基础的工作流程&#xff0c;但缺乏对任务细粒度管理的支持。传统白板或简单看板工具往往无法满足现代敏捷团队的需求&#xff0c;导致&#xff1a;冲刺规划混乱&#xff1…

途游大数据面试题及参考答案

Java 的反射机制是什么?主要应用在哪些场景? Java的反射机制是指程序在运行时,能够获取自身类的信息(如类名、属性、方法、构造器等),并动态操作这些信息的能力。正常情况下,Java代码编译时类型已确定,而反射打破了这种编译期约束,让程序在运行时灵活操作类和对象。 …

贪心+矩阵算法

贪心算法贪心的本质是&#xff1a;选择每一阶段的局部最优&#xff0c;从而达到全局最优做题的时候&#xff0c;只要想清楚 局部最优 是什么&#xff0c;如果推导出全局最优&#xff0c;其实就够了。买卖股票的最佳实际思路&#xff1a;如果第i天卖出股票&#xff0c;则最大利润…

STM32U5 周期性异常复位问题分析

关键字&#xff1a; Option Bytes, IDWG 1. 问题背景 客户反馈使用 NUCLEO_STM32U575 进行评估时&#xff0c;发现板子烧录完程序后&#xff0c;能看到指示程序运行的 LED 灯正常点亮&#xff0c;但是程序跑不起来。仔细观察 LED 指示灯&#xff0c;并不是常亮而是出现周期性…

RedisBloom使用

安装RedisBloom模块&#xff0c;从git获取对应的原码&#xff0c;make生成.so文件&#xff0c;挂载.so文件&#xff0c;启动redis docker run --name test-redis -v /iothub/test-redis/data:/data -v /iothub/test-redis/modules:/modules -p 6378:6379 -d redis:4.0.10 redis…

ADC、Flash、SPI、watchdog

ADCADC(Analog-to-Digital Converter), 即模拟信号 - 数字信号转换器在STM32F103C8T6中, 同样具有ADC功能.以我们的芯片为例, 也存在2个片上外设ADC, 即ADC1和ADC2, 这两个ADC片上外设都挂载在APB2总线上.我们的ADC片上外设, 是一种具有12位逐次逼近型ADC,ADC转换的本质是不断的…

冷库设备远程监控物联网+省电节能解决方案

随着生鲜电商、医药冷链、跨境物流等行业的爆发式增长&#xff0c;我国冷库容量激增&#xff0c;但传统冷库管理模式正面临严峻挑战。据统计&#xff0c;国内冷链运输损耗率高达12%-15%&#xff0c;其中因温度失控导致的货损占比超60%。在某医药企业冷库事故中&#xff0c;因制…

如何开发一个运行在windows系统服务器上的服务

第一步&#xff1a;vs2022创建一个windows服务项目第二步&#xff1a;从工具箱拖拽出一个timer第三步&#xff1a;按下图所示进入&#xff0c;开始编辑业务逻辑下面给个例子using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; …

本地组策略编辑器无法打开(gpedit.msc命令异常)

一、本地组策略编辑器打开方式1、直接搜索打开&#xff08;1&#xff09;在搜索栏中直接输入以下内容进行搜索本地组策略编辑器&#xff08;2&#xff09;搜索到后直接点击打开即可&#xff08;但是一部分同志无法搜索到&#xff0c;搜索到的内容基本都是网页信息而非本地系统的…

kafka部署集群模式

Kafka部署&#xff08;3.7&#xff09; 生产环境推荐的kafka部署方式为operator方式部署&#xff0c;Strimzi是目前最主流的operator方案。集群数据量较小的话&#xff0c;可以采用NFS共享存储&#xff0c;数据量较大的话可使用local pv存储 部署operator operator部署方式为he…

C语言中级_动态内存分配、指针和常量、各种指针类型、指针和数组、函数指针

0、前言&#xff1a; 动态内存分配是一个重要概念&#xff0c;要和静态数组对比着学习&#xff1b;指针和数组搭配在一起&#xff0c;让指针理解的难度上了一个台阶&#xff0c;尤其是二维数组搭配指针&#xff0c;要获取数组的值&#xff0c;什么时候“取地址”&#xff0c;什…

单变量单步时序预测:CNN-GRU卷积神经网络结合门控循环单元

目录预测效果1. **CNN-GRU的基本原理**2. **应用场景**3. **模型结构与实现**4. **优势与挑战**5. **相关研究与实现**6. **未来发展方向**结论代码设计预测效果 CNN-GRU卷积神经网络结合门控循环单元是一种结合了卷积神经网络&#xff08;CNN&#xff09;和门控循环单元&#…

MonoFusion 与 Genie 3

卡内基梅隆大学的研究者发明了一种叫 MonoFusion 的新技术&#xff0c;它能用很少的普通相机&#xff08;比如4个&#xff09;&#xff0c;就能拍出像电影特效一样细腻流畅的动态3D场景&#xff08;4D重建&#xff09;&#xff0c;比如弹钢琴、修自行车这种复杂动作&#xff0c…

kubernets命令行创建Token并附加权限给dashboard控制台登录

1、创建登录token kubectl create token default -n graph-node-test dgjeojrgopejgeropjgpsdjgerjglsdjfsjogjeojgeorjgortlfhj4yu493460uwperg3wef;lsj2y3r934tnrhifrlfe9t4h5tlhobdrmlgw485tw4yp653ut9ogogjerolj4w9erjgotj3fgjletyj49yr20o359truyo5u6908430jt5grjsdtgj49…

什么是SpringBoot

题目详细答案Spring Boot 是由 Pivotal 团队提供的一个基于 Spring 框架的项目&#xff0c;它旨在简化 Spring 应用的开发和部署。Spring Boot 通过提供一系列的约定和开箱即用的功能&#xff0c;使得开发者可以更快地构建独立的、生产级的 Spring 应用程序&#xff0c;而无需进…