wifiSearch.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. that.nodevice = false;
  62. that.deviceModelDeal();
  63. },
  64. fail: (err2) => {
  65. if(err2.errMsg.indexOf('getConnectedWifi:fail:wifi is disable')>-1){
  66. that.$showModal('当前WiFi未开启,请先开启WiFi后再进行设备搜索。');
  67. that.nodevice = true;
  68. }
  69. }
  70. })
  71. },
  72. fail: (err) => {
  73. that.nodevice = true;
  74. }
  75. })
  76. },
  77. deviceModelDeal(){
  78. let sysInfo = wx.getSystemInfoSync();
  79. this.platform = sysInfo?.platform;
  80. if(this.platform=='ios'){
  81. uni.showModal({
  82. title:'温馨提示',
  83. content:'检测到您的手机为ios系统,即将自动跳转设置-微信,需要您在设置中打开无线局域网,等待获取到WiFi列表后再返回小程序进行设备搜索。',
  84. success: (res) => {
  85. if(res.confirm){
  86. this.searchWifi()
  87. }
  88. }
  89. })
  90. }else{
  91. this.searchWifi()
  92. }
  93. },
  94. searchWifi(){
  95. let that = this;
  96. wx.startWifi({
  97. success (res) {
  98. wx.getWifiList({
  99. success(res2) {
  100. wx.onGetWifiList(res3 => {
  101. let temp = [];
  102. res3.wifiList.forEach(w=>{
  103. if(w.SSID){
  104. let exit = temp.find(t=>t.SSID===w.SSID);
  105. if(!exit) temp = [...temp,w]
  106. }
  107. })
  108. that.$nextTick(()=>{
  109. let wifi = temp.find(t=>t.SSID.indexOf('Xiaozhi')>-1)
  110. if(wifi){
  111. that.deviceWifi = wifi;
  112. that.show = true;
  113. }else{
  114. that.nodevice = true;
  115. }
  116. })
  117. })
  118. },
  119. fail: (err2) => {
  120. that.$showModal("getWifiList:err:"+JSON.stringify(err2))
  121. }
  122. })
  123. },
  124. fail: (err) => {
  125. that.$showModal("startWifi:err:"+JSON.stringify(err))
  126. }
  127. })
  128. },
  129. searchAgain(){
  130. this.nodevice = false;
  131. this.deviceModelDeal();
  132. },
  133. connectWiFi(){
  134. if(!this.flag) return
  135. this.flag = false;
  136. let that = this;
  137. wx.connectWifi({
  138. SSID: this.deviceWifi.SSID,
  139. password: '',
  140. success: (res) => {
  141. that.flag = true;
  142. uni.navigateTo({
  143. url:'/pagesMy/wifiSet'
  144. })
  145. },
  146. fail: (err) => {
  147. that.flag = true;
  148. that.$showModal("connectWifi:err:"+JSON.stringify(err))
  149. }
  150. });
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped lang="less">
  156. .page{
  157. width: 100%;
  158. padding: 0 0 300rpx;
  159. background: #FFFFFF;
  160. box-sizing: border-box;
  161. .search{
  162. image{
  163. width: 620rpx;
  164. height: 620rpx;
  165. margin-top: 120rpx;
  166. }
  167. p{
  168. font-family: PingFang-SC, PingFang-SC;
  169. font-weight: bold;
  170. font-size: 36rpx;
  171. color: #111111;
  172. line-height: 36rpx;
  173. text-align: center;
  174. margin-top: 80rpx;
  175. }
  176. }
  177. .empty{
  178. .title{
  179. font-family: PingFang-SC, PingFang-SC;
  180. font-weight: bold;
  181. font-size: 36rpx;
  182. color: #111111;
  183. line-height: 36rpx;
  184. text-align: center;
  185. margin-top: 158rpx;
  186. }
  187. &>image{
  188. width: 400rpx;
  189. height: 366rpx;
  190. margin-top: 48rpx;
  191. }
  192. .tip{
  193. font-family: PingFang-SC, PingFang-SC;
  194. font-weight: bold;
  195. font-size: 32rpx;
  196. color: #111111;
  197. line-height: 36rpx;
  198. text-align: center;
  199. margin-top: 53rpx;
  200. }
  201. .warn{
  202. background: rgba(27,80,255,0.06);
  203. border-radius: 28rpx;
  204. padding: 10rpx 24rpx;
  205. margin-top: 48rpx;
  206. image{
  207. width: 26rpx;
  208. height: 26rpx;
  209. }
  210. span{
  211. font-family: PingFangSC, PingFang SC;
  212. font-weight: 400;
  213. font-size: 26rpx;
  214. color: #1B50FF;
  215. line-height: 37rpx;
  216. margin-left: 8rpx;
  217. }
  218. }
  219. }
  220. .zt_btn{
  221. width: calc(100% - 120rpx);
  222. position: fixed;
  223. left: 60rpx;
  224. bottom: 201rpx;
  225. }
  226. .alert{
  227. padding: 54rpx 40rpx 0;
  228. .title{
  229. font-family: PingFang-SC, PingFang-SC;
  230. font-weight: bold;
  231. font-size: 36rpx;
  232. color: #111111;
  233. line-height: 36rpx;
  234. text-align: center;
  235. margin-bottom: 19rpx;
  236. }
  237. p{
  238. font-family: PingFangSC, PingFang SC;
  239. font-weight: 400;
  240. font-size: 30rpx;
  241. color: #111111;
  242. line-height: 65rpx;
  243. text-align: left;
  244. margin-top: 24rpx;
  245. }
  246. .btn{
  247. width: calc(100% - 108rpx);
  248. height: 90rpx;
  249. background: #D9F159;
  250. border-radius: 16rpx;
  251. font-family: PingFang-SC, PingFang-SC;
  252. font-weight: bold;
  253. font-size: 32rpx;
  254. color: #252525;
  255. line-height: 90rpx;
  256. text-align: center;
  257. margin: 113rpx 54rpx 0;
  258. letter-spacing: 2rpx;
  259. }
  260. }
  261. .connect{
  262. padding: 66rpx 40rpx 30rpx;
  263. .title{
  264. font-family: PingFangSC, PingFang SC;
  265. font-weight: 600;
  266. font-size: 36rpx;
  267. color: #111111;
  268. line-height: 36rpx;
  269. text-align: center;
  270. }
  271. image{
  272. width: 504rpx;
  273. height: 254rpx;
  274. margin-top: 104rpx;
  275. }
  276. .btn{
  277. width: 100%;
  278. height: 90rpx;
  279. background: #D9F159;
  280. border-radius: 16rpx;
  281. font-family: PingFang-SC, PingFang-SC;
  282. font-weight: bold;
  283. font-size: 32rpx;
  284. color: #252525;
  285. line-height: 90rpx;
  286. text-align: center;
  287. margin-top: 110rpx;
  288. letter-spacing: 2rpx;
  289. }
  290. }
  291. }
  292. </style>