diff --git a/wechat/app.json b/wechat/app.json index 59bf4665..14131674 100644 --- a/wechat/app.json +++ b/wechat/app.json @@ -5,7 +5,9 @@ "pages/my/my", "pages/add4G/index", "pages/4Gswitch/index", - "pages/deviceDetail/index" + "pages/addWiFi/index", + "pages/deviceDetail/index", + "pages/feedBack/feedBack" ], "window": { "backgroundColor": "#F6F6F6", @@ -52,6 +54,8 @@ "van-tag": "@vant/weapp/tag/index", "van-button": "@vant/weapp/button/index", "van-cell": "@vant/weapp/cell/index", - "van-cell-group": "@vant/weapp/cell-group/index" + "van-cell-group": "@vant/weapp/cell-group/index", + "van-radio": "@vant/weapp/radio/index", + "van-radio-group": "@vant/weapp/radio-group/index" } } \ No newline at end of file diff --git a/wechat/icons/acc.png b/wechat/icons/acc.png new file mode 100644 index 00000000..7d167e0a Binary files /dev/null and b/wechat/icons/acc.png differ diff --git a/wechat/icons/add_1.png b/wechat/icons/add_1.png index f0af557c..54e9656e 100644 Binary files a/wechat/icons/add_1.png and b/wechat/icons/add_1.png differ diff --git a/wechat/icons/delete.png b/wechat/icons/delete.png new file mode 100644 index 00000000..51671090 Binary files /dev/null and b/wechat/icons/delete.png differ diff --git a/wechat/icons/light.png b/wechat/icons/light.png new file mode 100644 index 00000000..32710d0b Binary files /dev/null and b/wechat/icons/light.png differ diff --git a/wechat/icons/phone.png b/wechat/icons/phone.png new file mode 100644 index 00000000..bc9eee99 Binary files /dev/null and b/wechat/icons/phone.png differ diff --git a/wechat/icons/suggest.png b/wechat/icons/suggest.png new file mode 100644 index 00000000..f7b16d01 Binary files /dev/null and b/wechat/icons/suggest.png differ diff --git a/wechat/icons/yes.png b/wechat/icons/yes.png new file mode 100644 index 00000000..cf78a94d Binary files /dev/null and b/wechat/icons/yes.png differ diff --git a/wechat/pages/4Gswitch/index.js b/wechat/pages/4Gswitch/index.js index d41d04e9..2beb1418 100644 --- a/wechat/pages/4Gswitch/index.js +++ b/wechat/pages/4Gswitch/index.js @@ -17,13 +17,10 @@ Page({ */ onLoad: function (options) { this.setNavigate(); - try { + if (getCurrentPages().length > 1) { this.getLastPageData(); - } catch (error) { - console.log(error); } this.isShared(options); - }, checkLogin(){ @@ -85,7 +82,7 @@ Page({ getLastPageData(){ const eventChannel = this.getOpenerEventChannel(); const that = this; - eventChannel.on('getDeviceInfo',async (data)=>{ + eventChannel.on('getDeviceInfo',(data)=>{ that.setData({ deviceId:data }) @@ -95,6 +92,7 @@ Page({ async getDeviceDetail(){ let deviceId = this.data.deviceId; + console.log(deviceId); const res = await request(`system/device/getDeviceInfoByDeviceId?deviceId=${deviceId}`,'get'); console.log(res); if (res.code === 200) { @@ -166,7 +164,10 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - this.getDeviceDetail(); + setTimeout(()=>{ + this.getDeviceDetail(); + },0) + }, /** @@ -183,7 +184,7 @@ Page({ return { title:"我分享了一个设备。", path:`/pages/4Gswitch/index?deviceInfo=${JSON.stringify(e.target.dataset.info)}&&isShare=1`, - imageUrl:'/icons/smart.jpg' + imageUrl:'/icons/light.png' } } }) \ No newline at end of file diff --git a/wechat/pages/add/add.js b/wechat/pages/add/add.js index 1c756c8c..e6cc8b41 100644 --- a/wechat/pages/add/add.js +++ b/wechat/pages/add/add.js @@ -20,9 +20,12 @@ Page({ }) }, addWifi(){ - wx.showToast({ - title: '暂不支持', - icon:'error' + // wx.showToast({ + // title: '暂不支持', + // icon:'error' + // }) + wx.navigateTo({ + url: '/pages/addWiFi/index', }) }, }) \ No newline at end of file diff --git a/wechat/pages/addWiFi/index.js b/wechat/pages/addWiFi/index.js new file mode 100644 index 00000000..bf18245b --- /dev/null +++ b/wechat/pages/addWiFi/index.js @@ -0,0 +1,279 @@ +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; + try { + let udp = this.data.udp; + udp.offListening(); + udp.offMessage(); + udp.offClose(); + udp.close(); + } catch (error) { + console.log(error); + } + 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 { + let udp = this.data.udp; + udp.offListening(); + udp.offMessage(); + udp.offClose(); + udp.close(); + } catch (error) { + // console.error(error); + } + }, + onShow(){ + this.getWifiInfo(); + } +}); \ No newline at end of file diff --git a/wechat/pages/addWiFi/index.json b/wechat/pages/addWiFi/index.json new file mode 100644 index 00000000..6b35d201 --- /dev/null +++ b/wechat/pages/addWiFi/index.json @@ -0,0 +1,7 @@ +{ + "usingComponents": { + "van-steps": "@vant/weapp/steps/index", + "van-button": "@vant/weapp/button/index", + "van-loading": "@vant/weapp/loading/index" + } +} \ No newline at end of file diff --git a/wechat/pages/addWiFi/index.wxml b/wechat/pages/addWiFi/index.wxml new file mode 100644 index 00000000..ea257284 --- /dev/null +++ b/wechat/pages/addWiFi/index.wxml @@ -0,0 +1,70 @@ + + + + + 第一步,输入家庭WiFi信息 + 第二步,连接设备热点 + 第三步,重新连接家庭WiFi + +
+
+ + + + 输入家庭WiFi信息 + + + + + + 下一步 + + + + + + + + 连接设备热点 + + + + + + 连接 + + + + + + + + + + {{ item.text }} + + + + \ No newline at end of file diff --git a/wechat/pages/addWiFi/index.wxss b/wechat/pages/addWiFi/index.wxss new file mode 100644 index 00000000..2c68dd0e --- /dev/null +++ b/wechat/pages/addWiFi/index.wxss @@ -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; +} \ No newline at end of file diff --git a/wechat/pages/feedBack/feedBack.js b/wechat/pages/feedBack/feedBack.js new file mode 100644 index 00000000..dbe5c213 --- /dev/null +++ b/wechat/pages/feedBack/feedBack.js @@ -0,0 +1,115 @@ +// pages/feedBack/feedBack.js + +const { request } = require('../../API/request'); + +Page({ + + /** + * 页面的初始数据 + */ + data: { + selectData:[ + { id:1,text:'程序bug' }, + { id:2,text:'内容意见' }, + { id:3,text:'网络问题' }, + { id:4,text:'功能建议' }, + { id:5,text:'其他' } + ], + maxlength:200, + radio: 1, + value:'', + tempFilePaths:[], + phoneNum:'', + lengthErr:false + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + wx.setNavigationBarTitle({ + title: '意见反馈' + }); + wx.setNavigationBarColor({ + backgroundColor: '#58bcff', + frontColor: '#ffffff', + }) + }, + + checkOne(e){ + this.setData({ + radio:e.detail + }) + }, + + inputDetail(e){ + if (e.detail.value.trim().length >= 15) { + this.setData({ + lengthErr:false + }) + } + this.setData({ + value:e.detail.value + }) + }, + + chooseImage(){ + const that = this; + let tempFilePaths = this.data.tempFilePaths; + wx.chooseImage({ + count: 3, + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success: (result) => { + that.setData({ + tempFilePaths:tempFilePaths.concat(result.tempFilePaths) + }) + } + }) + }, + + previewImage(e){ + console.log(e); + wx.previewImage({ + urls: this.data.tempFilePaths, + current:this.data.tempFilePaths[e.currentTarget.dataset.index] + }) + }, + + deleteImage(e){ + let tempFilePaths = this.data.tempFilePaths; + tempFilePaths.splice(e.currentTarget.dataset.index,1); + this.setData({ + tempFilePaths + }) + }, + inputNum(e){ + this.setData({ + phoneNum:e.detail.value + }) + }, + + async submit(){ + const tempFilePaths = this.data.tempFilePaths; + const describe = this.data.value; + const phone = this.data.phoneNum; + const radio = this.data.radio; + if(describe.trim().length < 15){ + this.setData({ + lengthErr:true + }) + return; + } + const res = await request('','post',{ + phone, + tempFilePaths, + describe, + type:this.data.selectData[radio-1] + }); + if (res.code === 200) { + wx.switchTab({ + url: '/pages/my/my', + }) + } + } +}) \ No newline at end of file diff --git a/wechat/pages/feedBack/feedBack.json b/wechat/pages/feedBack/feedBack.json new file mode 100644 index 00000000..8835af06 --- /dev/null +++ b/wechat/pages/feedBack/feedBack.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/wechat/pages/feedBack/feedBack.wxml b/wechat/pages/feedBack/feedBack.wxml new file mode 100644 index 00000000..dc05fb1b --- /dev/null +++ b/wechat/pages/feedBack/feedBack.wxml @@ -0,0 +1,59 @@ + + + 选择反馈类型 + + {{ item.text }} + + + + + + + + + + + + + + + + + + + + + + + + {{ value.length }} + / + {{ maxlength }} + + + 请至少输入15个字符! + + + + + 联系方式(选填) + + + + + + + + + + + 默认按钮 + \ No newline at end of file diff --git a/wechat/pages/feedBack/feedBack.wxss b/wechat/pages/feedBack/feedBack.wxss new file mode 100644 index 00000000..8ade4878 --- /dev/null +++ b/wechat/pages/feedBack/feedBack.wxss @@ -0,0 +1,138 @@ +/* pages/feedBack/feedBack.wxss */ +.checkbox{ + width: calc(100vw - 120rpx); + padding: 30rpx; + box-shadow: 0 0 12rpx #bfbfbf; + margin: 30rpx auto 15rpx; + background-color: #ffffff; +} +.title{ + color: #9e9e9e; + padding-bottom: 15rpx; +} +.van-radio{ + margin: 15rpx 0; +} +.length{ + color: #9e9e9e; + float: right; +} + +.input{ + width: calc(100vw - 120rpx); + padding: 30rpx; + box-shadow: 0 0 12rpx #bfbfbf; + margin: 15rpx auto; + background-color: #ffffff; +} +.main{ + box-shadow: 0 0 5rpx #bfbfbf; +} +textarea{ + padding:15rpx; + height: 150rpx; + width: calc(100% - 30rpx); +} +.phone{ + width: calc(100vw - 120rpx); + padding: 15rpx 30rpx; + box-shadow: 0 0 12rpx #bfbfbf; + margin: 15rpx auto; + background-color: #ffffff; +} +.inputPhone{ + display: flex; + align-items: center; +} +.inputPhone>input{ + padding: 10rpx 30rpx; + border-bottom: 2rpx solid #bfbfbf; + margin: 0 30rpx; +} + +.addImage{ + display: flex; +} +.add{ + width: 100rpx; + height: 100rpx; + border: 4rpx dashed #aaaaaa; + margin: 15rpx; + display: flex; + justify-content: center; + align-items: center; +} +.add>image{ + width: 50%; + height: 50%; +} +.add>image:active{ + width: 45%; + height: 45%; +} +.imgs{ + display: flex; + flex-wrap: wrap; +} +.item{ + width: 100rpx; + height: 100rpx; + border: 2rpx solid #8a8a8a; + margin: 15rpx; + position: relative; +} +.item>image{ + width: 100%; + height: 100%; +} +.delete{ + position: absolute; + right: 0; + top: 0; + width: 30rpx; + height: 30rpx; + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; + background-color: #ff1515; + transform: translate(50%,-50%); + border:1rpx solid #666; +} +.delete>image{ + width: 100%; + height: 100%; +} + +.icon{ + width: 50rpx; + height: 50rpx; +} +.icon>image{ + width: 100%; + height: 100%; +} +.btn{ + width: calc(100vw - 60rpx); + padding: 30rpx; +} +.Vibration{ + animation: Vibration 0.3s 1; +} +@keyframes Vibration{ + 0% { + transform: translateX(0); + } + 25% { + transform: translateX(-10rpx); + } + 50% { + transform: translateX(10rpx); + } + 75% { + transform: translateX(10rpx); + } + 100% { + transform: translateX(-10rpx); + } +} \ No newline at end of file diff --git a/wechat/pages/my/my.wxml b/wechat/pages/my/my.wxml index 41842435..8e2c41b9 100644 --- a/wechat/pages/my/my.wxml +++ b/wechat/pages/my/my.wxml @@ -30,5 +30,8 @@ + diff --git a/wechat/project.private.config.json b/wechat/project.private.config.json index b9709278..6c091ace 100644 --- a/wechat/project.private.config.json +++ b/wechat/project.private.config.json @@ -32,6 +32,11 @@ "referrerInfo": { "appId": "xxx" } + }, + { + "name": "pages/feedBack/feedBack", + "pathName": "pages/feedBack/feedBack", + "scene": null } ] }