mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
添加部分页面
This commit is contained in:
141
wechat/miniprogram/pages/4Gswitch/index.js
Normal file
141
wechat/miniprogram/pages/4Gswitch/index.js
Normal file
@@ -0,0 +1,141 @@
|
||||
// miniprogram/pages/4Gswitch/index.js
|
||||
|
||||
const { requestApi } = require('../../API/request')
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
deviceInfo:{},
|
||||
power:0,
|
||||
info:{
|
||||
name:"客厅1号",
|
||||
imei:123478098765432345,
|
||||
remark:"这是客厅1号的开关"
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
this.setNavigate();
|
||||
this.getLastPageData();
|
||||
console.log('options',options);
|
||||
},
|
||||
|
||||
setNavigate(){
|
||||
wx.setNavigationBarTitle({
|
||||
title: '4G开关',
|
||||
});
|
||||
wx.setNavigationBarColor({
|
||||
backgroundColor: '#4271f1',
|
||||
frontColor: '#ffffff',
|
||||
});
|
||||
},
|
||||
|
||||
getLastPageData(){
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
const that = this;
|
||||
eventChannel.on('getDeviceInfo',async (data)=>{
|
||||
const res = await requestApi(`/system/status/newByNum/${data.deviceNum}`,{ method:'GET' });
|
||||
that.setData({
|
||||
deviceInfo:JSON.parse(res.result).data,
|
||||
power:JSON.parse(res.result).data.lightStatus
|
||||
});
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
async lightPower(){
|
||||
let deviceInfo = this.data.deviceInfo;
|
||||
if(deviceInfo.lightStatus === 1){
|
||||
deviceInfo.lightStatus = 0;
|
||||
}else if(deviceInfo.lightStatus === 0){
|
||||
deviceInfo.lightStatus = 1;
|
||||
}
|
||||
const res = await requestApi('/system/status',{
|
||||
method:'PUT',
|
||||
body:deviceInfo,
|
||||
json:true
|
||||
})
|
||||
if (res.result.code === 200) {
|
||||
this.setData({ power:deviceInfo.lightStatus })
|
||||
}
|
||||
},
|
||||
|
||||
//打开分享的页面
|
||||
isShared(options){
|
||||
if (options.hasOwnProperty('deviceInfo')) {
|
||||
const deviceInfo = JSON.parse(options.deviceInfo);
|
||||
this.setData({
|
||||
info:deviceInfo
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
lookDetail(e){
|
||||
wx.navigateTo({
|
||||
url: '/pages/deviceDetail/index',
|
||||
success: (result) => {
|
||||
result.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info);
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function (e) {
|
||||
console.log(e);
|
||||
return {
|
||||
title:"我分享了一个设备。",
|
||||
path:`/pages/4Gswitch/index?deviceInfo=${JSON.stringify(e.target.dataset.info)}`,
|
||||
imageUrl:'/icons/smart.jpg'
|
||||
}
|
||||
}
|
||||
})
|
||||
3
wechat/miniprogram/pages/4Gswitch/index.json
Normal file
3
wechat/miniprogram/pages/4Gswitch/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
28
wechat/miniprogram/pages/4Gswitch/index.wxml
Normal file
28
wechat/miniprogram/pages/4Gswitch/index.wxml
Normal file
@@ -0,0 +1,28 @@
|
||||
<!--miniprogram/pages/4Gswitch/index.wxml-->
|
||||
<view class="name">
|
||||
{{ deviceInfo.deviceName }}
|
||||
</view>
|
||||
<view>
|
||||
<view class="outside">
|
||||
<view class="inside" bindtap="lightPower">
|
||||
<image wx:if="{{ power === 0 }}" class="switch" src="/icons/switch_off.png"></image>
|
||||
<image wx:if="{{ power === 1 }}" class="switch" src="/icons/switch_on.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="power">
|
||||
<text>开关状态:</text>
|
||||
<text wx:if="{{ power === 1 }}" style="color:#0000ff">开</text>
|
||||
<text wx:if="{{ power === 0 }}" style="color:#ff0000">关</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="bottom">
|
||||
<view class="bottom-item">
|
||||
<image src="/icons/share.png"></image>
|
||||
<text>分享</text>
|
||||
<button class="share" open-type="share" data-info = "{{ deviceInfo }}"></button>
|
||||
</view>
|
||||
<view class="bottom-item" bindtap="lookDetail" data-info="{{ deviceInfo }}">
|
||||
<image src="/icons/detail.png"></image>
|
||||
<text>详情</text>
|
||||
</view>
|
||||
</view>
|
||||
78
wechat/miniprogram/pages/4Gswitch/index.wxss
Normal file
78
wechat/miniprogram/pages/4Gswitch/index.wxss
Normal file
@@ -0,0 +1,78 @@
|
||||
/* miniprogram/pages/4Gswitch/index.wxss */
|
||||
page{
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.name{
|
||||
width: 60%;
|
||||
margin: 15vh auto 30rpx;
|
||||
text-align: center;
|
||||
font-size: 42rpx;
|
||||
}
|
||||
.outside{
|
||||
margin: 50rpx auto;
|
||||
width: 60vw;
|
||||
height: 60vw;
|
||||
border-radius: 50%;
|
||||
background-color: #dadada;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* border: 1rpx solid #666; */
|
||||
}
|
||||
.inside{
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
border-radius: 50%;
|
||||
background-color: #ffffff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
box-shadow: 0 0 8rpx #bfbfbf;
|
||||
}
|
||||
.inside:active{
|
||||
transform: translateY(5rpx);
|
||||
}
|
||||
.switch{
|
||||
width: 25%;
|
||||
height: 25%;
|
||||
}
|
||||
.power{
|
||||
width: 60%;
|
||||
margin: 30rpx auto;
|
||||
text-align: center;
|
||||
font-size: larger;
|
||||
}
|
||||
.bottom{
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100rpx;
|
||||
display: flex;
|
||||
}
|
||||
.bottom-item{
|
||||
position: relative;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #4271f1;
|
||||
border: 1rpx solid #bfbfbf;
|
||||
color: #ffffff;
|
||||
}
|
||||
.bottom-item>image{
|
||||
width: 44rpx;
|
||||
height: 44rpx;
|
||||
margin: 0 10rpx;
|
||||
}
|
||||
.bottom-item:active{
|
||||
background-color: #0044ff;
|
||||
}
|
||||
.share{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 0;
|
||||
}
|
||||
78
wechat/miniprogram/pages/add/index.js
Normal file
78
wechat/miniprogram/pages/add/index.js
Normal file
@@ -0,0 +1,78 @@
|
||||
// miniprogram/pages/add/index.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
wx.setNavigationBarTitle({
|
||||
title: '添加设备',
|
||||
})
|
||||
},
|
||||
|
||||
addFourG(){
|
||||
wx.navigateTo({
|
||||
url: '/pages/add4G/index',
|
||||
})
|
||||
},
|
||||
addWifi(){
|
||||
wx.navigateTo({
|
||||
url: '/pages/addWiFi/index',
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
3
wechat/miniprogram/pages/add/index.json
Normal file
3
wechat/miniprogram/pages/add/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
37
wechat/miniprogram/pages/add/index.wxml
Normal file
37
wechat/miniprogram/pages/add/index.wxml
Normal file
@@ -0,0 +1,37 @@
|
||||
<!--miniprogram/pages/add/index.wxml-->
|
||||
<view class="top">
|
||||
<image src="/images/smart.jpg" />
|
||||
</view>
|
||||
<view class="title">添加设备</view>
|
||||
<view class="main">
|
||||
<view class="name">设备分类 >>></view>
|
||||
<view class="content">
|
||||
<view class="item">
|
||||
<view class="type">
|
||||
<image src="/icons/4g.png"></image>
|
||||
<text>4G开关</text>
|
||||
</view>
|
||||
<view class="add" bindtap="addFourG">
|
||||
<image src="/icons/add_1.png" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="item">
|
||||
<view class="type">
|
||||
<image src="/icons/room.png"></image>
|
||||
<text>智慧宿舍</text>
|
||||
</view>
|
||||
<view class="add">
|
||||
<image src="/icons/add_1.png" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="item">
|
||||
<view class="type">
|
||||
<image src="/icons/wifi1.png"></image>
|
||||
<text>WiFi空气盒子</text>
|
||||
</view>
|
||||
<view class="add" bindtap="addWifi">
|
||||
<image src="/icons/add_1.png" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
69
wechat/miniprogram/pages/add/index.wxss
Normal file
69
wechat/miniprogram/pages/add/index.wxss
Normal file
@@ -0,0 +1,69 @@
|
||||
/* miniprogram/pages/add/index.wxss */
|
||||
.top{
|
||||
width:100vw;
|
||||
height: 40vw;
|
||||
}
|
||||
.top>image{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.title{
|
||||
/* margin: 30rpx auto; */
|
||||
padding: 30rpx 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 42rpx;
|
||||
background-color: rgb(64, 130, 252);
|
||||
color: #ffffff;
|
||||
}
|
||||
.main{
|
||||
|
||||
}
|
||||
.name{
|
||||
background-color: #ffffff;
|
||||
padding:15rpx 30rpx;
|
||||
border-bottom: 2rpx solid #666;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.content{
|
||||
padding:0 30rpx;
|
||||
margin: 30rpx 0;
|
||||
}
|
||||
.item{
|
||||
background-color: #ffffff;
|
||||
box-shadow: 3rpx 3rpx 3rpx #666666;
|
||||
margin: 30rpx auto;
|
||||
padding: 30rpx;
|
||||
width: 50vw;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.add{
|
||||
width: 130rpx;
|
||||
height: 130rpx;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 5rpx 3rpx #bfbfbb;
|
||||
background-color: #eeeeee;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.add>image{
|
||||
width: 70%;
|
||||
height: 70%;
|
||||
}
|
||||
.add:active{
|
||||
background-color: #bfbfbf;
|
||||
}
|
||||
|
||||
.type{
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
}
|
||||
.type>image{
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
}
|
||||
66
wechat/miniprogram/pages/add4G/index.js
Normal file
66
wechat/miniprogram/pages/add4G/index.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// miniprogram/pages/add4G/index.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
5
wechat/miniprogram/pages/add4G/index.json
Normal file
5
wechat/miniprogram/pages/add4G/index.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-button": "@vant/weapp/button/index"
|
||||
}
|
||||
}
|
||||
17
wechat/miniprogram/pages/add4G/index.wxml
Normal file
17
wechat/miniprogram/pages/add4G/index.wxml
Normal file
@@ -0,0 +1,17 @@
|
||||
<!--miniprogram/pages/add4G/index.wxml-->
|
||||
<view class="top">
|
||||
<image src="/icons/Internet.png"></image>
|
||||
</view>
|
||||
<view>
|
||||
<view class="title">添加4G设备</view>
|
||||
<label class='account'>
|
||||
<text>IMEI:</text>
|
||||
<input type='text' bind:input='inputIMEI' value='{{ imei }}' placeholder='请输入设备IMEI' />
|
||||
</label>
|
||||
<view class="btn">
|
||||
<van-button block color="linear-gradient(to right, #4bb0ff, #6149f6)" round>
|
||||
提 交
|
||||
</van-button>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
34
wechat/miniprogram/pages/add4G/index.wxss
Normal file
34
wechat/miniprogram/pages/add4G/index.wxss
Normal file
@@ -0,0 +1,34 @@
|
||||
/* miniprogram/pages/add4G/index.wxss */
|
||||
.top{
|
||||
margin: 100rpx auto 30rpx;
|
||||
}
|
||||
.title{
|
||||
font-size: 42rpx;
|
||||
text-align: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
label{
|
||||
display:flex;
|
||||
align-items:center;
|
||||
padding:30rpx 0;
|
||||
border-bottom:2rpx solid #bfbfbf;
|
||||
}
|
||||
.icon{
|
||||
width:40rpx;
|
||||
height:40rpx;
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
}
|
||||
input{
|
||||
padding:15rpx 30rpx;
|
||||
flex:1
|
||||
}
|
||||
.account{
|
||||
width:80vw;
|
||||
margin:0 auto;
|
||||
}
|
||||
.btn {
|
||||
margin: 60rpx auto;
|
||||
width: 50vw;
|
||||
}
|
||||
265
wechat/miniprogram/pages/addWiFi/index.js
Normal file
265
wechat/miniprogram/pages/addWiFi/index.js
Normal file
@@ -0,0 +1,265 @@
|
||||
const alreadyConnected = 'target wifi is already connected.';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
pwdHide:true,
|
||||
ssid: '',
|
||||
password: '',
|
||||
deviceSSID:'Shgf',
|
||||
devicePWD:'12345678',
|
||||
// deviceSSID:'XiaoYi_IOT_AirBox',
|
||||
// devicePWD:'asdqwe9867',
|
||||
udp: '',
|
||||
port: 0,
|
||||
showClearBtn: false,
|
||||
isFirst: true,
|
||||
stepsTop: [
|
||||
{ text: '步骤一',desc: '连接WiFi', },
|
||||
{ text: '步骤二',desc: '连接软热点', },
|
||||
{ text: '步骤三',desc: '开始配网', }
|
||||
],
|
||||
steps: [
|
||||
{ text: '手机与设备通信成功',success:false },
|
||||
{ text: '设备配网成功',success:false },
|
||||
{ text: '切换回家庭WiFi',success:false }
|
||||
],
|
||||
activeTop:0,
|
||||
active:-1
|
||||
},
|
||||
onLoad(opt) {
|
||||
let that = this;
|
||||
wx.startWifi({
|
||||
success(res) {
|
||||
console.log(res.errMsg, 'wifi初始化成功')
|
||||
that.getWifiInfo();
|
||||
},
|
||||
fail: function (res) {
|
||||
wx.showToast({
|
||||
title: '请连接路由器!',
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
getWifiInfo() {
|
||||
let that = this
|
||||
wx.getConnectedWifi({
|
||||
success(res) {
|
||||
console.log("getConnectedWifi ok:", JSON.stringify(res))
|
||||
if ('getConnectedWifi:ok' === res.errMsg) {
|
||||
that.setData({
|
||||
ssid: res.wifi.SSID,
|
||||
bssid: res.wifi.BSSID
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '请连接路由器',
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
fail(res) {
|
||||
wx.showToast({
|
||||
title: '请连接路由器',
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
onConfirm() {
|
||||
const that = this;
|
||||
console.log("ssid:", this.data.ssid, ",password:", this.data.password,',port:',this.data.port);
|
||||
// that.udpConnect();
|
||||
if ((this.data.ssid.trim() === '') || (this.data.password.trim() === '')) {
|
||||
wx.showToast({
|
||||
title: '请输入完整',
|
||||
icon:'error'
|
||||
});
|
||||
return;
|
||||
}
|
||||
that.setData({ activeTop:++that.data.activeTop });
|
||||
// that.udpConnect();
|
||||
},
|
||||
|
||||
udpConnect(){
|
||||
const udp = wx.createUDPSocket();
|
||||
udp.onListening(res => {
|
||||
console.log('正在监听...');
|
||||
})
|
||||
const password = this.data.password;
|
||||
const ssid = this.data.ssid;
|
||||
let message = JSON.stringify({
|
||||
port,
|
||||
password,
|
||||
ssid
|
||||
});
|
||||
let port = udp.bind(50314);
|
||||
console.log(udp,udp.onListening,udp.send);
|
||||
console.log('port',port);
|
||||
setInterval(() => {
|
||||
udp.send({
|
||||
address:'255.255.255.255',
|
||||
port:8081,
|
||||
message
|
||||
});
|
||||
}, 2000);
|
||||
console.log(message);
|
||||
udp.onMessage((res) => {
|
||||
console.log('res:',res)
|
||||
//字符串转换,很重要
|
||||
let unit8Arr = new Uint8Array(res.message);
|
||||
let encodedString = String.fromCharCode.apply(null, unit8Arr);
|
||||
let dat = decodeURIComponent(escape((encodedString)));
|
||||
console.log("data:", dat);
|
||||
let str = JSON.parse(dat);
|
||||
console.log(str);
|
||||
switch (str.code) {
|
||||
//成功收到信息
|
||||
case 0:
|
||||
udp.send({
|
||||
address:'255.255.255.255',
|
||||
port:8081,
|
||||
message
|
||||
});
|
||||
let steps = this.data.steps;
|
||||
steps[0].success = true;
|
||||
this.setData({ steps });
|
||||
break;
|
||||
//成功解析到信息
|
||||
case 1:
|
||||
udp.send({
|
||||
address:'255.255.255.255',
|
||||
port:8081,
|
||||
message:'I GOT YOU'
|
||||
});
|
||||
steps = this.data.steps;
|
||||
steps[1].success = true;
|
||||
this.setData({ steps });
|
||||
udp.offListening();
|
||||
udp.offMessage();
|
||||
udp.offClose();
|
||||
udp.close();
|
||||
wx.connectWifi({
|
||||
SSID: ssid,
|
||||
password: password,
|
||||
success:()=>{
|
||||
wx.onWifiConnected((result) => {
|
||||
let steps = this.data.steps;
|
||||
steps[2].success = true;
|
||||
this.setData({ steps });
|
||||
wx.hideLoading()
|
||||
const newUdp = wx.createUDPSocket();
|
||||
const newPort = newUdp.bind(50314);
|
||||
newUdp.onListening(res => {
|
||||
console.log('再次监听中。。。');
|
||||
});
|
||||
newUdp.onMessage(re => {
|
||||
let _unit8Arr = new Uint8Array(re.message);
|
||||
let _encodedString = String.fromCharCode.apply(null, _unit8Arr);
|
||||
let _dat = decodeURIComponent(escape((_encodedString)));
|
||||
console.log("data:", _dat);
|
||||
newUdp.send({
|
||||
address:'255.255.255.255',
|
||||
port:8081,
|
||||
message:'BIND SUCCESS !'
|
||||
});
|
||||
newUdp.offListening();
|
||||
newUdp.offMessage();
|
||||
newUdp.offClose();
|
||||
newUdp.close();
|
||||
})
|
||||
});
|
||||
wx.showToast({
|
||||
title: '准备连接路由器',
|
||||
})
|
||||
}
|
||||
});
|
||||
break;
|
||||
//成功连接到路由器
|
||||
// case 2:
|
||||
// wx.showToast({
|
||||
// title: '成功连接',
|
||||
// })
|
||||
// break;
|
||||
// //连接失败路由器
|
||||
// case 3:
|
||||
// wx.showToast({
|
||||
// title: '连接失败',
|
||||
// })
|
||||
// break;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
lookPwd(){
|
||||
let pwdHide = !this.data.pwdHide;
|
||||
this.setData({ pwdHide });
|
||||
},
|
||||
inputPwd(e){
|
||||
this.setData({ password:e.detail.value })
|
||||
},
|
||||
inputDevicePWD(e){
|
||||
this.setData({ devicePWD:e.detail.value })
|
||||
},
|
||||
inputAcc(e){
|
||||
this.setData({ ssid:e.detail.value })
|
||||
},
|
||||
inputDeviceSSID(e){
|
||||
this.setData({ deviceSSID:e.detail.value })
|
||||
},
|
||||
|
||||
onConnect(){
|
||||
const that = this;
|
||||
wx.showLoading({
|
||||
title: '连接中',
|
||||
mask:true
|
||||
})
|
||||
console.log("ssid:", this.data.deviceSSID, ",password:", this.data.devicePWD);
|
||||
wx.connectWifi({
|
||||
SSID: this.data.deviceSSID,
|
||||
password: this.data.devicePWD,
|
||||
}).then((res)=>{
|
||||
console.log(res);
|
||||
// if (res.wifiMsg===alreadyConnected) {
|
||||
// wx.hideLoading();
|
||||
// that.udpConnect();
|
||||
// }else{
|
||||
// wx.onWifiConnected((result) => {
|
||||
// wx.hideLoading();
|
||||
// // that.setData({ active:++that.data.active });
|
||||
// that.udpConnect();
|
||||
// })
|
||||
// }
|
||||
}).catch((err)=>{
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '连接失败',
|
||||
icon:'error'
|
||||
})
|
||||
console.error(err);
|
||||
});
|
||||
wx.onWifiConnected((result) => {
|
||||
wx.hideLoading();
|
||||
that.setData({ activeTop:++that.data.activeTop });
|
||||
that.udpConnect();
|
||||
})
|
||||
},
|
||||
|
||||
closeUDP(){
|
||||
this.data.udp.close();
|
||||
},
|
||||
|
||||
onUnload(){
|
||||
try {
|
||||
this.data.udp.close();
|
||||
} catch (error) {
|
||||
// console.error(error);
|
||||
}
|
||||
},
|
||||
onShow(){
|
||||
this.getWifiInfo();
|
||||
}
|
||||
});
|
||||
7
wechat/miniprogram/pages/addWiFi/index.json
Normal file
7
wechat/miniprogram/pages/addWiFi/index.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-steps": "@vant/weapp/steps/index",
|
||||
"van-button": "@vant/weapp/button/index",
|
||||
"van-loading": "@vant/weapp/loading/index"
|
||||
}
|
||||
}
|
||||
70
wechat/miniprogram/pages/addWiFi/index.wxml
Normal file
70
wechat/miniprogram/pages/addWiFi/index.wxml
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
<van-steps steps="{{ stepsTop }}" active="{{ activeTop }}" />
|
||||
<view class='teach'>
|
||||
<image src='/icons/route.png' />
|
||||
<view class=''>第一步,输入家庭WiFi信息</view>
|
||||
<view class=''>第二步,连接设备热点</view>
|
||||
<view class=''>第三步,重新连接家庭WiFi</view>
|
||||
</view>
|
||||
<br />
|
||||
<br />
|
||||
<block wx:if='{{ activeTop === 0 }}'>
|
||||
<view class='form'>
|
||||
<view class='title'>
|
||||
输入家庭WiFi信息
|
||||
</view>
|
||||
<label class='account'>
|
||||
<image class='icon' src='/icons/wifi.png' />
|
||||
<input type='text' bind:input='inputAcc' value='{{ ssid }}' placeholder='请输入WiFi名称' />
|
||||
</label>
|
||||
<label class='password'>
|
||||
<image class='icon' src='/icons/pwd.png' />
|
||||
<input wx:if='{{ pwdHide === true }}' bind:input='inputPwd' value='{{ password }}' type='password' placeholder='请输入密码' />
|
||||
<input wx:if='{{ pwdHide === false }}' bind:input='inputPwd' value='{{ password }}' type='text' placeholder='请输入密码' />
|
||||
<view class='icon' bindtap='lookPwd'>
|
||||
<image wx:if='{{ pwdHide === true }}' class='icon' src='/icons/close.png' />
|
||||
<image wx:if='{{ pwdHide === false }}' class='icon' src='/icons/open.png' />
|
||||
</view>
|
||||
</label>
|
||||
<view class='btn'>
|
||||
<van-button block round color="linear-gradient(to right, #4bb0ff, #6149f6)" bind:click='onConfirm'>
|
||||
下一步
|
||||
</van-button>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if='{{ activeTop === 1 }}'>
|
||||
<view class='form'>
|
||||
<view class='title'>
|
||||
连接设备热点
|
||||
</view>
|
||||
<label class='account'>
|
||||
<image class='icon' src='/icons/acc.png' />
|
||||
<input type='text' disabled bind:input='inputDeviceSSID' value='{{ deviceSSID }}' placeholder='请输入设备热点名称' />
|
||||
</label>
|
||||
<label class='password'>
|
||||
<image class='icon' src='/icons/pwd.png' />
|
||||
<input wx:if='{{ pwdHide === true }}' disabled bind:input='inputDevicePWD' value='{{ devicePWD }}' type='password' placeholder='请输入密码' />
|
||||
<input wx:if='{{ pwdHide === false }}' disabled bind:input='inputDevicePWD' value='{{ devicePWD }}' type='text' placeholder='请输入密码' />
|
||||
<view class='icon' bindtap='lookPwd'>
|
||||
<image wx:if='{{ pwdHide === true }}' class='icon' src='/icons/close.png' />
|
||||
<image wx:if='{{ pwdHide === false }}' class='icon' src='/icons/open.png' />
|
||||
</view>
|
||||
</label>
|
||||
<view class='btn'>
|
||||
<van-button block round color="linear-gradient(to right, #4bb0ff, #6149f6)" bind:click='onConnect'>
|
||||
连接
|
||||
</van-button>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:if='{{ activeTop === 2 }}'>
|
||||
<view class='step'>
|
||||
<view class='item' wx:for='{{ steps }}'>
|
||||
<van-loading wx:if='{{ item.success === false }}' type="spinner" />
|
||||
<image wx:if='{{ item.success === true }}' src='/icons/yes.png' />
|
||||
<text class='desc'>{{ item.text }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<button bindtap='closeUDP'>关闭</button>
|
||||
</block>
|
||||
52
wechat/miniprogram/pages/addWiFi/index.wxss
Normal file
52
wechat/miniprogram/pages/addWiFi/index.wxss
Normal file
@@ -0,0 +1,52 @@
|
||||
/* pages/index/index.wxss */
|
||||
.form{
|
||||
width:80vw;
|
||||
margin:0 auto;
|
||||
}
|
||||
.title{
|
||||
font-size:38rpx;
|
||||
}
|
||||
label{
|
||||
display:flex;
|
||||
align-items:center;
|
||||
padding:35rpx 0;
|
||||
border-bottom:2rpx solid #bfbfbf;
|
||||
}
|
||||
.icon{
|
||||
width:40rpx;
|
||||
height:40rpx;
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
}
|
||||
input{
|
||||
padding:15rpx 30rpx;
|
||||
flex:1
|
||||
}
|
||||
.btn{
|
||||
width:80%;
|
||||
margin:30rpx auto;
|
||||
}
|
||||
.teach{
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
align-items:center;
|
||||
margin:0 0 30rpx 0;
|
||||
}
|
||||
.step{
|
||||
margin:30rpx auto ;
|
||||
width:50%;
|
||||
}
|
||||
.item{
|
||||
display:flex;
|
||||
align-items:center;
|
||||
margin:15rpx 0;
|
||||
}
|
||||
.item>image{
|
||||
width:48rpx;
|
||||
height:48rpx;
|
||||
border-radius:50%;
|
||||
}
|
||||
.desc{
|
||||
padding:0 15rpx;
|
||||
}
|
||||
118
wechat/miniprogram/pages/deviceDetail/index.js
Normal file
118
wechat/miniprogram/pages/deviceDetail/index.js
Normal file
@@ -0,0 +1,118 @@
|
||||
// miniprogram/pages/deviceDetail/index.js
|
||||
const { requestApi } = require('../../API/request')
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
newRemark:{},
|
||||
newName:'',
|
||||
info:{},
|
||||
show:false
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
this.getLastPageData();
|
||||
},
|
||||
|
||||
getLastPageData(){
|
||||
const that = this;
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.on('getDeviceInfo', async(res)=>{
|
||||
const data = await requestApi(`/system/device/getByNum/${res.deviceNum}`,{ method:'GET' });
|
||||
that.setData({
|
||||
info:JSON.parse(data.result).data
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
changeName(e){
|
||||
this.setData({ newName:e.detail })
|
||||
},
|
||||
changeRemark(e){
|
||||
this.setData({ newRemark:e.detail })
|
||||
},
|
||||
|
||||
showDialog(){
|
||||
this.setData({ show:true })
|
||||
},
|
||||
async onConfirm(){
|
||||
wx.showLoading({
|
||||
title: '正在提交',
|
||||
});
|
||||
let info = this.data.info;
|
||||
info.deviceName = this.data.newName;
|
||||
info.newRemark = this.data.newRemark;
|
||||
const res = await requestApi('/system/device',{
|
||||
method:'PUT',
|
||||
body:info,
|
||||
json:true
|
||||
});
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: res.result.msg,
|
||||
})
|
||||
this.onClose();
|
||||
},
|
||||
onCancel(){
|
||||
this.onClose();
|
||||
},
|
||||
|
||||
onClose(){
|
||||
this.setData({ show:false });
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
8
wechat/miniprogram/pages/deviceDetail/index.json
Normal file
8
wechat/miniprogram/pages/deviceDetail/index.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-field": "@vant/weapp/field/index",
|
||||
"van-cell-group": "@vant/weapp/cell-group/index",
|
||||
"van-button": "@vant/weapp/button/index",
|
||||
"van-dialog": "@vant/weapp/dialog/index"
|
||||
}
|
||||
}
|
||||
46
wechat/miniprogram/pages/deviceDetail/index.wxml
Normal file
46
wechat/miniprogram/pages/deviceDetail/index.wxml
Normal file
@@ -0,0 +1,46 @@
|
||||
<!--miniprogram/pages/deviceDetail/index.wxml-->
|
||||
<van-cell-group title='设备信息'>
|
||||
<van-field
|
||||
label="设备编号"
|
||||
value="{{ info.deviceNum }}"
|
||||
readonly
|
||||
/>
|
||||
<van-field
|
||||
label="设备分类"
|
||||
value="4G开关"
|
||||
readonly
|
||||
/>
|
||||
</van-cell-group>
|
||||
<van-cell-group title='自定义信息'>
|
||||
<van-field
|
||||
label="设备名称"
|
||||
value="{{ info.deviceName }}"
|
||||
bind:change="changeName"
|
||||
/>
|
||||
<van-field
|
||||
label="设备位置"
|
||||
value="客厅"
|
||||
/>
|
||||
<van-field
|
||||
label="备注"
|
||||
value="{{ info.remark }}"
|
||||
type='textarea'
|
||||
bind:change="changeRemark"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<view class="btn">
|
||||
<van-button block round color="linear-gradient(to right, #4bb0ff, #6149f6)" bindtap="showDialog">
|
||||
提交修改
|
||||
</van-button>
|
||||
</view>
|
||||
|
||||
<van-dialog
|
||||
message='您确定要提交您所做的修改吗?'
|
||||
show="{{ show }}"
|
||||
show-cancel-button
|
||||
bind:close="onClose"
|
||||
bind:confirm="onConfirm"
|
||||
bind:cancel='onCancel'
|
||||
>
|
||||
</van-dialog>
|
||||
6
wechat/miniprogram/pages/deviceDetail/index.wxss
Normal file
6
wechat/miniprogram/pages/deviceDetail/index.wxss
Normal file
@@ -0,0 +1,6 @@
|
||||
/* miniprogram/pages/deviceDetail/index.wxss */
|
||||
|
||||
.btn{
|
||||
width:80vw;
|
||||
margin:30rpx auto;
|
||||
}
|
||||
@@ -36,6 +36,10 @@ Page({
|
||||
|
||||
//获取设备列表
|
||||
async getDevices(){
|
||||
wx.showLoading({
|
||||
title: '获取设备',
|
||||
mask: true
|
||||
})
|
||||
const res = await requestApi('/system/device/list',{ method:'GET' });
|
||||
console.log(res);
|
||||
const result = JSON.parse(res.result);
|
||||
@@ -53,6 +57,7 @@ Page({
|
||||
unlineList,
|
||||
DeviceList:result.rows
|
||||
})
|
||||
wx.hideLoading()
|
||||
},
|
||||
|
||||
|
||||
@@ -78,15 +83,21 @@ Page({
|
||||
goToDeviceControl(e){
|
||||
|
||||
switch (e.currentTarget.dataset.info.categoryId) {
|
||||
case 1:
|
||||
wx.navigateTo({
|
||||
url: '/pages/4Gswitch/index',
|
||||
success:(res)=>{
|
||||
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case 4:
|
||||
if (e.currentTarget.dataset.info.deviceNum === 'E8DB84933081') {
|
||||
wx.navigateTo({
|
||||
url: '/pages/someData/index',
|
||||
success:(res)=>{
|
||||
res.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
break;
|
||||
|
||||
case 5:
|
||||
@@ -137,12 +148,7 @@ Page({
|
||||
*/
|
||||
onShow: function () {
|
||||
this.getWeather();
|
||||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||||
this.getTabBar().setData({
|
||||
homeSelected:true,
|
||||
userSelected:false //这个数字是当前页面在tabBar中list数组的索引
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -164,6 +170,7 @@ Page({
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
this.onLoad();
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
"van-action-sheet": "@vant/weapp/action-sheet/index",
|
||||
"van-tab": "@vant/weapp/tab/index",
|
||||
"van-tabs": "@vant/weapp/tabs/index"
|
||||
}
|
||||
},
|
||||
"enablePullDownRefresh":true
|
||||
}
|
||||
@@ -42,4 +42,9 @@ Page({
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
onShow(){
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user