wifiSet.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='WiFi配置' bgColor="transparent"></cus-header>
  4. <div class="box">
  5. <div class="b_top adffcacjc">
  6. <image src="http://106.54.209.120:8188/static/wifi.png"></image>
  7. <text>WiFi配置</text>
  8. </div>
  9. <div class="b_pre">
  10. <div class="bp_text">SSID:</div>
  11. <div class="bp_inp">
  12. <input type="text" v-model="wifiSSID">
  13. </div>
  14. </div>
  15. <div class="b_pre">
  16. <div class="bp_text">密码:</div>
  17. <div class="bp_inp">
  18. <input type="password" v-model="wifiPwd">
  19. </div>
  20. </div>
  21. <div class="zt_btn" @tap="toConnectWiFi">连接</div>
  22. </div>
  23. <div class="box">
  24. <div class="b_title">从下面列表选择2.4GWiFi:</div>
  25. <div class="b_wifi adfac" v-for="(item,index) in wifi2gList" :key="index" @tap="toCode(item)">
  26. <text>{{item.ssid}}</text>
  27. <image src="http://106.54.209.120:8188/static/lock.png"></image>
  28. </div>
  29. </div>
  30. <u-popup :show="show" mode="center" @close="close">
  31. <div class="fail_box adffcacjc">
  32. <image src="http://106.54.209.120:8188/static/connect_off.png"></image>
  33. <text>网络连接失败</text>
  34. <p>请检查你的网络设置后刷新</p>
  35. <div class="zt_btn" @tap="toTryAgain">重试</div>
  36. </div>
  37. </u-popup>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data(){
  43. return {
  44. wifiSSID:'',
  45. wifiPwd:'',
  46. wifi2gList:[],
  47. show:false,
  48. tcp:'',
  49. flag:true
  50. }
  51. },
  52. onLoad() {
  53. this.initWiFi();
  54. },
  55. methods:{
  56. initWiFi(){
  57. uni.showLoading({
  58. title:'获取WiFi列表中'
  59. })
  60. let that = this;
  61. wx.request({
  62. url:'http://192.168.4.1/scan',
  63. success:res=>{
  64. uni.hideLoading();
  65. if(res.errMsg==='request:ok'){
  66. let temp = [];
  67. res.data.forEach(w=>{
  68. if(w.ssid&&w.ssid.indexOf('Xiaozhi')<0){
  69. let exit = temp.find(t=>t.ssid===w.ssid);
  70. if(!exit) temp = [...temp,w]
  71. }
  72. })
  73. that.$nextTick(()=>{
  74. that.wifi2gList = temp;
  75. that.$forceUpdate();
  76. uni.hideLoading();
  77. })
  78. }
  79. },
  80. fail:err=>{
  81. uni.hideLoading();
  82. }
  83. })
  84. },
  85. toConnectWiFi(){
  86. if(!this.wifiPwd) return this.$showToast('请输入密码')
  87. if(!this.flag) return
  88. this.flag = false;
  89. uni.showLoading({
  90. title:'联网中...'
  91. })
  92. let that = this;
  93. wx.request({
  94. url:'http://192.168.4.1/submit',
  95. method:'POST',
  96. data:{
  97. ssid:this.wifiSSID,
  98. password:this.wifiPwd
  99. },
  100. success:res2=>{
  101. if(res2.errMsg!=='request:ok') return that.$showToast('设备联网失败')
  102. wx.request({
  103. url:'http://192.168.4.1/reboot',
  104. method:'POST',
  105. success:res3=>{
  106. if(res3.errMsg!=='request:ok') return that.$showToast('设备重启失败')
  107. that.flag = true;
  108. uni.hideLoading();
  109. that.$showToast('联网成功,设备即将重启')
  110. setTimeout(()=>{
  111. uni.reLaunch({
  112. url:'/pages/home'
  113. })
  114. },1500)
  115. },
  116. fail:err3=>{
  117. that.flag = true;
  118. uni.hideLoading();
  119. }
  120. })
  121. },
  122. fail:err2=>{
  123. that.flag = true;
  124. uni.hideLoading();
  125. }
  126. })
  127. },
  128. close(){
  129. this.show = false;
  130. },
  131. toCode(item){
  132. this.wifiSSID = item.ssid;
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped lang="less">
  138. .page{
  139. background: #F7F7F7;
  140. padding: 0 30rpx 30rpx;
  141. box-sizing: border-box;
  142. .box{
  143. background: #FFFFFF;
  144. border-radius: 16rpx;
  145. padding: 40rpx 30rpx;
  146. margin-top: 20rpx;
  147. .b_top{
  148. image{
  149. width: 114rpx;
  150. height: 114rpx;
  151. }
  152. text{
  153. font-family: PingFang-SC, PingFang-SC;
  154. font-weight: bold;
  155. font-size: 40rpx;
  156. color: #111111;
  157. line-height: 40rpx;
  158. text-align: center;
  159. margin-top: 30rpx;
  160. }
  161. }
  162. .b_pre{
  163. margin-top: 40rpx;
  164. .bp_text{
  165. font-family: PingFang-SC, PingFang-SC;
  166. font-weight: bold;
  167. font-size: 30rpx;
  168. color: #111111;
  169. line-height: 32rpx;
  170. }
  171. .bp_inp{
  172. width: 100%;
  173. height: 90rpx;
  174. border-radius: 16rpx;
  175. border: 1rpx solid #E2E2E2;
  176. margin-top: 24rpx;
  177. padding: 24rpx 40rpx;
  178. box-sizing: border-box;
  179. input{
  180. border: none;
  181. }
  182. }
  183. }
  184. .zt_btn{
  185. margin-top: 40rpx;
  186. }
  187. .b_title{
  188. font-family: PingFang-SC, PingFang-SC;
  189. font-weight: bold;
  190. font-size: 32rpx;
  191. color: #111111;
  192. line-height: 45rpx;
  193. }
  194. .b_wifi{
  195. margin-top: 48rpx;
  196. text{
  197. font-family: PingFangSC, PingFang SC;
  198. font-weight: 400;
  199. font-size: 30rpx;
  200. color: #0066FE;
  201. line-height: 30rpx;
  202. }
  203. image{
  204. width: 36rpx;
  205. height: 36rpx;
  206. margin-left: 10rpx;
  207. }
  208. }
  209. }
  210. .fail_box{
  211. width: 570rpx;
  212. background: #FFFFFF;
  213. border-radius: 28rpx;
  214. padding: 34rpx 125rpx 54rpx;
  215. box-sizing: border-box;
  216. image{
  217. width: 232rpx;
  218. height: 232rpx;
  219. }
  220. text{
  221. font-family: PingFangSC, PingFang SC;
  222. font-weight: 400;
  223. font-size: 30rpx;
  224. color: #333333;
  225. line-height: 42rpx;
  226. margin-top: 10rpx;
  227. }
  228. p{
  229. font-family: PingFangSC, PingFang SC;
  230. font-weight: 400;
  231. font-size: 24rpx;
  232. color: #A6A6A6;
  233. line-height: 24rpx;
  234. margin-top: 24rpx;
  235. }
  236. .zt_btn{
  237. margin-top: 40rpx;
  238. }
  239. }
  240. }
  241. </style>