柒零 пре 1 година
родитељ
комит
c3e9389ea0
4 измењених фајлова са 95 додато и 290 уклоњено
  1. 64 115
      pages/data/data.js
  2. 2 1
      pages/data/data.wxml
  3. 26 174
      pages/index/index.js
  4. 3 0
      pages/index/index.wxml

+ 64 - 115
pages/data/data.js

@@ -2011,6 +2011,7 @@ Page({
 			// onInit: initChartTimeWaterfall
 		},
 		header: false,
+		showAuthorizedDialog:false,
 		nowDate: [{ //日历的初始化数据
 			month: 'current',
 			day: new Date().getDate(),
@@ -4336,16 +4337,38 @@ Page({
 		// console.log("睡眠数据最终=>", startTime);
 		console.log("睡眠数据最终=>", JSON.stringify(timePeriods));
 	},
+	authorizationSuccessful() {
+		console.log("授权成功");
+		this.setData({ showAuthorizedDialog: false })
+		this.showData();
+	},
 	onReady() {
-		var that = this;
-		that.initChartCircle();
-		that.initOutOfBed();
-		that.initBodyMovements();
-		that.initCardiacSystem();
-		that.initChartRespiratory();
-		that.initChartSnoring();
-		that.initChartApnea();
-		that.initTimeWaterfall();
+		if (!wx.getStorageSync('hasAuth')) {
+			this.setData({ showAuthorizedDialog: true })
+		} else {
+			this.showData();
+		}
+	},
+	showData() { 
+		let userInfo = wx.getStorageSync("userInfo") || {};
+		let hotelcodeTemp = userInfo.hotel;
+		let roomcodeTemp = userInfo.room;
+
+		this.getData(null, hotelcodeTemp, roomcodeTemp, null);
+		// 设置canvas的宽高  
+		this.setData({
+			hotelcode: hotelcodeTemp,
+			roomcode: roomcodeTemp,
+		});
+
+		this.initChartCircle();
+		this.initOutOfBed();
+		this.initBodyMovements();
+		this.initCardiacSystem();
+		this.initChartRespiratory();
+		this.initChartSnoring();
+		this.initChartApnea();
+		this.initTimeWaterfall();
 	},
 	/**			
 	 * 生命周期函数--监听页面加载
@@ -4370,112 +4393,38 @@ Page({
 
 	},
 	onLoad(option) {
-		var that = this;
-		console.log("data页面");
+		// var that = this;
+		// console.log("data页面");
 		// wx.clearStorage();
-		console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
-		if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
-			wx.showModal({
-				title: '提示',
-				content: '请先扫描房间二维码',
-				showCancel: false
-			});
-
-			setTimeout(function () {
-				wx.reLaunch({
-					url: '/pages/scan/scan',
-				})
-			}, 2000) // 设置延时时间,单位为毫秒
-		} else if (wx.getStorageSync('res').result.split('|').length != 2) {
-			wx.showModal({
-				title: '提示',
-				content: '房间二维码不正确,请重新扫码',
-				showCancel: false
-			});
-
-			setTimeout(function () {
-				wx.reLaunch({
-					url: '/pages/scan/scan',
-				})
-			}, 2000) // 设置延时时间,单位为毫秒
-		} else {
-			// const expiresAt = wx.getStorageSync('scanResultExpiresAt');
-			// const now = Date.now() 
-			// if (expiresAt || expiresAt < now) {
-			//   // 扫码结果已过期  
-			//   wx.showToast({
-			//     title: '扫码结果失效或已过期,请重新扫码',  
-			//     icon: 'none'  
-			//   });
-			//   // 清除过期的扫码结果  
-			//   wx.removeStorageSync('scanResultExpiresAt');  
-			//   setTimeout(function() {
-			//       wx.reLaunch({
-			//       		url: '/pages/scan/scan',
-			//       })
-			//     }, 2000) // 设置延时时间,单位为毫秒
-
-			// }else{
-			// 	//续期
-			// 	wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
-			// }
-
-			let hotelcodeTemp = '';
-			let roomcodeTemp = '';
-
-			hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
-			roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
-			this.getData(null, hotelcodeTemp, roomcodeTemp, null);
-			// const result = await this.getData();
-			// console.log('result='+JSON.stringify(result));
-			this.drawProgressCircle();
-			// 获取系统信息  
-			const systemInfo = wx.getSystemInfoSync();
-			const windowWidth = systemInfo.windowWidth; // 窗口宽度  
-
-			// 计算canvas的宽度和高度  
-			const canvasWidth = windowWidth; // 可以根据需求调整canvas的宽度  
-			const canvasHeight = windowWidth * 0.5; // 假设高度是宽度的一半,可以根据需求调整  
-
-
-			// var now = new Date(); // 创建一个Date对象,表示当前的日期和时间  
-			// var year = now.getFullYear(); // 获取年份  
-			// var month = now.getMonth() + 1; // 获取月份(注意月份是从0开始的,所以需要+1)  
-			// var date = now.getDate(); // 获取日期  
-			// var hours = now.getHours(); // 获取小时  
-			// var minutes = now.getMinutes(); // 获取分钟  
-			// var seconds = now.getSeconds(); // 获取秒  
-
-			// month = month < 10 ? '0' + month : month;  
-			// date = date < 10 ? '0' + date : date;  
-			// hours = hours < 10 ? '0' + hours : hours;  
-			// minutes = minutes < 10 ? '0' + minutes : minutes;  
-			// seconds = seconds < 10 ? '0' + seconds : seconds;  
-
-			// // 拼接日期和时间字符串  
-			// var currentDateTime = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds;  
-
-			// console.log(currentDateTime); 
-			// var currentDate = year + '-' + month + '-' + date;  
-			// var currentTime = hours + ':' + minutes + ':' + seconds;  
-
-			// this.selectComponent('#mychart-dom-bar00').init((canvas, width, height) => {
-			// 	that.initChart00(canvas, width, height)
-			//   });
-
-			// 设置canvas的宽高  
-			this.setData({
-				// currentDate: currentDate,
-				// currentTime: currentTime,
-				canvasWidth: canvasWidth,
-				canvasHeight: canvasHeight,
-				hotelcode: hotelcodeTemp,
-				roomcode: roomcodeTemp,
-				//		  roomname: wx.getStorageSync('roomname'),
-
-				// arrayFourth: array,
-			});
-		}
+		// console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
+		
+		// if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
+		// 	wx.showModal({
+		// 		title: '提示',
+		// 		content: '请先扫描房间二维码',
+		// 		showCancel: false
+		// 	});
+
+		// 	setTimeout(function () {
+		// 		wx.reLaunch({
+		// 			url: '/pages/scan/scan',
+		// 		})
+		// 	}, 2000) // 设置延时时间,单位为毫秒
+		// }
+		// else if (wx.getStorageSync('res').result.split('|').length != 2) {
+		// 	wx.showModal({
+		// 		title: '提示',
+		// 		content: '房间二维码不正确,请重新扫码',
+		// 		showCancel: false
+		// 	});
+
+		// 	setTimeout(function () {
+		// 		wx.reLaunch({
+		// 			url: '/pages/scan/scan',
+		// 		})
+		// 	}, 2000) // 设置延时时间,单位为毫秒
+		// }
+	
 
 		// else if(!this.data.home_room.includes(wx.getStorageSync('res').result)){
 		// 	  wx.showModal({
@@ -4500,7 +4449,7 @@ Page({
 		//   homeApi_https = "https://zhh.aidsleep.cn";
 		//  }
 
-		this.drawCircle();
+		// this.drawCircle();
 
 	},
 	mounted() {

+ 2 - 1
pages/data/data.wxml

@@ -806,5 +806,6 @@
   <view class='canvas5'>
     <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec5 }}" class="canvas5"></ec-canvas>
   </view> -->
-
+	<authorized-login-dialog showDialog="{{showAuthorizedDialog}}"
+		bind:authorizationSuccessful="authorizationSuccessful"></authorized-login-dialog>
 </view>

+ 26 - 174
pages/index/index.js

@@ -107,7 +107,7 @@ function updateChartCircularProgressBarOption(rscore_desc, rscore_value, that) {
 				console.log('view不存在');
 			}
 		}).exec(); // 执行查询
-		
+
 	}
 }
 
@@ -175,7 +175,7 @@ function setOption(chart) {
 				fontSize: "28px",
 				fontWeight: 'bolder',
 				formatter: function (value) {
-					return `${value.toFixed(0) }` + '{units|%}'
+					return `${value.toFixed(0)}` + '{units|%}'
 				},
 				color: '#3E3D44',
 				rich: {
@@ -347,7 +347,7 @@ Page({
 		Light: 0,
 		LiquidLevel: 0,
 		//香薰机参数 开始
-
+		showAuthorizedDialog: false,
 		area: "请求中", //城区
 		city: "请求中", //城市
 		airText: "请求中", //空气优良
@@ -455,7 +455,7 @@ Page({
 			'加湿器', '空调', '音箱', '窗帘', '纱帘'
 		],
 		temperatureHumidifyName: '温度',
-		temperatureValue:0,
+		temperatureValue: 0,
 		isButtonPressedHumidityUp: false,
 		isButtonPressedHumidityDown: false,
 		isButtonPressedClimateUp: false,
@@ -1391,7 +1391,7 @@ Page({
 			return chart;
 		});
 	},
-	
+
 
 
 
@@ -3458,7 +3458,7 @@ Page({
 									obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
 									obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
 									if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
-										
+
 										if (!obj.friendly_name.endsWith("电视")) {
 											listSwitchTemp.push(obj)
 										}
@@ -3892,11 +3892,23 @@ Page({
 			return strR.slice(-6);
 		}
 	},
-	onLoad(option) {
-		console.log("index页面");
-		// wx.clearStorage();
-		// this.setTextBreathing(wx.createSelectorQuery(".header-title-fire"),this);
-		//console.log('option.res='+JSON.stringify(wx.getStorageSync('res')));
+	onReady() {
+		console.log('页面渲染完成')
+		// 获取组件
+		// 确保页面渲染完成后查找节点
+		if (!wx.getStorageSync('hasAuth')) {
+			this.setData({ showAuthorizedDialog: true })
+		} else {
+			this.showData();
+		}
+
+	},
+	authorizationSuccessful() {
+		console.log("授权成功");
+		this.setData({ showAuthorizedDialog: false })
+		this.showData();
+	},
+	showData() {
 		if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
 			wx.showModal({
 				title: '提示',
@@ -3910,106 +3922,6 @@ Page({
 				})
 			}, 2000) // 设置延时时间,单位为毫秒
 		} else {
-
-			var that = this;
-			//  wx.request({
-			// url: `${aipushApi}`+'/getbigreport', 
-			// method: 'POST',
-			//  header: {
-			// 		  'content-type': 'application/json', // 默认值
-			// 		  'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
-			//   },
-			// data:{
-			//     "sn":'',"tokens":token_push
-			// },
-			// success(ress) {
-			// 	if(ress && ress.data){
-			// wx.request({
-			//   url: `${homeApi_https}/states`, //获取空气数据
-			//   method: 'GET',
-			//    header: {
-			// 		  'content-type': 'application/json', // 默认值
-			// 		  'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
-			// 	},
-			//   success(res) {
-			// 	if(!res || !res.data){
-			// 		wx.showModal({
-			// 				title: '提示',
-			// 				content: '请先连接房间wi-fi,再次扫描',
-			// 				showCancel: false
-			// 			  });
-
-			// 		setTimeout(function() {
-			// 		  wx.reLaunch({
-			// 				url: '/pages/scan/scan',
-			// 		  })
-			// 		}, 2000) // 设置延时时间,单位为毫秒
-			// 	}else{
-			// 		// console.log("res.data====="+JSON.stringify(res.data));
-			// 	}
-			//   },
-			// }); 
-			// 		}else{
-			// 			wx.showModal({
-			// 					title: '提示',
-			// 					content: '请先连接房间wi-fi,再次扫描',
-			// 					showCancel: false
-			// 				  });
-
-			// 			setTimeout(function() {
-			// 			  wx.reLaunch({
-			// 					url: '/pages/scan/scan',
-			// 			  })
-			// 			}, 2000) // 设置延时时间,单位为毫秒
-			// 		}
-			// 	},
-			// });
-
-			// const socketUrl = 'http://192.168.3.65:8123';
-			// wx.connectSocket({
-			// 	url: socketUrl,  
-			// 	success: function (res) {  
-			// 	  console.log('WebSocket连接成功', res);  
-			// 	},  
-			// 	fail: function (error) {  
-			// 	  console.error('WebSocket连接打开失败', error);  
-			// 	}  
-			//   });
-			//wi-fi判断
-			// wx.startWifi({
-			//         fail(error) {
-			//           console.log('初始化wifi-失败', error)
-			//         },
-			//         success(res) {
-			//           console.log('初始化wifi-成功', res)
-			//         },
-			// });
-
-
-			//    const expiresAt = wx.getStorageSync('scanResultExpiresAt');  
-			//    const now = Date.now() 
-			//    console.log('expiresAt='+expiresAt);
-			// console.log('now='+now);
-			//    if (expiresAt || expiresAt < now) {  
-			//      // 扫码结果已过期  
-			//      wx.showToast({  
-			//        title: '扫码结果失效或已过期,请重新扫码',  
-			//        icon: 'none'  
-			//      });  
-			//      // 清除过期的扫码结果  
-			//      wx.removeStorageSync('scanResultExpiresAt');  
-			//   setTimeout(function() {
-			//       wx.reLaunch({
-			//       		url: '/pages/scan/scan',
-			//       })
-			//     }, 2000) // 设置延时时间,单位为毫秒
-
-			//    }else{
-			// 	//续期
-			// 	wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
-			// }
-
-
 			let hotelcodeTemp = '';
 			let roomcodeTemp = '';
 			if (wx.getStorageSync('res').result.split('|').length != 2) {
@@ -4045,61 +3957,8 @@ Page({
 			}
 
 		}
-
-
-
-		// else if(!this.data.home_room.includes(wx.getStorageSync('res').result)){
-		// 	  wx.showModal({
-		// 	    title: '提示',
-		// 	    content: '房间二维码不正确,请重新扫描',
-		// 	    showCancel: false
-		// 	  });
-
-		// 	  setTimeout(function() {
-		// 	      wx.reLaunch({
-		// 	      		url: '/pages/scan/scan',
-		// 	      })
-		// 	    }, 2000) // 设置延时时间,单位为毫秒
-		// }
-
-		// this.showCanvasRing();
-
-		// 创建音频上下文  
-		//      this.innerAudioContext = wx.createInnerAudioContext();  
-
-		//      // 设置音频源  
-		//      this.innerAudioContext.src = '你的音频文件链接'; // 替换为你的音频文件链接  
-
-		//      // 监听播放状态  
-		//      this.innerAudioContext.onPlay(() => {  
-		//        this.setData({ isPlaying: true });  
-		//      });  
-		//      this.innerAudioContext.onPause(() => {  
-		//        this.setData({ isPlaying: false });  
-		//      });  
-		//      this.innerAudioContext.onStop(() => {  
-		//        this.setData({ isPlaying: false });  
-		//      });  
-		//      this.innerAudioContext.onError((res) => {
-		//        console.log('res.errorCode='+res.errorCode);  
-		//        console.log('res.errorMsg='+res.errorMsg);  
-		//      });  
-
-		//      // 监听播放进度  
-		//      this.innerAudioContext.onTimeUpdate(() => {  
-		//        this.setData({  
-		//          currentTime: this.innerAudioContext.currentTime,  
-		//          duration: this.innerAudioContext.duration  
-		//        });  
-		//      });
-		// // 初始化歌曲列表
-		//     this.setData({
-		//       songs: [
-		//         { id: 1, title: '歌曲1', artist: '歌手1', url: 'song1.mp3' },
-		//         { id: 2, title: '歌曲2', artist: '歌手2', url: 'song2.mp3' },
-		//         { id: 3, title: '歌曲3', artist: '歌手3', url: 'song3.mp3' }
-		//       ]
-		//     });
+	},
+	onLoad(option) {
 
 	},
 	mounted() {
@@ -4131,13 +3990,6 @@ Page({
 		// if (this.data.observer) {  
 		//   this.data.observer.disconnect();  
 		// } 
-	},
-	onReady() {
-		console.log('页面渲染完成')
-		// 获取组件
-		// 确保页面渲染完成后查找节点
-
-
 	},
 	showLoading: function () {
 		wx.showToast({
@@ -4346,7 +4198,7 @@ Page({
 							const {
 								now
 							} = res.data;
-							
+
 							var weatherBg = "/subpages/images/weather/qing.png"
 							if (now.text.includes("晴")) {
 								weatherBg = "/subpages/images/weather/qing.png"

+ 3 - 0
pages/index/index.wxml

@@ -385,4 +385,7 @@
         style="display: block;width: 56rpx;height: 56rpx; margin: 30rpx auto;" bindtap="onClickHideMenuTabDialog" />
     </view>
   </van-overlay>
+
+  <authorized-login-dialog showDialog="{{showAuthorizedDialog}}"
+    bind:authorizationSuccessful="authorizationSuccessful"></authorized-login-dialog>
 </view>