瀏覽代碼

最新需求修改

htc 1 天之前
父節點
當前提交
3edf18a35a
共有 2 個文件被更改,包括 232 次插入158 次删除
  1. 98 97
      pagesMy/wifiSearch.vue
  2. 134 61
      pagesMy/wifiSet.vue

+ 98 - 97
pagesMy/wifiSearch.vue

@@ -11,7 +11,7 @@
 			<div class="empty adffcac">
 				<div class="title">搜索超时</div>
 				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/5824159f-0bd8-4399-be6c-7d309e2a35dc.png"></image>
-				<div class="tip">没有找到可用设备</div>
+				<div class="tip">没有找到可用设备</div>
 				<div class="warn adfac" @tap="alertShow=true">
 					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/19ca1b06-9bfd-4ae6-9c1c-eec45a86f0a0.png"></image>
 					<span>找不到设备怎么办 ></span>
@@ -24,7 +24,7 @@
 				<div class="title">找不到设备怎么办</div>
 				<p style="margin-top: 53rpx;">1.请确保可配网的设备在手机旁边</p>
 				<p>2.如果没有开机,请先按住开关键直到指示灯亮起</p>
-				<p>3.开机状态下,按住开关键3秒进入配网模式</p>
+				<p>3.开机状态下,按配网键1次进入配网模式</p>
 				<div class="btn" @tap="alertShow=false">我知道了</div>
 			</div>
 		</u-popup>
@@ -32,6 +32,7 @@
 			<div class="connect adffcac">
 				<div class="title">找到一个待配网的设备</div>
 				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/6f06a2de-5d6c-4596-9a0c-77971d6ea230.png"></image>
+				<div class="tip">序列号:{{lanya.deviceId}}</div>
 				<div class="btn" @tap="connectWiFi">连接</div>
 			</div>
 		</u-popup>
@@ -39,116 +40,108 @@
 </template>
 
 <script>
