From a66290c5a17f8d6c8f0054752aeb091bb8fd292d Mon Sep 17 00:00:00 2001
From: "3321822538@qq.com" <3321822538@qq.com>
Date: Fri, 27 Sep 2024 18:01:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E8=AE=BE=E5=A4=87=E4=B8=BB?=
 =?UTF-8?q?=E5=9B=BE=20=E5=BD=95=E5=85=A5=E8=B7=B3=E8=BD=AC=E6=8E=A7?=
 =?UTF-8?q?=E5=88=B6=E8=AE=BE=E5=A4=87=E9=A1=B5=20=E6=96=B0=E5=A2=9E?=
 =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=A7=E5=88=B6=E9=A1=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 common/http.interceptor.js        |   4 +-
 page_components/bindsz.vue        |  31 +-
 page_components/bindszthr.vue     |   2 +-
 page_fenbao/device/joinDevice.vue |  27 +-
 page_user/wifijoint/index.vue     | 540 +++++++++++++++---------------
 pages/index/index.vue             |  11 +-
 pages/shouye/index.vue            |   1 +
 7 files changed, 299 insertions(+), 317 deletions(-)

diff --git a/common/http.interceptor.js b/common/http.interceptor.js
index dec621d..9c734f5 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.81:10002',
-			// baseUrl: 'https://kg.chuangtewl.com/prod-api',
+			// baseUrl: 'http://192.168.2.81:10002',
+			baseUrl: 'https://kg.chuangtewl.com/prod-api',
 			// loadingText: '努力加载中~',
 			// loadingTime: 1000,
 			// 设置自定义头部content-type
diff --git a/page_components/bindsz.vue b/page_components/bindsz.vue
index aeb8c99..b2224cc 100644
--- a/page_components/bindsz.vue
+++ b/page_components/bindsz.vue
@@ -120,9 +120,9 @@
 				isMch: false,
 				taocan: '',
 				token: '',
-				userImgs: 'https://api.ccttiot.com/FgwOJJPjHwS-5SsfCvIIuOPfh0A_',
+				userImgs: '',
 				url: '',
-				modelid:''
+				modelid:[]
 			}
 		},
 		onLoad(option) {
@@ -182,20 +182,21 @@
 					this.$u.put('/app/device', data).then((res) => {
 						if (res.code == 200) {
 							this.getDevice()
-							this.modelid.forEach(item => {
-								if(item == 2){
-									uni.navigateTo({
-										url: '/page_components/bindsztwo?id=' + this.id
-									})
-								}else{
-									uni.navigateTo({
-										url:'/page_components/bindszthr?id=' + this.id
-									})
-								}
-							})
+							if (this.modelid.some(item => item == 2)) {  
+							    console.log('wifi');  
+							    uni.navigateTo({  
+							        url: '/page_components/bindsztwo?id=' + this.id  
+							    });  
+							} else {  
+							    console.log('4g');  
+							    uni.navigateTo({  
+							        url: '/page_components/bindszthr?id=' + this.id  
+							    });  
+							}
 						}
 					})
 				}
+				
 
 			},
 			btntiao() {
@@ -386,9 +387,7 @@
 					if (res.code == 200) {
 						this.listobj = res.data
 						this.xgname = this.listobj.deviceName
-						if (res.data.customPicture) {
-							this.userImgs = res.data.customPicture
-						}
+						this.userImgs = res.data.picture
 					}
 				})
 			},
