wifiSearch.vue 7.5 KB

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