+	var xBlufi = require("@/utils/blufi/xBlufi.js");
+	let _this = null;
 	export default {
 		data(){
 			return {
 				nodevice:false,
 				show:false,
 				alertShow:false,
-				flag:true,
-				deviceWifi:null
+				lanya:null,
+				devicesList: [],
+				searching: false,
 			}
 		},
-		onReady() {
-			this.checkWifi();
+		onLoad: function() {
+			this.Search();
+			_this = this;
+			xBlufi.initXBlufi(1);
+			xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
+		},
+		onUnload() {
+			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
 		},
 		methods:{
-			checkWifi(){
-				let that = this;
-				wx.startWifi({
-					success(res){
-						wx.getConnectedWifi({
-							success(res2){
-								that.nodevice = false;
-								that.deviceModelDeal();
-							},
-							fail: (err2) => {
-								if(err2.errMsg.indexOf('getConnectedWifi:fail:wifi is disable')>-1){
-									that.$showModal('当前WiFi未开启,请先开启WiFi后再进行设备搜索。');
-									that.nodevice = true;
-								}
-							}
-						})
-					},
-					fail: (err) => {
-						that.nodevice = true;
-					}
-				})
-			},
-			deviceModelDeal(){
-				let sysInfo = wx.getSystemInfoSync();
-				this.platform = sysInfo?.platform;
-				if(this.platform=='ios'){
-					uni.showModal({
-						title:'温馨提示',
-						content:'检测到您的手机为ios系统,即将自动跳转设置-微信,需要您在设置中打开无线局域网,等待获取到WiFi列表后再返回小程序进行设备搜索。',
-						success: (res) => {
-							if(res.confirm){
-								this.searchWifi()
+			funListenDeviceMsgEvent: function(options) {
+				switch (options.type) {
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
+						if (options.result)
+							_this.devicesList = options.data;
+							let ly = _this.devicesList.find(d=>d.name=='BLUFI_DEVICE');
+							if(ly){
+								_this.lanya = ly;
+								_this.nodevice = false;
+								_this.show = true;
 							}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
+						if (options.result) {
+							wx.hideLoading()
+							wx.showToast({
+								title: '连接成功',
+								icon: 'none'
+							})
+							wx.navigateTo({
+								url: '/pagesMy/wifiSet?deviceId=' + options.data.deviceId + '&name=' + options
+									.data.name,
+							});
+						} else {
+							wx.hideLoading()
+							wx.showModal({
+							  title: '提示',
+							  content: '连接失败',
+							  showCancel: false
+							});
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
+						if (!options.result) {
+							wx.showToast({
+								title: '蓝牙未开启',
+								icon: 'none'
+							})
+						} else {
+							//蓝牙搜索开始
+							_this.searching = true;
 						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
+						if (options.result) {
+							//蓝牙停止搜索ok
+							console.log('蓝牙停止搜索ok')
+						} else {
+							//蓝牙停止搜索失败
+							console.log('蓝牙停止搜索失败')
+						}
+						_this.searching = false;
+						break;
+				}
+			},
+			Search: function() {
+				if (this.searching) {
+					xBlufi.notifyStartDiscoverBle({
+						'isStart': false
+					})
+				} else {
+					xBlufi.notifyStartDiscoverBle({
+						'isStart': true
 					})
-				}else{
-					this.searchWifi()
 				}
 			},
-			searchWifi(){
-				let that = this;
-				wx.startWifi({
-					success (res) {
-						wx.getWifiList({
-							success(res2) {
-								wx.onGetWifiList(res3 => {
-									let temp = [];
-									res3.wifiList.forEach(w=>{
-										if(w.SSID){
-											let exit = temp.find(t=>t.SSID===w.SSID);
-											if(!exit) temp = [...temp,w]
-										}
-									})
-									that.$nextTick(()=>{
-										let wifi = temp.find(t=>t.SSID.indexOf('Xiaozhi')>-1)
-										if(wifi){
-											that.deviceWifi = wifi;
-											that.show = true;
-										}else{
-											that.nodevice = true;
-										}
-									})
-								})
-							},
-							fail: (err2) => {
-								that.$showModal("getWifiList:err:"+JSON.stringify(err2))
-							}
-						})
-					},
-					fail: (err) => {
-						that.$showModal("startWifi:err:"+JSON.stringify(err))
-					}
+			connectWiFi: function() {
+				//停止搜索
+				xBlufi.notifyStartDiscoverBle({
+					'isStart': false
 				})
-			},
-			searchAgain(){
-				this.nodevice = false;
-				this.deviceModelDeal();
-			},
-			connectWiFi(){
-				if(!this.flag) return
-				this.flag = false;
-				let that = this;
-				wx.connectWifi({
-					SSID: this.deviceWifi.SSID,
-					password: '',
-					success: (res) => {
-						that.flag = true;
-						uni.navigateTo({
-							url:'/pagesMy/wifiSet'
-						})
-					},
-					fail: (err) => {
-						that.flag = true;
-						that.$showModal("connectWifi:err:"+JSON.stringify(err))
-					}
+				xBlufi.notifyConnectBle({
+					isStart: true,
+					deviceId: _this.lanya.deviceId,
+					name:_this.lanya.name
 				});
+				wx.showLoading({
+					title: '连接蓝牙设备中...',
+				})
 			}
 		}
 	}
@@ -274,7 +267,15 @@
 			image{
 				width: 504rpx;
 				height: 254rpx;
-				margin-top: 104rpx;
+				margin-top: 37rpx;
+			}
+			.tip{
+				font-family: PingFangSC, PingFang SC;
+				font-weight: 400;
+				font-size: 30rpx;
+				color: #111111;
+				line-height: 36rpx;
+				margin-top: 40rpx;
 			}
 			.btn{
 				width: 100%;
@@ -287,7 +288,7 @@
 				color: #252525;
 				line-height: 90rpx;
 				text-align: center;
-				margin-top: 110rpx;
+				margin-top: 101rpx;
 				letter-spacing: 2rpx;
 			}
 		}

+ 134 - 61
pagesMy/wifiSet.vue

@@ -1,8 +1,7 @@
 <template>
 	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
 		<cus-header title='配置网络'></cus-header>
-		<div class="title">选择设备要加入的Wi-Fi</div>
-		<div class="tip">设备仅支持使用2.4Hz Wi-Fi连接使用</div>
+		<div class="title">设置Wi-Fi信息</div>
 		<div class="items">
 			<div class="item adfacjb">
 				<div class="il">
@@ -22,8 +21,15 @@
 		</div>
 		<div class="zt_btn" @tap="connectWifi">连接</div>
 		<div class="memo">
-			<p>Wi-Fi密码名称和密码输入错误是最常见的失败原因之一,请仔细检查。</p>
-			<p class="tip">密码必须至少包含8个字符</p>
+			<div class="m_title">配网说明</div>
+			<div class="m_p">
+				1、请注意设备仅支持2.4G的WiFi<br>
+				2、不支持无密码的WiFi连接<br>
+				3、不支持二次授权或者需要网页二次登录的WiFi<br>
+				4、如果使用手机热点连接,请确保手机热点正常开启<br>
+				5、如果使用iPhone热点,请确保热点开启了最大兼容模式<br>
+				6、iPhone热点因为低功耗,一段时间不使用,热点将会自动关闭,如果无法连接,请重新打开热点
+			</div>
 		</div>
 		<u-popup :show="show" :round="56" mode="center" @close="show=false">
 			<div class="wifis">
@@ -37,8 +43,8 @@
 				<div class="list" v-if="wifiList.length">
 					<div class="item adfacjb" v-for="(item,index) in wifiList" :key="index">
 						<div class="il adfac">
-								<image src="@/static/wifi.png"></image>
-							<text>{{item.ssid}}</text>
+							<image src="@/static/wifi.png"></image>
+							<text>{{item}}</text>
 						</div>
 						<div class="ir" @tap="selectWifi(item)">选择</div>
 					</div>
@@ -52,11 +58,16 @@
 </template>
 
 <script>
+	var xBlufi = require("@/utils/blufi/xBlufi.js");
 	import pageEmpty from '@/components/pageEmpty/index.vue'
 	export default {
 		components:{pageEmpty},
 		data(){
 			return {
+				name: '',
+				connectedDeviceId: '',
+				connected: true,
+				isInitOK: false,
 				wifiSSID:'',
 				wifiPWD:'',
 				isPwd:true,
@@ -64,53 +75,122 @@
 				wifiList:[]
 			}
 		},
+		onLoad: function(options) {
+			var that = this
+			this.name = options.name;
+			this.connectedDeviceId = options.deviceId;
+			xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
+			xBlufi.notifyInitBleEsp32({
+				deviceId: options.deviceId,
+			})
+			wx.showLoading({
+				title: '设备初始化中',
+			})
+		},
+		onUnload: function() {
+			let that = this
+			xBlufi.notifyConnectBle({
+				isStart: false,
+				deviceId: that.connectedDeviceId,
+				name: that.name,
+			});
+			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
+		},
 		methods:{
+			funListenDeviceMsgEvent: function(options) {
+				let that = this
+				let ssid_arry = this.wifiList;
+				switch (options.type) {
+					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
+						that.connected = options.result
+						if (!options.result) {
+							wx.showModal({
+								title: '很抱歉提醒你!',
+								content: '小程序与设备异常断开',
+								showCancel: false, //是否显示取消按钮
+							})
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
+						wx.hideLoading();
+						if (!options.result)
+							wx.showModal({
+								title: '温馨提示',
+								content: '配网失败,请重试',
+								showCancel: false,
+							})
+						else {
+							if (options.data.progress == 100) {
+								uni.navigateTo({
+									url:'/pagesMy/wifiSuccess'
+								})
+							}
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
+						wx.showModal({
+							title: '收到自定义设备数据',
+							content: `【${options.data}】`,
+							showCancel: false,
+						})
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_NEAR_ROUTER_LISTS:
+						wx.hideLoading();
+						if ('' === options.data.SSID) break;
+						if(!ssid_arry.includes(options.data.SSID)) ssid_arry.push(options.data.SSID)
+						that.wifiList = ssid_arry;
+						that.wifiSSID = that.wifiList[0];
+						that.isInitOK = true
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
+						wx.hideLoading();
+						if (options.result) {
+							xBlufi.notifySendGetNearRouterSsid()
+							wx.showLoading({
+								title: '获取周围WiFi列表...',
+							})
+						} else {
+							that.connected = false
+							wx.showModal({
+								title: '温馨提示',
+								content: `设备初始化失败`,
+								showCancel: false, //是否显示取消按钮
+							})
+						}
+						break;
+				}
+			},
 			changePwd(){
 				this.isPwd = !this.isPwd;
 			},
+			initWiFi(){
+				xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
+				xBlufi.notifyInitBleEsp32({
+					deviceId: this.connectedDeviceId,
+				})
+			},
 			connectWifi(){
+				let that = this;
 				if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
 				if(!this.wifiPWD) return this.$showToast('请输入Wi-Fi密码')
-				uni.navigateTo({
-					url:`/pagesMy/wifiConnect?wifiSSID=${this.wifiSSID}&wifiPWD=${this.wifiPWD}`
+				wx.showLoading({
+					title: '正在配网...',
+					mask: true
+				})
+				xBlufi.notifySendRouterSsidAndPassword({
+					ssid: that.wifiSSID,
+					password: that.wifiPWD
 				})
 			},
 			toSelectWifi(){
 				this.show = true;
-				this.initWiFi();
-			},
-			initWiFi(){
-				uni.showLoading({
-					title:'获取WiFi列表中'
-				})
-				let that = this;
-				wx.request({
-					url:'http://192.168.4.1/scan',
-					success:res=>{
-						uni.hideLoading();
-						if(res.errMsg==='request:ok'){
-							let temp = [];
-							res.data.forEach(w=>{
-								if(w.ssid&&w.ssid.indexOf('Xiaozhi')<0){
-									let exit = temp.find(t=>t.ssid===w.ssid);
-									if(!exit) temp = [...temp,w]
-								}
-							})
-							that.$nextTick(()=>{
-								that.wifiList = temp;
-								that.$forceUpdate();
-								uni.hideLoading();
-							})
-						}
-					},
-					fail:err=>{
-						uni.hideLoading();
-					}
-				})
 			},
 			selectWifi(item){
-				this.wifiSSID = item.ssid;
+				this.wifiSSID = item;
+				let password = wx.getStorageSync(item)
+				this.wifiPWD = password || '';
 				this.show = false;
+				this.isInitOK = true
 			}
 		}
 	}
@@ -129,16 +209,8 @@
 			line-height: 36rpx;
 			margin-top: 64rpx;
 		}
-		&>.tip{
-			font-family: PingFangSC, PingFang SC;
-			font-weight: 400;
-			font-size: 26rpx;
-			color: #111111;
-			line-height: 32rpx;
-			margin-top: 36rpx;
-		}
 		.items{
-			margin-top: 96rpx;
+			margin-top: 188rpx;
 			.item{
 				margin-top: 80rpx;
 				padding-bottom: 30rpx;
@@ -178,22 +250,21 @@
 			margin-top: 100rpx;
 		}
 		.memo{
-			width: calc(100% - 80rpx);
-			position: fixed;
-			left: 40rpx;
-			bottom: 100rpx;
-			p{
+			margin-top: 100rpx;
+			.m_title{
 				font-family: PingFangSC, PingFang SC;
-				font-weight: 600;
+				font-weight: 400;
 				font-size: 26rpx;
 				color: #111111;
 				line-height: 40rpx;
-				&.tip{
-					font-weight: 400;
-					color: #7C8592;
-					line-height: 42rpx;
-					margin-top: 8rpx;
-				}
+			}
+			.m_p{
+				font-family: PingFangSC, PingFang SC;
+				font-weight: 400;
+				font-size: 24rpx;
+				color: #7C8592;
+				line-height: 54rpx;
+				margin-top: 10rpx;
 			}
 		}
 		.ph{
@@ -202,8 +273,9 @@
 	
 		.wifis{
 			width: 670rpx;
-			max-height: 740rpx;
+			max-height: 720rpx;
 			overflow: hidden;
+			padding-bottom: 20rpx;
 			.top{
 				margin-top: 14rpx;
 				padding: 40rpx;
@@ -234,6 +306,7 @@
 				height: 609rpx;
 				overflow-y: auto;
 				padding: 30rpx 40rpx;
+				box-sizing: border-box;
 				.item{
 					width: 100%;
 					height: 120rpx;