template view classtime-switch-wrap !-- 顶部分段标签 activeKey 为u-tabs标准绑定字段 -- u-tabs :classtabsClass :listtabList :activeStylemergedActiveStyle :inactiveStylemergedInactiveStyle changeonChange / !-- 导航 -- view classdate-nav-1 u-icon v-ifactiveType ! custom classnav-left nameplay-left-fill size16 clickprevDate / view classdate-text clickopenDatePopup{{ displayDate }}/view u-icon v-ifactiveType ! custom classnav-right nameplay-right-fill size16 clicknextDate / /view !-- 选择日期 -- !-- 底部弹出层 -- view v-ifpopupShowactiveType day classpopup-calendar u-calendar :minDateminCalendarDate monthNum121 :disabledFunallDateCanSelect :showshow confirmonDaySelect / /view !-- 周选择弹窗区间选择 -- view v-ifpopupShowactiveType week classpopup-week u-calendar v-modelselectDay modesingle :showshow title选择任意一天自动匹配完整周一~周日 confirmonWeekSelect closeclosebtn / /view !-- 年月选择弹窗 -- view v-ifpopupShowactiveType month classpopup-month u-picker :showshow v-modelmonthPickerValue :columnsmonthColumns confirmonMonthSelect / /view !-- 年份选择弹窗 -- view v-ifpopupShowactiveType year classpopup-year u-picker :showshow v-modelyearPickerValue :columnsyearColumns confirmonYearSelect / /view !-- 自定义时间可自行扩展区间日历 -- view v-ifpopupShowactiveType custom classpopup-custom u-calendar closeclosebtn :minDateminCalendarDate monthNum121 v-modelweekRange allowSameDay :showshow moderange confirmonCustomSelect / /view /view /template script setup languts import { ref, computed, defineEmits, watch, withDefaults } from vue import { dayuts } from /uni_modules/lime-dayuts; export type TimeDimension day | week | month | year | custom const tabList [ { name: 日, value: day as TimeDimension }, { name: 周, value: week as TimeDimension }, { name: 月, value: month as TimeDimension }, { name: 年, value: year as TimeDimension }, { name: 自定义, value: custom as TimeDimension }, // { name: 自定义wwww, value: custom as TimeDimension }, ] const show ref(false) // 只定义一次Props删除下方重复interface Props interface Props { modelValue : TimeDimension currentDate : string | Date activeStyle ?: Recordstring, string inactiveStyle ?: Recordstring, string enableTabsClass ?: boolean } const props withDefaults(definePropsProps(), { // 【内置默认激活样式】 activeStyle: () ({ color: #1F2329, fontWeight: bold, background: #eff2f7, }), // 【内置默认未激活样式】 inactiveStyle: () ({ fontWeight: 400, color: #1F2329, }), enableTabsClass: false }) const emit defineEmits{ update:modelValue : [val: TimeDimension] update:currentDate : [date: string] change : [ type: TimeDimension, baseDate: string, range?: { start ?: string end ?: string yearMonth ?: string year ?: number } ] }() const tabsClass computed(() { return props.enableTabsClass ? u-tabs-f : }) const baseDate ref(dayuts(props.currentDate)) const popupShow ref(false) const activeType refTimeDimension(props.modelValue) const minCalendarDate computed(() { // 复制一份日期避免修改原baseDate const minDay baseDate.value.subtract(120, month) return minDay.format(YYYY-MM-DD) }) const mergedActiveStyle computed(() ({ ...props.activeStyle })) const mergedInactiveStyle computed(() ({ ...props.inactiveStyle })) const closebtn () { popupShow.value false } const onChange (e) { baseDate.value dayuts(props.currentDate) console.log(e, e) activeType.value e.value // 同步父组件选中tab emit(update:modelValue, e.value) const baseStr baseDate.value.format(YYYY-MM-DD) emit(update:currentDate, baseStr) if (activeType.value week) { const start getWeekStart(baseDate.value).format(YYYY-MM-DD) const end getWeekEnd(baseDate.value).format(YYYY-MM-DD) emit(change, activeType.value, baseStr, { start, end }) } else if (activeType.value month) { const yearMonth baseDate.value.format(YYYY-MM) emit(change, activeType.value, baseStr, { yearMonth }) } else if (activeType.value year) { const year baseDate.value.year() emit(change, activeType.value, baseStr, { year }) } else if (activeType.value custom) { // 自定义默认当天开始、当天结束 const start baseStr const end baseStr weekRange.value [baseStr, baseStr] emit(change, activeType.value, baseStr, { start, end }) } else { // day 无额外参数 emit(change, activeType.value, baseStr) } } const handleWeekDisabled (date : Date) : boolean { const target dayuts(date) const selectStart weekRange.value[0] ? dayuts(weekRange.value[0]) : null // 未选开始日期全部可点 if (!selectStart) return false const diffDays target.diff(selectStart, day) // 只能往后选最多6天凑满7天 if (diffDays 0 || diffDays 6) return true const startWeekDay selectStart.day() // 0周日 1周一 ...6周六 const endWeekDay target.day() // 规则起始必须周一结束必须周日且间隔正好6天共7天 const isFullWeek startWeekDay 1 endWeekDay 0 diffDays 6 return !isFullWeek } // 各选择器绑定值 const selectDay refstring(baseDate.value.format(YYYY-MM-DD)) // 周/自定义共用区间数组 const weekRange refstring[]([ getWeekStart(baseDate.value).format(YYYY-MM-DD), getWeekEnd(baseDate.value).format(YYYY-MM-DD) ]) const monthPickerValue refstring([ String(baseDate.value.year()), String(baseDate.value.month() 1) ]) const yearPickerValue refstring[]([String(baseDate.value.year())]) type DayutsInstance ReturnTypetypeof dayuts // 计算本周周一 function getWeekStart(d : DayutsInstance) : DayutsInstance { const dayNum d.day() const offset dayNum 0 ? -6 : 1 - dayNum return d.add(offset, day) } // 计算本周周日 function getWeekEnd(d : DayutsInstance) : DayutsInstance { return getWeekStart(d).add(6, day) } // 月份picker列 const monthColumns computed(() { const curYear baseDate.value.year() const years : string[] [] for (let i curYear - 10; i curYear 10; i) { years.push(String(i)) } const months [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] return [years, months] }) // 年份picker列 const yearColumns computed(() { const curYear baseDate.value.year() const years : string[] [] for (let i curYear - 10; i curYear 10; i) { years.push(String(i)) } return [years] }) // 监听外部参数 watch(() props.modelValue, (newVal : TimeDimension) { activeType.value newVal }) watch(() props.currentDate, (val) { baseDate.value dayuts(val) resetPickerValue() syncEmit() }) // 重置选择器绑定值自定义默认当天-当天 const resetPickerValue () { const safeDate baseDate.value.isValid() ? baseDate.value : dayuts() const today safeDate.format(YYYY-MM-DD) selectDay.value today if (activeType.value custom) { weekRange.value [today, today] } else if (activeType.value week) { // 打开周日历默认当前整周 const mon getWeekStart(safeDate) const sun getWeekEnd(safeDate) weekRange.value [mon.format(YYYY-MM-DD), sun.format(YYYY-MM-DD)] } else { weekRange.value [ getWeekStart(safeDate).format(YYYY-MM-DD), getWeekEnd(safeDate).format(YYYY-MM-DD) ] } monthPickerValue.value [ String(safeDate.year()), String(safeDate.month() 1) ] yearPickerValue.value [String(safeDate.year())] } // 打开底部弹窗 const openDatePopup () { resetPickerValue() popupShow.value true show.value true } // 页面展示日期文本新增custom分支展示区间 const displayDate computed(() { const d baseDate.value switch (activeType.value) { case day: return d.format(YYYY/M/D) case week: const s getWeekStart(d) const e getWeekEnd(d) return ${s.format(YYYY/M/D)} - ${e.format(YYYY/M/D)} case month: return d.format(YYYY/M) case year: return String(d.year()) case custom: // 自定义展示当前基准日-当前基准日 const start weekRange.value[0] const end weekRange.value[weekRange.value.length - 1] console.log(weekRange.value, weekRange.value) return ${dayuts(start).format(YYYY/M/D)} - ${dayuts(end).format(YYYY/M/D)} default: return d.format(YYYY/M/D) } }) // 上一周期 const prevDate () { switch (activeType.value) { case day: baseDate.value baseDate.value.subtract(1, day) break case week: baseDate.value baseDate.value.subtract(7, day) break case month: baseDate.value baseDate.value.subtract(1, month) break case year: baseDate.value baseDate.value.subtract(1, year) break case custom: baseDate.value baseDate.value.subtract(1, day) break } syncEmit() } // 下一周期 const nextDate () { switch (activeType.value) { case day: baseDate.value baseDate.value.add(1, day) break case week: baseDate.value baseDate.value.add(7, day) break case month: baseDate.value baseDate.value.add(1, month) break case year: baseDate.value baseDate.value.add(1, year) break case custom: baseDate.value baseDate.value.add(1, day) break } syncEmit() } // 同步通知父组件补全custom分支 const syncEmit () { const baseStr baseDate.value.format(YYYY-MM-DD) emit(update:currentDate, baseStr) if (activeType.value week) { const start getWeekStart(baseDate.value).format(YYYY-MM-DD) const end getWeekEnd(baseDate.value).format(YYYY-MM-DD) emit(change, activeType.value, baseStr, { start, end }) } else if (activeType.value month) { const yearMonth baseDate.value.format(YYYY-MM) console.log(yearMonth, yearMonth) emit(change, activeType.value, baseStr, { yearMonth }) } else if (activeType.value year) { const year baseDate.value.year() emit(change, activeType.value, baseStr, { year }) } else if (activeType.value custom) { const start weekRange.value[0] const end weekRange.value[weekRange.value.length - 1] emit(change, activeType.value, baseStr, { start, end }) } else { emit(change, activeType.value, baseStr) } } // 单日选择确认 const onDaySelect (date : string[]) { baseDate.value dayuts(date[0]) popupShow.value false show.value false syncEmit() } // 周区间选择确认 const onWeekSelect (dateArr : string[]) { const pickDay dayuts(dateArr[0]) // 获取选中日对应的周一、周日 const mon getWeekStart(pickDay) const sun getWeekEnd(pickDay) // 更新区间为完整一周 weekRange.value [mon.format(YYYY-MM-DD), sun.format(YYYY-MM-DD)] // 基准日期设为本周周一 baseDate.value mon popupShow.value false show.value false syncEmit() } // 月份选择确认 const onMonthSelect (res : string[]) { console.log(res, res) const year Number(res.value[0]) const month Number(res.value[1]) - 1 // 必须减1 console.log(转换后year, year, month, month, 最终month, month) baseDate.value dayuts().year(year).month(month).date(1) console.log(baseDate.value, baseDate.value ) popupShow.value false show.value false syncEmit() } // 年份选择确认 const onYearSelect (res : string[]) { const year Number(res.value[0]) baseDate.value dayuts().year(year).month(0).date(1) popupShow.value false show.value false syncEmit() } // 自定义区间选择确认 const onCustomSelect (res : string[]) { console.log(自定义选中区间, res) // 更新基准日期为选中起始日 baseDate.value dayuts(res[0]) // 更新全局区间数组 weekRange.value res // 关闭弹窗 popupShow.value false show.value false // 统一走syncEmit派发事件内部自动处理custom逻辑 syncEmit() } /script style langscss scoped .time-switch-wrap { width: 100%; .date-nav-1 { margin-top: 33rpx; display: flex; flex-direction: row; justify-content: center; align-items: center; .nav-left { margin-right: 53rpx; } .nav-right { margin-left: 53rpx; } .date-text { font-weight: 600; font-size: 29rpx; color: #1F2329; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } } } // 平板适配min-width:768px单位px media screen and (min-width: 768px) { .time-switch-wrap { // u-tabs 标签整体微调大屏不拥挤 :deep(.u-tabs) { height: 40rpx !important; } :deep(.u-tabs__wrapper__scroll-view__item) { padding: 0 40rpx; } :deep(.u-tabs__wrapper__scroll-view__item-text) { font-size: 21rpx !important; } .date-nav-1 { margin-top: 24rpx; .nav-left { margin-right: 36rpx; } .nav-right { margin-left: 36rpx; } .date-text { font-size: 22rpx; } } } } /styleimport { dayuts } from /uni_modules/lime-dayuts const timeTyperef(day) 初始类型 const selectDate ref(dayuts().format(YYYY-MM-DD)) 初始时间也就是当前时间 TimeTabSwitch v-modeltimeType :current-dateselectDate changehandleTimeChange / const handleTimeChange (type : TimeDimension, baseDate : string, range ?: { start ?: string; end ?: string; yearMonth ?: string; year ?: string }) { if (type week range) { console.log(周开始, range.start) console.log(周结束, range.end) itemizeModel.startTime range.start itemizeModel.endTime range.end // 接口请求传 start / end } else if (type month range) { console.log(选择年月, range.yearMonth) itemizeModel.startTime range.yearMonth itemizeModel.endTime range.yearMonth } else if (type year range) { console.log(选择年份, range.year) itemizeModel.startTime range.year } else if (type custom range) { itemizeModel.startTime range.start itemizeModel.endTime range.end } else { console.log(当前维度, type, 基准日期, baseDate) itemizeModel.startTime baseDate itemizeModel.endTime baseDate } // 接口请求逻辑 itemizeModel.time type findEnergyConsumptionSubItem()//调用自己方法 }
企业数字化 ERP 产品动态
相关推荐
nVisual 如何解决跨楼层机房的线缆问题? 大家好,这里是 nVisual 频道。本频道将持续更新 nVisual 的使用技巧与常见问题的解决方法,欢迎大家关注。
在机房规划中,有时会遇到跨楼层机房的设计场景:上层机房与下层机房通过竖井连接。这类场景下的仿真设计往往让不少用户感到… · 2026/9/18 8:59:24
卷积扰动认证训练:提升CNN鲁棒性的可验证防御方法 这次我们来看一个名为"Certified Training for Convolutional Perturbations"的项目,这是一个专注于提升卷积神经网络鲁棒性的认证训练方法。该项目针对深度学习模型在面对卷积扰动时的脆弱性问题,提供了一套可验证的防御方案。从项目名称就能… · 2026/8/4 3:02:32
零门槛解锁Wand专业版:告别付费订阅的游戏修改新体验 零门槛解锁Wand专业版:告别付费订阅的游戏修改新体验 【免费下载链接】Wand-Enhancer Advanced UX and interoperability extension for Wand (WeMod) app 项目地址: https://gitcode.com/GitHub_Trending/we/Wand-Enhancer
还在为Wand(原WeMod&a… · 2026/9/19 12:07:40
使用ExecTI解决Windows注册表TrustedInstaller权限问题 1. 先聊聊那条让人抓狂的报错:"你需要TrustedInstaller提供的权限" 很多玩注册表的人第一次撞上这堵墙,是在改某个系统服务参数或者清理软件残留的时候。你明明用的是管理员账号,UAC 也点了"是",regedit 也好… · 2026/9/24 18:42:13
草莓成熟度YOLO数据集:开箱即用,支持v5/v8训练与边缘部署 简介:本资源是一套专为农业智能检测场景设计的YOLO格式草莓成熟度识别数据集,面向计算机视觉初学者、农业AI项目开发者及模型训练实践者,解决果实成熟状态自动判别这一典型目标检测问题。数据集严格遵循YOLOv5目录结构组织,含训练… · 2026/9/24 18:42:13
合同多格式比对:Word/PDF/扫描件的底层技术逻辑 1. 合同比对不是“找不同”,而是法律风险的显微镜合同比对这件事,很多人第一反应是打开Word的“比较”功能,或者拖两个PDF进在线比对网站,点一下就等结果。我做过三年法务支持,也帮二十多家企业搭建过合同生命周期管理… · 2026/9/24 18:42:07
GPT术语漂移治理:从提示词到强制校验的完整落地方案 去年我在做一套面向工业设备行业的智能文档生成服务时,最头疼的问题不是模型不会写,而是它太“会写”了——同一个产品名,今天叫“智能脱扣器”,明天叫“过载保护单元”,后天甚至自创一个“智能保护模块”。对于对外技… · 2026/9/24 18:42:07
YOLO草莓成熟度检测数据集:农业视觉落地关键 简介:本资源是一套专为农业智能检测场景设计的YOLO格式草莓成熟度识别数据集,面向计算机视觉初学者、农业AI项目开发者及YOLO系列模型实践者,解决果实分级自动化中的关键标注与训练数据缺失问题。数据集严格遵循YOLOv5目录结构组织࿰… · 2026/9/24 18:42:07
火语言RPA攻克网页表单控件:单选框、复选框、下拉框操作实战 做RPA最常踩的坑,往往不是登录、不是翻页,而是那些看似人畜无害的网页表单控件。单选框、复选框、下拉框,随便哪个在页面里换了皮肤、套了框架、加了懒加载,就能让脚本在运行到一半的时候突然“神经质”。我用火语言RPA处理网页表… · 2026/9/24 18:42:06
基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程 简介:这是一套面向计算机、人工智能、自动化等专业学生与教师的毕业设计级项目资源,围绕YOLOv8实现渔船作业监控系统,可用于毕设、课程设计、大作业或项目立项演示。压缩包共97个文件,约24.21MB,以70个Python源码文件为… · 2026/9/24 0:00:13
1D-CNN时间序列建模实战:从Conv1d原理到工业落地 简介:面向时间序列数据建模的一维卷积神经网络完整实现,适合深度学习入门者及需要快速验证时序模型的研究者,能够从音频、文本、传感器或股价等序列中挖掘局部特征与时间依赖。压缩包体积很小,只有3KB,内含3个Python脚… · 2026/9/24 0:00:26
柔软的L:汉语语流中被忽视的舌肌张力控制 1. 这个“L”不是字母表里的L,而是舌尖上的L最近在几个方言群和语音教学社群里,反复看到有人发一句:“也说字母L:柔软的长舌”。初看以为是英语发音课笔记,点开才发现全是方言爱好者、播音系学生、语言康复师甚至戏曲演… · 2026/9/24 0:00:44