wifiSearch.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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.开机状态下,按配网键1次进入配网模式</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="tip">序列号:{{lanya.deviceId}}</div>
  36. <div class="btn" @tap="connectWiFi">连接</div>
  37. </div>
  38. </u-popup>
  39. </view>
  40. </template>
  41. <script>
  42. var xBlufi = require("@/utils/blufi/xBlufi.js");
  43. let _this = null;
  44. export default {
  45. data(){
  46. return {
  47. nodevice:false,
  48. show:false,
  49. alertShow:false,
  50. lanya:null,
  51. devicesList: [],
  52. searching: false,
  53. type:''
  54. }
  55. },
  56. onShow() {
  57. this.nodevice = false;
  58. this.show = false;
  59. this.alertShow = false;
  60. this.lanya = null;
  61. this.devicesList = [];
  62. this.searching = false;
  63. xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  64. this.Search();
  65. xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
  66. },
  67. onLoad: function(option) {
  68. this.type = option.type || '';
  69. _this = this;
  70. },
  71. onUnload() {
  72. xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  73. },
  74. methods:{
  75. funListenDeviceMsgEvent: function(options) {
  76. switch (options.type) {
  77. case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
  78. console.log(options,'TYPE_STATUS_CONNECTED')
  79. break;
  80. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
  81. if (options.result)
  82. _this.devicesList = options.data;
  83. let ly = _this.devicesList.find(d=>d.name.indexOf('cx-')>-1);
  84. if(!ly) ly = _this.devicesList.find(d=>d.name.indexOf('BLUFI_DEVICE')>-1);
  85. if(ly){
  86. console.log(ly,'找到设备')
  87. xBlufi.notifyStartDiscoverBle({
  88. 'isStart': false
  89. })
  90. _this.lanya = ly;
  91. _this.nodevice = false;
  92. _this.show = true;
  93. }
  94. break;
  95. case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
  96. if (options.result) {
  97. wx.hideLoading()
  98. wx.showToast({
  99. title: '连接成功',
  100. icon: 'none'
  101. })
  102. console.log(options.data,'连接成功')
  103. wx.navigateTo({
  104. url: '/pagesMy/wifiSet?deviceId=' + options.data.deviceId + '&name=' + options
  105. .data.name+ '&type=' + _this.type
  106. });
  107. } else {
  108. wx.hideLoading()
  109. wx.showModal({
  110. title: '连接失败',
  111. content: '请检查:\n1.设备是否离手机太远;\n2.设备是否已被其他手机连接;\n3.请尝试重启设备后再试。',
  112. showCancel: false
  113. });
  114. }
  115. break;
  116. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
  117. if (!options.result) {
  118. wx.showToast({
  119. title: '蓝牙未开启',
  120. icon: 'none'
  121. })
  122. } else {
  123. //蓝牙搜索开始
  124. _this.searching = true;
  125. }
  126. break;
  127. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
  128. if (options.result) {
  129. //蓝牙停止搜索ok
  130. console.log('蓝牙停止搜索ok')
  131. } else {
  132. //蓝牙停止搜索失败
  133. console.log('蓝牙停止搜索失败')
  134. }
  135. _this.searching = false;
  136. break;
  137. }
  138. },
  139. Search: function() {
  140. if (this.searching) {
  141. xBlufi.notifyStartDiscoverBle({
  142. 'isStart': false
  143. })
  144. } else {
  145. xBlufi.notifyStartDiscoverBle({
  146. 'isStart': true
  147. })
  148. }
  149. },
  150. connectWiFi: function() {
  151. xBlufi.notifyConnectBle({
  152. isStart: true,
  153. deviceId: _this.lanya.deviceId,
  154. name:_this.lanya.name
  155. });
  156. wx.showLoading({
  157. title: '连接蓝牙设备中...',
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style scoped lang="less">
  164. .page{
  165. width: 100%;
  166. padding: 0 0 300rpx;
  167. background: #FFFFFF;
  168. box-sizing: border-box;
  169. .search{
  170. image{
  171. width: 620rpx;
  172. height: 620rpx;
  173. margin-top: 120rpx;
  174. }
  175. p{
  176. font-family: PingFang-SC, PingFang-SC;
  177. font-weight: bold;
  178. font-size: 36rpx;
  179. color: #111111;
  180. line-height: 36rpx;
  181. text-align: center;
  182. margin-top: 80rpx;
  183. }
  184. }
  185. .empty{
  186. .title{
  187. font-family: PingFang-SC, PingFang-SC;
  188. font-weight: bold;
  189. font-size: 36rpx;
  190. color: #111111;
  191. line-height: 36rpx;
  192. text-align: center;
  193. margin-top: 158rpx;
  194. }
  195. &>image{
  196. width: 400rpx;
  197. height: 366rpx;
  198. margin-top: 48rpx;
  199. }
  200. .tip{
  201. font-family: PingFang-SC, PingFang-SC;
  202. font-weight: bold;
  203. font-size: 32rpx;
  204. color: #111111;
  205. line-height: 36rpx;
  206. text-align: center;
  207. margin-top: 53rpx;
  208. }
  209. .warn{
  210. background: rgba(27,80,255,0.06);
  211. border-radius: 28rpx;
  212. padding: 10rpx 24rpx;
  213. margin-top: 48rpx;
  214. image{
  215. width: 26rpx;
  216. height: 26rpx;
  217. }
  218. span{
  219. font-family: PingFangSC, PingFang SC;
  220. font-weight: 400;
  221. font-size: 26rpx;
  222. color: #1B50FF;
  223. line-height: 37rpx;
  224. margin-left: 8rpx;
  225. }
  226. }
  227. }
  228. .zt_btn{
  229. width: calc(100% - 120rpx);
  230. position: fixed;
  231. left: 60rpx;
  232. bottom: 201rpx;
  233. }
  234. .alert{
  235. padding: 54rpx 40rpx 0;
  236. .title{
  237. font-family: PingFang-SC, PingFang-SC;
  238. font-weight: bold;
  239. font-size: 36rpx;
  240. color: #111111;
  241. line-height: 36rpx;
  242. text-align: center;
  243. margin-bottom: 19rpx;
  244. }
  245. p{
  246. font-family: PingFangSC, PingFang SC;
  247. font-weight: 400;
  248. font-size: 30rpx;
  249. color: #111111;
  250. line-height: 65rpx;
  251. text-align: left;
  252. margin-top: 24rpx;
  253. }
  254. .btn{
  255. width: calc(100% - 108rpx);
  256. height: 90rpx;
  257. background: #D9F159;
  258. border-radius: 16rpx;
  259. font-family: PingFang-SC, PingFang-SC;
  260. font-weight: bold;
  261. font-size: 32rpx;
  262. color: #252525;
  263. line-height: 90rpx;
  264. text-align: center;
  265. margin: 113rpx 54rpx 0;
  266. letter-spacing: 2rpx;
  267. }
  268. }
  269. .connect{
  270. padding: 66rpx 40rpx 30rpx;
  271. .title{
  272. font-family: PingFangSC, PingFang SC;
  273. font-weight: 600;
  274. font-size: 36rpx;
  275. color: #111111;
  276. line-height: 36rpx;
  277. text-align: center;
  278. }
  279. image{
  280. width: 504rpx;
  281. height: 254rpx;
  282. margin-top: 37rpx;
  283. }
  284. .tip{
  285. font-family: PingFangSC, PingFang SC;
  286. font-weight: 400;
  287. font-size: 30rpx;
  288. color: #111111;
  289. line-height: 36rpx;
  290. margin-top: 40rpx;
  291. }
  292. .btn{
  293. width: 100%;
  294. height: 90rpx;
  295. background: #D9F159;
  296. border-radius: 16rpx;
  297. font-family: PingFang-SC, PingFang-SC;
  298. font-weight: bold;
  299. font-size: 32rpx;
  300. color: #252525;
  301. line-height: 90rpx;
  302. text-align: center;
  303. margin-top: 101rpx;
  304. letter-spacing: 2rpx;
  305. }
  306. }
  307. }
  308. </style>