wifiSet.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. uni.navigateTo({
  113. url:'/pagesMy/wifiSuccess'
  114. })
  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. toTryAgain(){
  135. this.show = false;
  136. this.toConnectWiFi();
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped lang="less">
  142. .page{
  143. background: #F7F7F7;
  144. padding: 0 30rpx 30rpx;
  145. box-sizing: border-box;
  146. .box{
  147. background: #FFFFFF;
  148. border-radius: 16rpx;
  149. padding: 40rpx 30rpx;
  150. margin-top: 20rpx;
  151. .b_top{
  152. image{
  153. width: 114rpx;
  154. height: 114rpx;
  155. }
  156. text{
  157. font-family: PingFang-SC, PingFang-SC;
  158. font-weight: bold;
  159. font-size: 40rpx;
  160. color: #111111;
  161. line-height: 40rpx;
  162. text-align: center;
  163. margin-top: 30rpx;
  164. }
  165. }
  166. .b_pre{
  167. margin-top: 40rpx;
  168. .bp_text{
  169. font-family: PingFang-SC, PingFang-SC;
  170. font-weight: bold;
  171. font-size: 30rpx;
  172. color: #111111;
  173. line-height: 32rpx;
  174. }
  175. .bp_inp{
  176. width: 100%;
  177. height: 90rpx;
  178. border-radius: 16rpx;
  179. border: 1rpx solid #E2E2E2;
  180. margin-top: 24rpx;
  181. padding: 24rpx 40rpx;
  182. box-sizing: border-box;
  183. input{
  184. border: none;
  185. }
  186. }
  187. }
  188. .zt_btn{
  189. margin-top: 40rpx;
  190. }
  191. .b_title{
  192. font-family: PingFang-SC, PingFang-SC;
  193. font-weight: bold;
  194. font-size: 32rpx;
  195. color: #111111;
  196. line-height: 45rpx;
  197. }
  198. .b_wifi{
  199. margin-top: 48rpx;
  200. text{
  201. font-family: PingFangSC, PingFang SC;
  202. font-weight: 400;
  203. font-size: 30rpx;
  204. color: #0066FE;
  205. line-height: 30rpx;
  206. }
  207. image{
  208. width: 36rpx;
  209. height: 36rpx;
  210. margin-left: 10rpx;
  211. }
  212. }
  213. }
  214. .fail_box{
  215. width: 570rpx;
  216. background: #FFFFFF;
  217. border-radius: 28rpx;
  218. padding: 34rpx 125rpx 54rpx;
  219. box-sizing: border-box;
  220. image{
  221. width: 232rpx;
  222. height: 232rpx;
  223. }
  224. text{
  225. font-family: PingFangSC, PingFang SC;
  226. font-weight: 400;
  227. font-size: 30rpx;
  228. color: #333333;
  229. line-height: 42rpx;
  230. margin-top: 10rpx;
  231. }
  232. p{
  233. font-family: PingFangSC, PingFang SC;
  234. font-weight: 400;
  235. font-size: 24rpx;
  236. color: #A6A6A6;
  237. line-height: 24rpx;
  238. margin-top: 24rpx;
  239. }
  240. .zt_btn{
  241. margin-top: 40rpx;
  242. }
  243. }
  244. }
  245. </style>