wifiSet.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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'){
  102. that.show = true;
  103. return
  104. }
  105. wx.request({
  106. url:'http://192.168.4.1/reboot',
  107. method:'POST',
  108. success:res3=>{
  109. if(res3.errMsg!=='request:ok') return that.$showToast('设备重启失败')
  110. that.flag = true;
  111. uni.hideLoading();
  112. setTimeout(()=>{
  113. uni.navigateTo({
  114. url:'/pagesMy/wifiSuccess'
  115. })
  116. },2000)
  117. },
  118. fail:err3=>{
  119. that.flag = true;
  120. uni.hideLoading();
  121. }
  122. })
  123. },
  124. fail:err2=>{
  125. that.flag = true;
  126. uni.hideLoading();
  127. }
  128. })
  129. },
  130. close(){
  131. this.show = false;
  132. },
  133. toCode(item){
  134. this.wifiSSID = item.ssid;
  135. },
  136. toTryAgain(){
  137. this.show = false;
  138. this.toConnectWiFi();
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped lang="less">
  144. .page{
  145. background: #F7F7F7;
  146. padding: 0 30rpx 30rpx;
  147. box-sizing: border-box;
  148. .box{
  149. background: #FFFFFF;
  150. border-radius: 16rpx;
  151. padding: 40rpx 30rpx;
  152. margin-top: 20rpx;
  153. .b_top{
  154. image{
  155. width: 114rpx;
  156. height: 114rpx;
  157. }
  158. text{
  159. font-family: PingFang-SC, PingFang-SC;
  160. font-weight: bold;
  161. font-size: 40rpx;
  162. color: #111111;
  163. line-height: 40rpx;
  164. text-align: center;
  165. margin-top: 30rpx;
  166. }
  167. }
  168. .b_pre{
  169. margin-top: 40rpx;
  170. .bp_text{
  171. font-family: PingFang-SC, PingFang-SC;
  172. font-weight: bold;
  173. font-size: 30rpx;
  174. color: #111111;
  175. line-height: 32rpx;
  176. }
  177. .bp_inp{
  178. width: 100%;
  179. height: 90rpx;
  180. border-radius: 16rpx;
  181. border: 1rpx solid #E2E2E2;
  182. margin-top: 24rpx;
  183. padding: 24rpx 40rpx;
  184. box-sizing: border-box;
  185. input{
  186. border: none;
  187. }
  188. }
  189. }
  190. .zt_btn{
  191. margin-top: 40rpx;
  192. }
  193. .b_title{
  194. font-family: PingFang-SC, PingFang-SC;
  195. font-weight: bold;
  196. font-size: 32rpx;
  197. color: #111111;
  198. line-height: 45rpx;
  199. }
  200. .b_wifi{
  201. margin-top: 48rpx;
  202. text{
  203. font-family: PingFangSC, PingFang SC;
  204. font-weight: 400;
  205. font-size: 30rpx;
  206. color: #0066FE;
  207. line-height: 30rpx;
  208. }
  209. image{
  210. width: 36rpx;
  211. height: 36rpx;
  212. margin-left: 10rpx;
  213. }
  214. }
  215. }
  216. .fail_box{
  217. width: 570rpx;
  218. background: #FFFFFF;
  219. border-radius: 28rpx;
  220. padding: 34rpx 125rpx 54rpx;
  221. box-sizing: border-box;
  222. image{
  223. width: 232rpx;
  224. height: 232rpx;
  225. }
  226. text{
  227. font-family: PingFangSC, PingFang SC;
  228. font-weight: 400;
  229. font-size: 30rpx;
  230. color: #333333;
  231. line-height: 42rpx;
  232. margin-top: 10rpx;
  233. }
  234. p{
  235. font-family: PingFangSC, PingFang SC;
  236. font-weight: 400;
  237. font-size: 24rpx;
  238. color: #A6A6A6;
  239. line-height: 24rpx;
  240. margin-top: 24rpx;
  241. }
  242. .zt_btn{
  243. margin-top: 40rpx;
  244. }
  245. }
  246. }
  247. </style>