优化设备列表请求太慢 订单时间不准确 绑定默认选中等
This commit is contained in:
		
							parent
							
								
									5f5562ebe1
								
							
						
					
					
						commit
						704efa6243
					
				|  | @ -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
 | ||||
|  |  | |||
|  | @ -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 | ||||
| 			}, | ||||
|   | ||||
| 		} | ||||
| 	} | ||||
| </script> | ||||
|  |  | |||
|  | @ -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){ | ||||
|  |  | |||
|  | @ -2,9 +2,6 @@ | |||
| 	<view> | ||||
| 		<u-navbar title="秘钥管理" :border-bottom="false" :background="bgc" title-color='#fff' back-icon-color="#fff" | ||||
| 			title-size='36' height='42'></u-navbar> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 		<!-- 有秘钥 --> | ||||
| 		<view class="wubox" v-if="flag"> | ||||
| 			<view class="youmy"> | ||||
|  | @ -20,7 +17,6 @@ | |||
| 				重置秘钥 | ||||
| 			</view> | ||||
| 		</view> | ||||
| 		 | ||||
| 		<view class="" v-else> | ||||
| 			<view class="img"> | ||||
| 				<image src="https://api.ccttiot.com/smartmeter/img/static/uCvMUhBep204JORh00p4" mode=""></image> | ||||
|  | @ -32,8 +28,6 @@ | |||
| 				申请 | ||||
| 			</view> | ||||
| 		</view> | ||||
| 
 | ||||
| 
 | ||||
|          <!-- 弹窗 --> | ||||
| 		 <view class="tanc" v-if="maskflag"> | ||||
| 		 	<image src="https://api.ccttiot.com/smartmeter/img/static/uNaia3ZQXsWB9nkprcaa" mode=""></image> | ||||
|  | @ -58,7 +52,6 @@ | |||
| 		 </view> | ||||
| 		 <view class="mask" v-if="maskflag"></view> | ||||
| 		 <view v-if="btnmsk" style="width: 100%;height: 100vh;position: fixed;top: 0;left: 0;background-color: #000;opacity: .1;z-index: 999;"></view> | ||||
| 
 | ||||
| 	</view> | ||||
| </template> | ||||
| 
 | ||||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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,11 +792,19 @@ | |||
| 				} 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()  | ||||
| 						// } | ||||
| 						if(this.qingqiuflag == true){ | ||||
| 							let sum = this.total / this.pagesize | ||||
| 						console.log(this.wateringList.length,this.total); | ||||
| 						if (this.wateringList.length  < this.total) { | ||||
| 							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) | ||||
| 						if (deltaY > 250) { | ||||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user