wifiConnect.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='配置网络'></cus-header>
  4. <div class="title">设备配网&绑定</div>
  5. <div class="tip">服务器需要对设备进行配置,网络不好的情况,可能需要写时间,请耐心等待。</div>
  6. <div class="box adffcacjc">
  7. <image src="@/static/connect.png"></image>
  8. <div class="text">正在连接设备</div>
  9. <div class="memo">连接过程请勿关闭小程序或者设备</div>
  10. </div>
  11. <u-popup :show="show" :round="56" mode="center" @close="close">
  12. <div class="fail_box adffcacjc">
  13. <image src="@/static/connect_off.png"></image>
  14. <text>网络连接失败</text>
  15. <p>请检查你的网络连接后重试</p>
  16. <div class="btns adfacjb">
  17. <div class="qx_btn" @tap="goBack">返回</div>
  18. <div class="zt_btn" @tap="toTryAgain">重试</div>
  19. </div>
  20. </div>
  21. </u-popup>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data(){
  27. return {
  28. wifiSSID:'',
  29. wifiPWD:'',
  30. show:false
  31. }
  32. },
  33. onLoad(option) {
  34. this.wifiSSID = option?.wifiSSID;
  35. this.wifiPWD = option?.wifiPWD;
  36. this.connectWifi();
  37. },
  38. methods:{
  39. connectWifi(){
  40. let that = this;
  41. wx.request({
  42. url:'http://192.168.4.1/submit',
  43. method:'POST',
  44. data:{
  45. ssid:that.wifiSSID,
  46. password:that.wifiPWD
  47. },
  48. success:res=>{
  49. if(res.errMsg!=='request:ok'||!res.data.success){
  50. that.show = true;
  51. return
  52. }
  53. wx.request({
  54. url:'http://192.168.4.1/reboot',
  55. method:'POST',
  56. success:res2=>{
  57. if(res2.errMsg!=='request:ok'){
  58. that.$showToast('设备重启失败')
  59. return
  60. }
  61. setTimeout(()=>{
  62. uni.navigateTo({
  63. url:'/pagesMy/wifiSuccess'
  64. })
  65. },1000)
  66. },
  67. fail:err2=>{
  68. that.$showModal("reboot:err:"+JSON.stringify(err2))
  69. }
  70. })
  71. },
  72. fail:err=>{
  73. that.show = true;
  74. that.$showModal("submit:err:"+JSON.stringify(err))
  75. }
  76. })
  77. },
  78. goBack(){
  79. uni.redirectTo({
  80. url:'/pagesMy/wifiSearch'
  81. })
  82. },
  83. toTryAgain(){
  84. this.show = false;
  85. this.connectWifi();
  86. }
  87. }
  88. }
  89. </script>
  90. <style scoped lang="less">
  91. .page{
  92. padding: 0 40rpx 40rpx;
  93. box-sizing: border-box;
  94. background: #FFFFFF;
  95. .title{
  96. font-family: PingFang-SC, PingFang-SC;
  97. font-weight: bold;
  98. font-size: 36rpx;
  99. color: #111111;
  100. line-height: 36rpx;
  101. margin-top: 64rpx;
  102. }
  103. .tip{
  104. font-family: PingFangSC, PingFang SC;
  105. font-weight: 400;
  106. font-size: 26rpx;
  107. color: #111111;
  108. line-height: 40rpx;
  109. margin-top: 30rpx;
  110. }
  111. .box{
  112. margin-top: 154rpx;
  113. image{
  114. width: 240rpx;
  115. height: 309rpx;
  116. }
  117. .text{
  118. font-family: PingFang-SC, PingFang-SC;
  119. font-weight: bold;
  120. font-size: 36rpx;
  121. color: #111111;
  122. line-height: 36rpx;
  123. text-align: center;
  124. margin-top: 43rpx;
  125. }
  126. .memo{
  127. font-family: PingFangSC, PingFang SC;
  128. font-weight: 400;
  129. font-size: 28rpx;
  130. color: #7C8592;
  131. line-height: 42rpx;
  132. text-align: center;
  133. margin-top: 30rpx;
  134. }
  135. }
  136. .fail_box{
  137. width: 670rpx;
  138. background: #FFFFFF;
  139. border-radius: 28rpx;
  140. padding: 34rpx 60rpx 54rpx;
  141. box-sizing: border-box;
  142. image{
  143. width: 232rpx;
  144. height: 232rpx;
  145. }
  146. text{
  147. font-family: PingFangSC, PingFang SC;
  148. font-weight: 400;
  149. font-size: 30rpx;
  150. color: #333333;
  151. line-height: 42rpx;
  152. margin-top: 10rpx;
  153. }
  154. p{
  155. font-family: PingFangSC, PingFang SC;
  156. font-weight: 400;
  157. font-size: 24rpx;
  158. color: #A6A6A6;
  159. line-height: 24rpx;
  160. margin-top: 24rpx;
  161. text-align: center;
  162. }
  163. .btns{
  164. width: 100%;
  165. margin-top: 40rpx;
  166. &>div{
  167. width: calc(50% - 15rpx);
  168. }
  169. }
  170. }
  171. }
  172. </style>