From 704efa62439894b8005de4df8d9b677d4258472d Mon Sep 17 00:00:00 2001 From: "3321822538@qq.com" <3321822538@qq.com> Date: Wed, 6 Nov 2024 17:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=AF=B7=E6=B1=82=E5=A4=AA=E6=85=A2=20=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=97=B6=E9=97=B4=E4=B8=8D=E5=87=86=E7=A1=AE=20?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/http.interceptor.js | 4 +- page_components/eletj.vue | 121 ++++++++++++++++++--------------- page_components/fuwu/index.vue | 7 +- page_components/miyao.vue | 18 ----- pages/index/index.vue | 58 ++++++++++++++-- 5 files changed, 127 insertions(+), 81 deletions(-) diff --git a/common/http.interceptor.js b/common/http.interceptor.js index 3173f5d..4f59292 100644 --- a/common/http.interceptor.js +++ b/common/http.interceptor.js @@ -19,8 +19,8 @@ const install = (Vue, vm) => { // }, // }); Vue.prototype.$u.http.setConfig({ - baseUrl: 'http://192.168.2.12:10002', - // baseUrl: 'https://kg.chuangtewl.com/prod-api', + // baseUrl: 'http://192.168.2.12:10002', + baseUrl: 'https://kg.chuangtewl.com/prod-api', // loadingText: '加载中...', // loadingTime: 1000, // 设置自定义头部content-type diff --git a/page_components/eletj.vue b/page_components/eletj.vue index 45e17fe..1f68969 100644 --- a/page_components/eletj.vue +++ b/page_components/eletj.vue @@ -281,7 +281,6 @@ "全部", "电表", "水表", - ], czflag:false, curtitidx: 0, @@ -321,7 +320,9 @@ channelId:'', dingobj: '', timerone:null, - hasCalledGetczly:false + hasCalledGetczly:false, + timerIds: null , + formattedTime:'' } }, onLoad(option) { @@ -341,29 +342,11 @@ }, computed: { - // 计算剩余时间 - formattedTime() { - // console.log(this.timeday,'00000'); - if (this.timeday.days > 0) { - // 只展示天和小时 - return `${this.timeday.days}天${this.timeday.hours}小时` - } else if (this.timeday.hours > 0) { - // 展示小时和分钟 - return `${this.timeday.hours}小时${this.timeday.minutes}分钟` - } else if (this.timeday.minutes > 0) { - // 展示分钟和秒 - return `${this.timeday.minutes}分钟${this.timeday.seconds}秒` - } else if(this.timeday.seconds == 0){ - this.getDevice() - this.timeday.seconds = 0 - } else { - // 展示秒或0(如果秒也为0) - return this.timeday.seconds > 0 ? `${this.timeday.seconds}秒` : '0' - } - } + }, onUnload: function() { console.log("unload "); + this.stopTimer(); clearInterval(this.timerone); this.timerone= null xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent); @@ -371,6 +354,10 @@ deviceId: this.deviceId, }) }, + mounted() { + // 组件挂载后启动定时器 + + }, // 分享到好友(会话) onShareAppMessage: function() { return { @@ -402,19 +389,71 @@ }, onHide() { // this.stopTimer(); + uni.navigateBack() }, beforeDestroy() { - // 组件销毁前清除定时器,防止内存泄漏 + uni.navigateBack() + // 组件销毁前清除定时器,防止内存泄漏 + if (this.timerIds) { + clearInterval(this.timerIds); + } if (this.timer) { clearInterval(this.timer) this.timer = null; console.log('已销毁') } }, - onUnload() { - this.stopTimer(); - }, methods: { + start() { + this.timerIds = setInterval(() => { + // 首先处理秒数的递减 + if (this.timeday.seconds > 0) { + this.timeday.seconds--; + } else { + // 如果秒数为0,则处理分钟数的递减,并重置秒数为59 + if (this.timeday.minutes > 0) { + this.timeday.seconds = 59; + this.timeday.minutes--; + } else { + // 如果分钟数为0,则处理小时数的递减,并重置分钟和秒数为59 + if (this.timeday.hours > 0) { + this.timeday.minutes = 59; + this.timeday.seconds = 59; + this.timeday.hours--; + } else { + // 如果小时数为0,则处理天数的递减,并重置小时、分钟和秒数为最大值 + if (this.timeday.days > 0) { + this.timeday.hours = 23; + this.timeday.minutes = 59; + this.timeday.seconds = 59; + this.timeday.days--; + } else { + // 当天数也为0时,清除定时器并执行所需操作 + clearInterval(this.timerIds); + this.getDevice(); + return; // 这里可以添加return来退出函数,但实际上由于setInterval是异步的,它不会阻止后续的console.log执行(但在这个上下文中它是多余的) + } + } + } + } + // 格式化时间并打印到控制台 + this.formattedTime = this.formatTime(this.timeday); + // console.log(formattedTime, 'idsidsids'); + }, 1000); // 每1000毫秒(1秒)执行一次 + }, + formatTime(timeObj) { + // 根据时间的不同部分构建格式化的字符串 + if (timeObj.days > 0) { + return `${timeObj.days}天 ${timeObj.hours.toString().padStart(2, '0')}小时 ${timeObj.minutes.toString().padStart(2, '0')}分钟 ${timeObj.seconds.toString().padStart(2, '0')}秒`; + } else if (timeObj.hours > 0) { + return `${timeObj.hours}小时 ${timeObj.minutes.toString().padStart(2, '0')}分钟 ${timeObj.seconds.toString().padStart(2, '0')}秒`; + } else if (timeObj.minutes > 0) { + return `${timeObj.minutes}分钟 ${timeObj.seconds.toString().padStart(2, '0')}秒`; + } else { + return `${timeObj.seconds}秒`; + } + }, + startTimerone() { // 清除之前可能存在的定时器,防止重复设置 clearInterval(this.timerone); @@ -1221,14 +1260,14 @@ let expireDate = new Date(expireDateParts[0], expireDateParts[1] - 1, expireDateParts[2], expireTimePartsTime[0], expireTimePartsTime[1], expireTimePartsTime[2]) let now = new Date() let differenceInMs = expireDate - now - console.log(differenceInMs,expireDate,now,this.formatMilliseconds(differenceInMs),'101010'); + // console.log(differenceInMs,expireDate,now,this.formatMilliseconds(differenceInMs),'101010'); this.timeday == '' if (differenceInMs <= 0) { this.timeday = 0 } else { if (this.timeday == '') { this.timeday = this.formatMilliseconds(differenceInMs) - this.startTimer() + this.start() } } } @@ -1283,31 +1322,6 @@ } return result }, - - startTimer() { - this.timer = setInterval(() => { - if (this.timeday.seconds > 0) { - this.timeday.seconds-- - } else if (this.timeday.minutes > 0) { - this.timeday.seconds = 59 // 重置秒数为59 - this.timeday.minutes-- - } else if (this.timeday.hours > 0) { - this.timeday.minutes = 59 // 重置分钟数为59 - this.timeday.hours-- - this.timeday.seconds = 0 // 同时重置秒数为0 - } else if (this.timeday.days > 0) { - this.timeday.hours = 23 // 重置小时数为23 - this.timeday.minutes = 59 // 重置分钟数为59 - this.timeday.seconds = 0 // 重置秒数为0 - this.timeday.days-- - } else { - // 所有时间单位都已减为0,停止定时器 - clearInterval(this.timer) - this.timer = null; - console.log('时间已到期') - } - }, 1000); // 每秒执行一次 - }, // 计算天时分秒 formatMilliseconds(milliseconds) { // 计算天数 @@ -1477,7 +1491,6 @@ // 返回解析后的数据对象 return parsedData }, - } } diff --git a/page_components/fuwu/index.vue b/page_components/fuwu/index.vue index 2d3fcce..3400944 100644 --- a/page_components/fuwu/index.vue +++ b/page_components/fuwu/index.vue @@ -304,9 +304,14 @@ } } }) + }else if(this.userId != this.deviceobj.userId && this.deviceobj.suitList.length == 0){ + uni.showToast({ + title:'该设备暂无套餐,请联系商家添加套餐在使用', + icon: 'none', + duration:2000 + }) } }, - getzfqd(){ this.$u.get(`/app/channel/recharge/enabledList`).then(res =>{ if(res.code == 200){ diff --git a/page_components/miyao.vue b/page_components/miyao.vue index ccccd8b..0c7c277 100644 --- a/page_components/miyao.vue +++ b/page_components/miyao.vue @@ -2,9 +2,6 @@ - - - @@ -20,7 +17,6 @@ 重置秘钥 - @@ -32,8 +28,6 @@ 申请 - - @@ -58,7 +52,6 @@ - @@ -230,19 +223,16 @@ color: #3D3D3D; } } - } page { background-color: #F7FAFE; text-align: center; } - .wubox { margin: auto; width: 646rpx; margin-top: 48rpx; text-align: left !important; - .youmy { width: 646rpx; height: 210rpx; @@ -251,21 +241,18 @@ border-radius: 20rpx 20rpx 20rpx 20rpx; font-size: 36rpx; color: #3D3D3D; - .key { height: 106rpx; line-height: 106rpx; padding-left: 24rpx; box-sizing: border-box; } - .xian { width: 606rpx; height: 0rpx; border: 2rpx solid #D8D8D8; margin-left: 24rpx; } - .mima { height: 106rpx; line-height: 106rpx; @@ -273,7 +260,6 @@ box-sizing: border-box; } } - .cz { margin-top: 44rpx; width: 646rpx; @@ -287,26 +273,22 @@ color: #8883F0; } } - .img { width: 430rpx; height: 430rpx; margin: auto; margin-top: 114rpx; - image { width: 430rpx; height: 430rpx; } } - .ts { font-weight: 500; font-size: 36rpx; color: #3D3D3D; margin-top: 94rpx; } - .sq { width: 370rpx; height: 96rpx; diff --git a/pages/index/index.vue b/pages/index/index.vue index 9bd2844..c7b3556 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -243,6 +243,7 @@ addflag: false, sbflag: true, show: false, + qingqiuflag:true, list: [{ value: '1', label: '扫码添加' @@ -265,7 +266,7 @@ storeId: '', pagenum: 1, wateringList: [], - pagesize: 999, + pagesize: 10, isLoading: false, noMoreData: false, total: 0, @@ -791,10 +792,18 @@ } else if (Math.abs(deltaY) > 50 && Math.abs(deltaX) < Math.abs(deltaY)) { if (deltaY < 100) { console.log("上滑") - let sum = this.total / this.pagesize - console.log(this.wateringList.length,this.total); - if (this.wateringList.length < this.total) { - this.getlist() + // let sum = this.total / this.pagesize + // console.log(this.wateringList.length,this.total); + // if (this.wateringList.length < this.total) { + // this.getlist() + // } + if(this.qingqiuflag == true){ + let sum = this.total / this.pagesize + console.log(this.groupLists[0].wateringList.length,this.total); + if (this.groupLists[0].wateringList.length < this.total) { + this.qingqiuflag = false + this.getlist() + } } } else { console.log(deltaY) @@ -1056,8 +1065,10 @@ if (this.pagenum > 1) { this.pagenum++ // this.wateringList = [] - this.wateringList = this.wateringList.concat(res.rows) + // this.wateringList = this.wateringList.concat(res.rows) + this.wateringList = res.rows this.shujuflag = false + this.qingqiuflag = true // console.log(this.wateringList); this.groupLists.forEach(groupItem => { groupItem.wateringList @@ -1074,10 +1085,28 @@ } }) }) + // this.groupLists[0] = this.groupLists[0].map(group => { + // // 使用一个对象来跟踪已经遇到的 deviceId + // const seenDeviceIds = {}; + // // 使用 reduce 来创建一个新的 wateringList,只包含唯一的 deviceId + // const uniqueWateringList = group.wateringList.reduce((acc, item) => { + // if (!seenDeviceIds[item.deviceId]) { + // seenDeviceIds[item.deviceId] = true; + // acc.push(item); + // } + // return acc; + // }, []); + // // 返回更新后的组对象 + // return { + // ...group, + // wateringList: uniqueWateringList + // }; + // }) uni.hideLoading() } else { this.pagenum++ this.wateringList = res.rows + this.qingqiuflag = true // console.log(this.wateringList,'000') this.groupLists.forEach(groupItem => { groupItem.wateringList = [] @@ -1093,6 +1122,23 @@ }) }) // console.log(this.groupLists) + // this.groupLists[0] = this.groupLists[0].map(group => { + // // 使用一个对象来跟踪已经遇到的 deviceId + // const seenDeviceIds = {}; + // // 使用 reduce 来创建一个新的 wateringList,只包含唯一的 deviceId + // const uniqueWateringList = group.wateringList.reduce((acc, item) => { + // if (!seenDeviceIds[item.deviceId]) { + // seenDeviceIds[item.deviceId] = true; + // acc.push(item); + // } + // return acc; + // }, []); + // // 返回更新后的组对象 + // return { + // ...group, + // wateringList: uniqueWateringList + // }; + // }) uni.hideLoading() } this.isLoading = false