wifiSet.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f1cc6aee-2d47-46f0-ae29-3ef4923777cb.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="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/c303f95d-ecd9-449e-bdc6-fc79a54de338.png"></image>
  28. </div>
  29. </div>
  30. <u-popup :show="show" mode="center" @close="close">
  31. <div class="fail_box adffcacjc">
  32. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f62889e7-ebdd-4351-b4b2-d6d82070d202.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. console.log(res,'res');
  65. uni.hideLoading();
  66. if(res.errMsg==='request:ok'){
  67. let temp = [];
  68. res.data.forEach(w=>{
  69. if(w.ssid&&w.ssid.indexOf('Xiaozhi')<0){
  70. let exit = temp.find(t=>t.ssid===w.ssid);
  71. if(!exit) temp = [...temp,w]
  72. }
  73. })
  74. that.$nextTick(()=>{
  75. that.wifi2gList = temp;
  76. that.$forceUpdate();
  77. uni.hideLoading();
  78. })
  79. }
  80. },
  81. fail:err=>{
  82. uni.hideLoading();
  83. }
  84. })
  85. },
  86. toConnectWiFi(){
  87. if(!this.wifiSSID) return this.$showToast('请从下方选择一个wifi进行连接')
  88. if(!this.wifiPwd) return this.$showToast('请输入密码')
  89. if(!this.flag) return
  90. this.flag = false;
  91. uni.showLoading({
  92. title:'联网中...'
  93. })
  94. let that = this;
  95. wx.request({
  96. url:'http://192.168.4.1/submit',
  97. method:'POST',
  98. data:{
  99. ssid:this.wifiSSID,
  100. password:this.wifiPwd
  101. },
  102. success:res2=>{
  103. console.log(res2,'res2');
  104. if(res2.errMsg!=='request:ok'||!res2.data.success){
  105. uni.hideLoading();
  106. that.show = true;
  107. that.flag = true;
  108. return
  109. }
  110. wx.request({
  111. url:'http://192.168.4.1/reboot',
  112. method:'POST',
  113. success:res3=>{
  114. if(res3.errMsg!=='request:ok'){
  115. that.$showToast('设备重启失败')
  116. return
  117. }
  118. that.flag = true;
  119. uni.hideLoading();
  120. setTimeout(()=>{
  121. uni.navigateTo({
  122. url:'/pagesMy/wifiSuccess'
  123. })
  124. },2000)
  125. },
  126. fail:err3=>{
  127. console.log(err3,'err3');
  128. that.flag = true;
  129. that.$showModal(JSON.stringify(err3));
  130. uni.hideLoading();
  131. }
  132. })
  133. },
  134. fail:err2=>{
  135. console.log(err2,'err2');
  136. that.flag = true;
  137. that.$showModal(JSON.stringify(err2));
  138. uni.hideLoading();
  139. }
  140. })
  141. },
  142. close(){
  143. this.show = false;
  144. },
  145. toCode(item){
  146. this.wifiSSID = item.ssid;
  147. },
  148. toTryAgain(){
  149. this.show = false;
  150. this.flag = true;
  151. this.toConnectWiFi();
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped lang="less">
  157. .page{
  158. background: #F7F7F7;
  159. padding: 0 30rpx 30rpx;
  160. box-sizing: border-box;
  161. .box{
  162. background: #FFFFFF;
  163. border-radius: 16rpx;
  164. padding: 40rpx 30rpx;
  165. margin-top: 20rpx;
  166. .b_top{
  167. image{
  168. width: 114rpx;
  169. height: 114rpx;
  170. }
  171. text{
  172. font-family: PingFang-SC, PingFang-SC;
  173. font-weight: bold;
  174. font-size: 40rpx;
  175. color: #111111;
  176. line-height: 40rpx;
  177. text-align: center;
  178. margin-top: 30rpx;
  179. }
  180. }
  181. .b_pre{
  182. margin-top: 40rpx;
  183. .bp_text{
  184. font-family: PingFang-SC, PingFang-SC;
  185. font-weight: bold;
  186. font-size: 30rpx;
  187. color: #111111;
  188. line-height: 32rpx;
  189. }
  190. .bp_inp{
  191. width: 100%;
  192. height: 90rpx;
  193. border-radius: 16rpx;
  194. border: 1rpx solid #E2E2E2;
  195. margin-top: 24rpx;
  196. padding: 24rpx 40rpx;
  197. box-sizing: border-box;
  198. input{
  199. border: none;
  200. }
  201. }
  202. }
  203. .zt_btn{
  204. margin-top: 40rpx;
  205. }
  206. .b_title{
  207. font-family: PingFang-SC, PingFang-SC;
  208. font-weight: bold;
  209. font-size: 32rpx;
  210. color: #111111;
  211. line-height: 45rpx;
  212. }
  213. .b_wifi{
  214. margin-top: 48rpx;
  215. text{
  216. font-family: PingFangSC, PingFang SC;
  217. font-weight: 400;
  218. font-size: 30rpx;
  219. color: #0066FE;
  220. line-height: 30rpx;
  221. }
  222. image{
  223. width: 36rpx;
  224. height: 36rpx;
  225. margin-left: 10rpx;
  226. }
  227. }
  228. }
  229. .fail_box{
  230. width: 570rpx;
  231. background: #FFFFFF;
  232. border-radius: 28rpx;
  233. padding: 34rpx 125rpx 54rpx;
  234. box-sizing: border-box;
  235. image{
  236. width: 232rpx;
  237. height: 232rpx;
  238. }
  239. text{
  240. font-family: PingFangSC, PingFang SC;
  241. font-weight: 400;
  242. font-size: 30rpx;
  243. color: #333333;
  244. line-height: 42rpx;
  245. margin-top: 10rpx;
  246. }
  247. p{
  248. font-family: PingFangSC, PingFang SC;
  249. font-weight: 400;
  250. font-size: 24rpx;
  251. color: #A6A6A6;
  252. line-height: 24rpx;
  253. margin-top: 24rpx;
  254. text-align: center;
  255. }
  256. .zt_btn{
  257. margin-top: 40rpx;
  258. }
  259. }
  260. }
  261. </style>