diff --git a/page_components/bindszthr.vue b/page_components/bindszthr.vue
index 02d8d3c..86a2e14 100644
--- a/page_components/bindszthr.vue
+++ b/page_components/bindszthr.vue
@@ -216,7 +216,7 @@
 						success: function(res) {
 							if (res.confirm) {
 								this.btnmsk = false
-								uni.reLaunch({
+								uni.switchTab({
 									url:'/pages/index/index'
 								})
 							} 
diff --git a/page_fenbao/device/joinDevice.vue b/page_fenbao/device/joinDevice.vue
index 7330f16..befe9ed 100644
--- a/page_fenbao/device/joinDevice.vue
+++ b/page_fenbao/device/joinDevice.vue
@@ -17,7 +17,6 @@
 			</view>
 			<input type="text" class="ips" v-model="storeId" placeholder="请扫描设备上的二维码" style="margin-left: 32rpx;"
 				placeholder-class="my-placeholder" />
-
 		</view>
 		<view class="iptbox" @click="show=true">
 			<!-- <view class="" v-if="hardwareInfo.version">
@@ -282,8 +281,13 @@
 							icon: 'success',
 							duration: 2000
 						})
+						wx.closeBLEConnection({
+							deviceId: this.deviceId,
+						})
 						setTimeout(()=>{
-							uni.navigateBack()
+							uni.navigateTo({
+								url:'/page_user/wifijoint/index?sn=' + this.storeId
+							})
 						},1500)
 					} else {
 						uni.showToast({
@@ -739,25 +743,6 @@
 			btnhd() {
 				this.tishiflag = false
 			},
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 		}
 	}
 </script>
diff --git a/page_user/wifijoint/index.vue b/page_user/wifijoint/index.vue
index a3ad294..513bbc2 100644
--- a/page_user/wifijoint/index.vue
+++ b/page_user/wifijoint/index.vue
@@ -1,78 +1,79 @@
 <template>
 	<view class="">
-		<u-navbar title="WIFI连接" :border-bottom="false" :background="bgc" title-color='#fff' back-icon-color="#fff" title-size='36'
+		<u-navbar title="设备控制" :border-bottom="false" :background="bgc" title-color='#262B37' back-icon-color="#262B37" title-size='36'
 			height='50'></u-navbar>
-		<view class="container">
-			<view class="device">
-				<span class="device-list-title">WIFI连接</span>
+        <view class="title">
+        	控制台
+        </view>
+		<view class="shuom">
+			请扫描设备上的二维码
+		</view>
+		<view class="iptbox">
+			<view class="qrcode" @click="qrcode()">
+				<image src="https://api.ccttiot.com/smartmeter/img/static/uy7BNwAMIKwvstqFnRhs" mode=""></image>
 			</view>
-			<view class="flex-row items-center flex-1 group">
-				<text class="text_3 ml-3">请输入您的WiFi名称和密码</text>
-			</view>
-
-			<!-- wifi信息 -->
-			<view class="wifibd">
-				<view class="name">
-					<text>您的WiFi网络名称</text>
-					<input type="text" v-model="name" placeholder="请输入您的WiFi网络名称" />
+			<input type="text" class="ips" v-model="storeId" placeholder="请扫描设备上的二维码" style="margin-left: 32rpx;"
+				placeholder-class="my-placeholder" />
+		</view>
+		<view class="machao">
+			MAC号:{{obj.mac == undefined ? '--' : obj.mac}}
+		</view>
+		<view class="machao">
+			电压:{{obj.voltage == undefined ? '--' : obj.voltage}}V
+		</view>
+		<view class="machao">
+			功率:{{obj.realTimePower == undefined ? '--' : obj.realTimePower}}KW
+		</view>
+		<view class="machao">
+			电流:{{obj.electricity == undefined ? '--' : obj.electricity}}A
+		</view>
+		<view class="machao">
+			网络:<text v-if="onlineStatus == '离线'" style="color: red;">离线</text> <text v-if="onlineStatus == '在线'" style="color: green;">在线</text>
+		</view>
+		<view class="machao">
+			状态:<text v-if="powerStatus == '关闭'" style="color: red;">关闭</text> <text v-if="powerStatus == '开启'" style="color: green;">开启</text>
+		</view>
+		<view class="machao">
+			最后在线时间:{{obj.lastOnlineTime == undefined ? '--' : obj.lastOnlineTime}}
+		</view>
+		
+		<view class="list">
+			<view class="anniulist">
+				<view class="anniu" @click="btnkq">
+					开启
 				</view>
- 
-				<view class="pwd"> 
-					<text>密码</text>
-					<input type="text" v-model="password" placeholder="请输入您的WiFi密码" />
+				<view class="anniu" @click="btngb">
+					关闭
+				</view>
+				<view class="anniu" @click="btnsx">
+					刷新
 				</view>
 			</view>
-			<!-- 点击连接 -->
-			<view class="button" @click="content_wf">连接</view>
-
-			<!-- 加载状态 -->
-			<view class="containers" v-show="statusflag">
-				<uni-section>
-					<uni-load-more :status="status"/>
-				</uni-section>
+			<view class="fanhui" @click="btnfh">
+				返回录入
 			</view>
 		</view>
+		
 	</view>
-
 </template>
 
 <script>
-	var xBlufi = require("@/page_components/blufi/xBlufi.js")
-	// import { getwifi } from '@/api/index.js'
 	export default {
 		data() {
 			return {
-				name: '',
-				password: '',
-				options: '',
-				falg: 0,
-				objlist: '',
-				statusflag: false,
-				status: 'loading',
 				bgc: {
-					backgroundColor: "#8883f0",
+					backgroundColor: "#F7FAFE",
 				},
+				storeId: '',
+				obj:{},
+				id:'',
+				onlineStatus:'--',
+				powerStatus:'--'
 			}
-
 		},
 		onLoad(options) {
-			this.name = JSON.parse(options.ssid)
-			this.options = options
-			this.objlist = JSON.parse(options.objlist)
-			// console.log("获取到id",JSON.parse(this.options.objlist.deviceId))
-			console.log("this.objlist.deviceId", this.objlist.deviceId)
-			xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
-			xBlufi.notifyInitBleEsp32({
-				deviceId: this.objlist.deviceId
-			})
-
-		},
-		onReady() {},
-		onUnload() {
-			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
-			// wx.closeBLEConnection({
-			// 	deviceId: this.objlist.deviceId,
-			// })
+            this.storeId = options.sn
+			this.getsn()
 		},
 		// 分享到好友(会话)
 		  onShareAppMessage: function () {  
@@ -91,232 +92,229 @@
 		    }  
 		  },
 		methods: {
-			content_wf() {
-				if (!this.name) {
-					uni.showToast({
-						title: 'SSID不能为空',
-						icon: 'none'
-					});
-					return;
-				}
-				if (!this.password) {
-					uni.showToast({
-						title: '密码不能为空',
-						icon: 'none'
-					});
-					return;
-				}
-				uni.showLoading({
-					title: '正在配网',
-					mask: true
-				})
-                xBlufi.notifySendCustomData({
-                      customData: "ssid@" + this.name + "pass@" + this.password
-                 })
-				// xBlufi.notifySendCustomData({
-				// 	customData: "ssid@" + this.name
-				// })
-
-				// xBlufi.notifySendCustomData({
-				// 	customData: "pass@" + this.password
-				// })
-
-			},
-
-			funListenDeviceMsgEvent: function(options) {
-				let that = this;
-				switch (options.type) {
-					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: {
-						console.log('状态', options.result)
-						uni.showModal({
-							title: '很抱歉提醒你!',
-							content: '小程序与设备异常断开', 
-							showCancel: false,
-							success: function(res) {
-								uni.navigateTo({
-									url:'/pages/index/index'
-								})
-							}
-						});
-						this.statusflag = false
-						uni.hideLoading();
+             qrcode() {
+             	uni.scanCode({
+             		onlyFromCamera: true,
+             		scanType: ['qrCode'],
+             		success: res => {
+             			function getQueryParam(url, paramName) {
+             				let regex = new RegExp(`[?&]${paramName}=([^&]*)`)
+             				let results = regex.exec(url);
+             				return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null
+             			}
+             			let sceneValue = res.result
+             			let decodedValue = decodeURIComponent(sceneValue)
+             			let id = getQueryParam(decodedValue, 's')
+             			this.storeId = id
+						this.getsn()
+             		},
+             		fail: err => {
+             			console.error('扫描失败:', err)
+             			uni.showToast({
+             				title: '扫描失败',
+             				icon: 'none'
+             			})
+             		}
+             	})
+             },
+			 
+			 getsn(){
+				 this.$u.get(`/app/device/${this.storeId}/bySn`).then(res => {
+				 	if (res.code == 200) {
+				 		this.obj = res.data
+						this.id = res.data.deviceId
+						if(res.data.onlineStatus == 0){
+							this.onlineStatus = '离线'
+						}else if(res.data.onlineStatus == 1){
+							this.onlineStatus = '在线'
+						}
+						if(res.data.powerStatus == 0){
+							this.powerStatus = '关闭'
+						}else if(res.data.powerStatus == 1){
+							this.powerStatus = '开启'
+						}
+						uni.showToast({
+							title: res.msg,
+							icon: 'success',
+							duration: 2000,
+						})
+				 	}else{
+						uni.showToast({
+							title: res.msg,
+							icon: 'none',
+							duration: 2000,
+						})
 					}
-					break;
+				 })
+			 },
+			 
+			 // 返回录入
+			 btnfh(){
+				uni.navigateBack({
+					delta:2
+				})
+			 },
+			 
+			 // 开启
+			 btnkq(){
+				 this.$u.put(`/app/device/admin/${this.id}/switch?open=true`).then((res) => {
+				 	if (res.code == 200) {
+						this.getsn()
+				 		uni.showToast({
+				 			title: res.msg,
+				 			icon: 'success',
+				 			duration: 2000
+				 		})
+				 	} else {
+				 		uni.showToast({
+				 			title: res.msg,
+				 			icon: 'none',
+				 			duration: 2000
+				 		})
+				 	}
+				 })
+			 },
+			 // 关闭
+			 btngb(){
+				 this.$u.put(`/app/device/admin/${this.id}/switch?open=false`).then((res) => {
+				 	if (res.code == 200) {
+						this.getsn()
+				 		uni.showToast({
+				 			title: res.msg,
+				 			icon: 'success',
+				 			duration: 2000
+				 		})
+				 	} else {
+				 		uni.showToast({
+				 			title: res.msg,
+				 			icon: 'none',
+				 			duration: 2000
+				 		})
+				 	}
+				 })
+			 },
+			 // 刷新
+			 btnsx(){
+				 this.$u.get(`/app/device/${this.id}/refreshIot`).then((res) => {
+					 if(res.code == 200){
+						 this.getsn()
+						 uni.showToast({
+						 	title: res.msg,
+						 	icon: 'success',
+						 	duration: 2000
+						 })
+					 }else{
+						 uni.showToast({
+						 	title: res.msg,
+						 	icon: 'none',
+						 	duration: 2000
+						 })
+					 }
+				 })
+			 }
 
-					case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
-						uni.hideLoading();
-						if (!options.result)
-							this.statusflag = false,
-							uni.hideLoading(),
-							uni.showModal({
-								title: '温馨提示',
-								content: '配网失败,请重试',
-								showCancel: false //是否显示取消按钮
-							});
-						else {
-							if (options.data.progress == 100) {
-								let ssid = options.data.ssid;
-								this.statusflag = false
-								uni.hideLoading();
-								uni.showModal({
-									title: '温馨提示',
-									content: `连接成功`,
-									showCancel: false,
-									success: function(res) {
-										uni.switchTab({
-											url: '/pages/index/index'
-										})
-										// let ids = that.$store.state.user.deviceId
-										wx.closeBLEConnection({
-											deviceId: this.objlist.deviceId,
-										})
-										
-										// getwifi(ids).then(res => {
-										// 	console.log(res);
-										// 	uni.switchTab({
-										// 		url:'/pages/index/index'
-										// 	})
-										// })
-									}
-								})
-							}
-						}
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_MY_DATA:
-						this.loadPercent = options.data;
-						this.loadText = '文件读取中'
-						console.log("文件读取中", options.data);
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
-
-						this.ver_data = this.parseCustomData(options.data)
-						console.log("1收到设备发来的自定义数据结果:", this.ver_data);
-						break;
-
-					case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
-						uni.hideLoading();
-						if (options.result) {
-							console.log('初始化成功');
-						} else {
-							console.log('初始化失败');
-							uni.showModal({
-								title: '温馨提示',
-								content: `设备初始化失败`,
-								showCancel: false,
-								//是否显示取消按钮
-								success: function(res) {
-									// uni.redirectTo({
-									// 	url: '../search/search'
-									// });
-								}
-							});
-						}
-						break;
-				}
-			},
-			// 解析自定义数据
-			parseCustomData(data) {
-				// 将字符串按照 "@" 分割成数组
-				const dataArray = data.split('@');
-
-				// 根据约定,解析各个字段的值
-				const voltage = parseFloat(dataArray[0].substring(1)); // 去除前缀 "V",并将字符串转换为浮点数
-				const switchState = dataArray[1].substring(1); // 去除前缀 "S"
-				const current = parseFloat(dataArray[2].substring(1)); // 去除前缀 "A",并将字符串转换为浮点数
-				const power = parseFloat(dataArray[4].substring(1)); // 去除前缀 "P",并将字符串转换为浮点数
-				const remainingPower = parseFloat(dataArray[5].substring(1)); // 去除前缀 "M",并将字符串转换为浮点数
-				const setMode = dataArray[6].substring(3); // 去除前缀 "SET"
-
-				// 返回解析后的数据对象
-				return {
-					voltage,
-					switchState,
-					current,
-					power,
-					remainingPower,
-					setMode
-				};
-			}
+		
 		}
 	}
 </script>
 
 <style lang="less">
-	.containers {
-		width: 100%;
-		height: 100vh;
+	.list{
 		position: fixed;
-		top: 220rpx;
-		left: 0;
-		z-index: 999 !important;
-	}
-
-
-	.pwd,
-	.name {
-		text {
-			color: #3D3D3D;
-			font-size: 32rpx;
-			margin-top: 30rpx;
-			display: block;
-			line-height: 30rpx;
-		}
-
-		input {
-			margin-top: 10rpx;
-			color: rgba(80, 86, 90, 1);
-			font-size: 14px;
-			border-bottom: 1px solid #ccc;
-			height: 60rpx;
-			line-height: 60rpx;
-		}
-
-		input::placeholder {
-			font-size: 14px;
-		}
-	}
-
-	.wifibd {
-		margin-top: 182rpx;
-	}
-
-	.device-list-title {
-		color: #50565a;
-		font-size: 86rpx;
-		font-family: SourceHanSansCN;
-		// margin-top: 100rpx;
-	}
-
-	.text_3 {
-		margin-top: 10rpx;
-		color: rgba(119, 128, 141, 1);
-		font-size: 28rpx;
-	}
-
-	.container {
-		/* padding-top: 30rpx !important; */
-		padding: 40rpx 30rpx 0 30rpx !important;
-		box-sizing: border-box;
-		align-items: center;
-	}
-
-	.button {
-		position: fixed;
-		display: flex;
-		align-items: center;
-		justify-content: center;
+		bottom: 50rpx;
 		left: 50%;
 		transform: translateX(-50%);
-		bottom: 50rpx;
-		height: 96rpx;
-		//margin-top: -100rpx;
-		padding: 10rpx 0;
-		box-sizing: border-box;
-		background-color: #8883F0 !important;
-		border-radius: 52rpx 52rpx 52rpx 52rpx;
-		font-weight: 700;
-		font-size: 20px;
-		width: 622rpx;
-		color: #FFFFFF;
+		.anniulist{
+			width: 658rpx;
+			margin: auto;
+			margin-top: 200rpx;
+			text-align: left;
+			font-size: 32rpx;
+			display: flex;
+			justify-content: space-between;
+			.anniu{
+				width: 30%;
+				height: 90rpx;
+				border-radius: 20rpx;
+				background-color: #8883f0;
+				color: #fff;
+				font-size: 32rpx;
+				text-align: center;
+				line-height: 90rpx;
+			}
+		}
+		.fanhui{
+			width: 658rpx;
+			height: 90rpx;
+			border-radius: 20rpx;
+			background-color: #8883f0;
+			color: #fff;
+			font-size: 32rpx;
+			text-align: center;
+			line-height: 90rpx;
+			margin: auto;
+			margin-top: 50rpx;
+		}
 	}
+	.machao{
+		width: 658rpx;
+		margin: auto;
+		margin-top: 20rpx;
+		text-align: left;
+		font-size: 32rpx;
+	}
+	.title{
+		font-size: 70rpx;
+		font-weight: 600;
+		text-align: left;
+		width: 658rpx;
+		margin: auto;
+		margin-top: 30rpx;
+	}
+	.shuom{
+		width: 658rpx;
+		margin: auto;
+		margin-top: 30rpx;
+		text-align: left;
+		font-size: 32rpx;
+	}
+	.iptbox {
+		display: flex;
+		align-items: center;
+		flex-wrap: nowrap;
+		padding: 22rpx;
+		margin: 28rpx auto 0;
+		width: 658rpx;
+		height: 88rpx;
+		background: #FFFFFF;
+		box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.15);
+		border-radius: 20rpx 20rpx 20rpx 20rpx;
+	
+		.qrcode {
+			padding-right: 20rpx;
+			border-right: 2rpx solid #D8D8D8;
+	
+			image {
+				width: 54rpx;
+				height: 54rpx;
+			}
+		}
+	
+		.ips {
+			width: 630rpx;
+	
+		}
+	
+		image {
+			width: 18rpx;
+			height: 32rpx;
+		}
+	
+		.my-placeholder {
+			font-weight: 400;
+			font-size: 32rpx;
+			color: #808080;
+		}
+	}
+      
 </style>
\ No newline at end of file
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 1ff14ac..3bcc5f8 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -133,7 +133,7 @@
 								<view class="card_right" @click="todetail(item.deviceId)">
 									<image v-if="item.customPicture" :src="item.customPicture" mode="aspectFit"
 										style="border-radius: 20rpx;"></image>
-									<image v-else :src="item.picture" mode=""></image>
+									<image v-else :src="item.picture" mode="aspectFit"></image>
 								</view>
 							</view>
 						</view>
@@ -581,7 +581,7 @@
 							// })
 							this.shibaiflag = false
 							this.bluetoothflag = false
-							uni.hideLoading();
+							uni.hideLoading()
 							uni.removeStorageSync('mac');
 							let systemInfo = uni.getSystemInfoSync()
 							if (systemInfo.platform == 'android') {
@@ -622,6 +622,7 @@
 					})
 				}
 			},
