wifiSearch.vue 7.4 KB

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