wifiSearch.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='配置网络'></cus-header>
  4. <template v-if="!nodevice">
  5. <div class="search adffcac">
  6. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/379c752c-13f5-4668-9977-e8cad9cd0fa4.gif"></image>
  7. <p>正在搜索可配网设备</p>
  8. </div>
  9. </template>
  10. <template v-else>
  11. <div class="empty adffcac">
  12. <div class="title">搜索超时</div>
  13. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/5824159f-0bd8-4399-be6c-7d309e2a35dc.png"></image>
  14. <div class="tip">没有找到可用设备</div>
  15. <div class="warn adfac" @tap="alertShow=true">
  16. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/19ca1b06-9bfd-4ae6-9c1c-eec45a86f0a0.png"></image>
  17. <span>找不到设备怎么办 ></span>
  18. </div>
  19. </div>
  20. </template>
  21. <div class="zt_btn" v-if="nodevice" @tap="searchAgain">再次搜索</div>
  22. <u-popup :show="alertShow" :round="56" mode="center" @close="alertShow=false">
  23. <div class="alert">
  24. <div class="title">找不到设备怎么办</div>
  25. <p style="margin-top: 53rpx;">1.请确保可配网的设备在手机旁边</p>
  26. <p>2.如果没有开机,请先按住开关键直到指示灯亮起</p>
  27. <p>3.开机状态下,按住开关键3秒进入配网模式</p>
  28. <div class="btn" @tap="alertShow=false">我知道了</div>
  29. </div>
  30. </u-popup>
  31. <u-popup :show="show" :round="64" mode="bottom" @close="show=false">
  32. <div class="connect adffcac">
  33. <div class="title">找到一个待配网的设备</div>
  34. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/6f06a2de-5d6c-4596-9a0c-77971d6ea230.png"></image>
  35. <div class="btn" @tap="connectWiFi">连接</div>
  36. </div>
  37. </u-popup>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data(){
  43. return {
  44. nodevice:false,
  45. show:false,
  46. alertShow:false,
  47. flag:true,
  48. deviceWifi:null
  49. }
  50. },
  51. onReady() {
  52. this.checkWifi();
  53. },
  54. methods:{
  55. checkWifi(){
  56. let that = this;
  57. wx.startWifi({
  58. success(res){
  59. wx.getConnectedWifi({
  60. success(res2){
  61. if(res2.errCode===0){
  62. that.nodevice = false;
  63. that.deviceModelDeal();
  64. }
  65. },
  66. fail: (err2) => {
  67. if(err2.errMsg.indexOf('getConnectedWifi:fail:wifi is disable')>-1){
  68. that.$showModal('当前WiFi未开启,请先开启WiFi后再进行设备搜索。');
  69. that.nodevice = true;
  70. }
  71. }
  72. })
  73. },
  74. fail: (err) => {
  75. that.nodevice = true;
  76. }
  77. })
  78. },
  79. deviceModelDeal(){
  80. let sysInfo = wx.getSystemInfoSync();
  81. this.platform = sysInfo?.platform;
  82. if(this.platform=='ios'){
  83. uni.showModal({
  84. title:'温馨提示',
  85. content:'检测到您的手机为ios系统,即将自动跳转设置-微信,需要您在设置中打开无线局域网,等待获取到WiFi列表后再返回小程序进行设备搜索。',
  86. success: (res) => {
  87. if(res.confirm){
  88. this.searchWifi()
  89. }
  90. }
  91. })
  92. }else{
  93. this.searchWifi()
  94. }
  95. },
  96. searchWifi(){
  97. let that = this;
  98. wx.startWifi({
  99. success (res) {
  100. wx.getWifiList({
  101. success(res2) {
  102. wx.onGetWifiList(res3 => {
  103. let temp = [];
  104. res3.wifiList.forEach(w=>{
  105. if(w.SSID){
  106. let exit = temp.find(t=>t.SSID===w.SSID);
  107. if(!exit) temp = [...temp,w]
  108. }
  109. })
  110. that.$nextTick(()=>{
  111. let wifi = temp.find(t=>t.SSID.indexOf('Xiaozhi')>-1)
  112. if(wifi){
  113. that.deviceWifi = wifi;
  114. that.show = true;
  115. }else{
  116. that.nodevice = true;
  117. }
  118. })
  119. })
  120. },
  121. fail: (err2) => {
  122. that.$showModal("getWifiList:err:"+JSON.stringify(err2))
  123. }
  124. })
  125. },
  126. fail: (err) => {
  127. that.$showModal("startWifi:err:"+JSON.stringify(err))
  128. }
  129. })
  130. },
  131. searchAgain(){
  132. this.nodevice = false;
  133. this.deviceModelDeal();
  134. },
  135. connectWiFi(){
  136. if(!this.flag) return
  137. this.flag = false;
  138. uni.showLoading({
  139. title:'热点连接中'
  140. })
  141. let that = this;
  142. wx.connectWifi({
  143. SSID: this.deviceWifi.SSID,
  144. password: '',
  145. success: (res) => {
  146. uni.hideLoading();
  147. that.flag = true;
  148. setTimeout(()=>{
  149. uni.navigateTo({
  150. url:'/pagesMy/wifiSet'
  151. })
  152. },2000)
  153. },
  154. fail: (err) => {
  155. uni.hideLoading();
  156. that.flag = true;
  157. that.$showModal("connectWifi:err:"+JSON.stringify(err))
  158. }
  159. });
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped lang="less">
  165. .page{
  166. width: 100%;
  167. padding: 0 0 300rpx;
  168. background: #FFFFFF;
  169. box-sizing: border-box;
  170. .search{
  171. image{
  172. width: 620rpx;
  173. height: 620rpx;
  174. margin-top: 120rpx;
  175. }
  176. p{
  177. font-family: PingFang-SC, PingFang-SC;
  178. font-weight: bold;
  179. font-size: 36rpx;
  180. color: #111111;
  181. line-height: 36rpx;
  182. text-align: center;
  183. margin-top: 80rpx;
  184. }
  185. }
  186. .empty{
  187. .title{
  188. font-family: PingFang-SC, PingFang-SC;
  189. font-weight: bold;
  190. font-size: 36rpx;
  191. color: #111111;
  192. line-height: 36rpx;
  193. text-align: center;
  194. margin-top: 158rpx;
  195. }
  196. &>image{
  197. width: 400rpx;
  198. height: 366rpx;
  199. margin-top: 48rpx;
  200. }
  201. .tip{
  202. font-family: PingFang-SC, PingFang-SC;
  203. font-weight: bold;
  204. font-size: 32rpx;
  205. color: #111111;
  206. line-height: 36rpx;
  207. text-align: center;
  208. margin-top: 53rpx;
  209. }
  210. .warn{
  211. background: rgba(27,80,255,0.06);
  212. border-radius: 28rpx;
  213. padding: 10rpx 24rpx;
  214. margin-top: 48rpx;
  215. image{
  216. width: 26rpx;
  217. height: 26rpx;
  218. }
  219. span{
  220. font-family: PingFangSC, PingFang SC;
  221. font-weight: 400;
  222. font-size: 26rpx;
  223. color: #1B50FF;
  224. line-height: 37rpx;
  225. margin-left: 8rpx;
  226. }
  227. }
  228. }
  229. .zt_btn{
  230. width: calc(100% - 120rpx);
  231. position: fixed;
  232. left: 60rpx;
  233. bottom: 201rpx;
  234. }
  235. .alert{
  236. padding: 54rpx 40rpx 0;
  237. .title{
  238. font-family: PingFang-SC, PingFang-SC;
  239. font-weight: bold;
  240. font-size: 36rpx;
  241. color: #111111;
  242. line-height: 36rpx;
  243. text-align: center;
  244. margin-bottom: 19rpx;
  245. }
  246. p{
  247. font-family: PingFangSC, PingFang SC;
  248. font-weight: 400;
  249. font-size: 30rpx;
  250. color: #111111;
  251. line-height: 65rpx;
  252. text-align: left;
  253. margin-top: 24rpx;
  254. }
  255. .btn{
  256. width: calc(100% - 108rpx);
  257. height: 90rpx;
  258. background: #D9F159;
  259. border-radius: 16rpx;
  260. font-family: PingFang-SC, PingFang-SC;
  261. font-weight: bold;
  262. font-size: 32rpx;
  263. color: #252525;
  264. line-height: 90rpx;
  265. text-align: center;
  266. margin: 113rpx 54rpx 0;
  267. letter-spacing: 2rpx;
  268. }
  269. }
  270. .connect{
  271. padding: 66rpx 40rpx 30rpx;
  272. .title{
  273. font-family: PingFangSC, PingFang SC;
  274. font-weight: 600;
  275. font-size: 36rpx;
  276. color: #111111;
  277. line-height: 36rpx;
  278. text-align: center;
  279. }
  280. image{
  281. width: 504rpx;
  282. height: 254rpx;
  283. margin-top: 104rpx;
  284. }
  285. .btn{
  286. width: 100%;
  287. height: 90rpx;
  288. background: #D9F159;
  289. border-radius: 16rpx;
  290. font-family: PingFang-SC, PingFang-SC;
  291. font-weight: bold;
  292. font-size: 32rpx;
  293. color: #252525;
  294. line-height: 90rpx;
  295. text-align: center;
  296. margin-top: 110rpx;
  297. letter-spacing: 2rpx;
  298. }
  299. }
  300. }
  301. </style>