|
@@ -1,8 +1,7 @@
|
|
<template>
|
|
<template>
|
|
<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
|
|
<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
|
|
<cus-header title='配置网络'></cus-header>
|
|
<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="items">
|
|
<div class="item adfacjb">
|
|
<div class="item adfacjb">
|
|
<div class="il">
|
|
<div class="il">
|
|
@@ -22,8 +21,15 @@
|
|
</div>
|
|
</div>
|
|
<div class="zt_btn" @tap="connectWifi">连接</div>
|
|
<div class="zt_btn" @tap="connectWifi">连接</div>
|
|
<div class="memo">
|
|
<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>
|
|
</div>
|
|
<u-popup :show="show" :round="56" mode="center" @close="show=false">
|
|
<u-popup :show="show" :round="56" mode="center" @close="show=false">
|
|
<div class="wifis">
|
|
<div class="wifis">
|
|
@@ -37,8 +43,8 @@
|
|
<div class="list" v-if="wifiList.length">
|
|
<div class="list" v-if="wifiList.length">
|
|
<div class="item adfacjb" v-for="(item,index) in wifiList" :key="index">
|
|
<div class="item adfacjb" v-for="(item,index) in wifiList" :key="index">
|
|
<div class="il adfac">
|
|
<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>
|
|
<div class="ir" @tap="selectWifi(item)">选择</div>
|
|
<div class="ir" @tap="selectWifi(item)">选择</div>
|
|
</div>
|
|
</div>
|
|
@@ -52,11 +58,16 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+ var xBlufi = require("@/utils/blufi/xBlufi.js");
|
|
import pageEmpty from '@/components/pageEmpty/index.vue'
|
|
import pageEmpty from '@/components/pageEmpty/index.vue'
|
|
export default {
|
|
export default {
|
|
components:{pageEmpty},
|
|
components:{pageEmpty},
|
|
data(){
|
|
data(){
|
|
return {
|
|
return {
|
|
|
|
+ name: '',
|
|
|
|
+ connectedDeviceId: '',
|
|
|
|
+ connected: true,
|
|
|
|
+ isInitOK: false,
|
|
wifiSSID:'',
|
|
wifiSSID:'',
|
|
wifiPWD:'',
|
|
wifiPWD:'',
|
|
isPwd:true,
|
|
isPwd:true,
|
|
@@ -64,53 +75,122 @@
|
|
wifiList:[]
|
|
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:{
|
|
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(){
|
|
changePwd(){
|
|
this.isPwd = !this.isPwd;
|
|
this.isPwd = !this.isPwd;
|
|
},
|
|
},
|
|
|
|
+ initWiFi(){
|
|
|
|
+ xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
|
|
|
+ xBlufi.notifyInitBleEsp32({
|
|
|
|
+ deviceId: this.connectedDeviceId,
|
|
|
|
+ })
|
|
|
|
+ },
|
|
connectWifi(){
|
|
connectWifi(){
|
|
|
|
+ let that = this;
|
|
if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
|
|
if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
|
|
if(!this.wifiPWD) 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(){
|
|
toSelectWifi(){
|
|
this.show = true;
|
|
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){
|
|
selectWifi(item){
|
|
- this.wifiSSID = item.ssid;
|
|
|
|
|
|
+ this.wifiSSID = item;
|
|
|
|
+ let password = wx.getStorageSync(item)
|
|
|
|
+ this.wifiPWD = password || '';
|
|
this.show = false;
|
|
this.show = false;
|
|
|
|
+ this.isInitOK = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -129,16 +209,8 @@
|
|
line-height: 36rpx;
|
|
line-height: 36rpx;
|
|
margin-top: 64rpx;
|
|
margin-top: 64rpx;
|
|
}
|
|
}
|
|
- &>.tip{
|
|
|
|
- font-family: PingFangSC, PingFang SC;
|
|
|
|
- font-weight: 400;
|
|
|
|
- font-size: 26rpx;
|
|
|
|
- color: #111111;
|
|
|
|
- line-height: 32rpx;
|
|
|
|
- margin-top: 36rpx;
|
|
|
|
- }
|
|
|
|
.items{
|
|
.items{
|
|
- margin-top: 96rpx;
|
|
|
|
|
|
+ margin-top: 188rpx;
|
|
.item{
|
|
.item{
|
|
margin-top: 80rpx;
|
|
margin-top: 80rpx;
|
|
padding-bottom: 30rpx;
|
|
padding-bottom: 30rpx;
|
|
@@ -178,22 +250,21 @@
|
|
margin-top: 100rpx;
|
|
margin-top: 100rpx;
|
|
}
|
|
}
|
|
.memo{
|
|
.memo{
|
|
- width: calc(100% - 80rpx);
|
|
|
|
- position: fixed;
|
|
|
|
- left: 40rpx;
|
|
|
|
- bottom: 100rpx;
|
|
|
|
- p{
|
|
|
|
|
|
+ margin-top: 100rpx;
|
|
|
|
+ .m_title{
|
|
font-family: PingFangSC, PingFang SC;
|
|
font-family: PingFangSC, PingFang SC;
|
|
- font-weight: 600;
|
|
|
|
|
|
+ font-weight: 400;
|
|
font-size: 26rpx;
|
|
font-size: 26rpx;
|
|
color: #111111;
|
|
color: #111111;
|
|
line-height: 40rpx;
|
|
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{
|
|
.ph{
|
|
@@ -202,8 +273,9 @@
|
|
|
|
|
|
.wifis{
|
|
.wifis{
|
|
width: 670rpx;
|
|
width: 670rpx;
|
|
- max-height: 740rpx;
|
|
|
|
|
|
+ max-height: 720rpx;
|
|
overflow: hidden;
|
|
overflow: hidden;
|
|
|
|
+ padding-bottom: 20rpx;
|
|
.top{
|
|
.top{
|
|
margin-top: 14rpx;
|
|
margin-top: 14rpx;
|
|
padding: 40rpx;
|
|
padding: 40rpx;
|
|
@@ -234,6 +306,7 @@
|
|
height: 609rpx;
|
|
height: 609rpx;
|
|
overflow-y: auto;
|
|
overflow-y: auto;
|
|
padding: 30rpx 40rpx;
|
|
padding: 30rpx 40rpx;
|
|
|
|
+ box-sizing: border-box;
|
|
.item{
|
|
.item{
|
|
width: 100%;
|
|
width: 100%;
|
|
height: 120rpx;
|
|
height: 120rpx;
|