+			
 			btnwifi(mac){
 				this.qrResult = mac
 				this.btnmsk = false
@@ -708,14 +709,12 @@
 							if (systemInfo.platform == 'android') {
 								// 当前设备是 Android  
 								uni.navigateTo({
-									url: '/page_components/wifilist/index?deviceId=' + this.deviceId +
-										'&name=' + this.name
+									url: '/page_components/wifilist/index?deviceId=' + this.deviceId +'&name=' + this.name
 								})
 							} else if (systemInfo.platform == 'ios') {
 								// 当前设备是 iOS  
 								uni.navigateTo({
-									url: '/page_fenbao/device/wifivideo?deviceId=' + this.deviceId +
-										'&name=' + this.name
+									url: '/page_fenbao/device/wifivideo?deviceId=' + this.deviceId +'&name=' + this.name
 								})
 							}
 						} else {
diff --git a/pages/shouye/index.vue b/pages/shouye/index.vue
index 5ec941f..a40282b 100644
--- a/pages/shouye/index.vue
+++ b/pages/shouye/index.vue
@@ -627,6 +627,7 @@
 					}
 				});
 			},
+			
 			addMarkersWithLabels() {
 				this.listmap.forEach((item) => {
 					if (item.deviceCount !== null && item.deviceCount > 0) {