wifiSearch.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.Search();
  60. },
  61. onLoad: function(option) {
  62. this.type = option.type || '';
  63. _this = this;
  64. this.Search();
  65. // xBlufi.initXBlufi(1);
  66. xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
  67. },
  68. onUnload() {
  69. xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  70. },
  71. methods:{
  72. initBluetooth() {
  73. let that = this;
  74. try{
  75. wx.openBluetoothAdapter({
  76. success: (res) => {
  77. // 监听连接状态变化
  78. wx.onBLEConnectionStateChange((res2) => {
  79. console.log(res2,'onBLEConnectionStateChange');
  80. });
  81. wx.startBluetoothDevicesDiscovery({
  82. services: ['0000FFFF-0000-1000-8000-00805F9B34FB'], // Blufi服务UUID
  83. success: (res3) => {
  84. // 监听发现新设备
  85. wx.onBluetoothDeviceFound((resu) => {
  86. let ly = resu.devices.find(d=>d.name.indexOf('cx-')>-1);
  87. if(ly){
  88. that.lanya = ly;
  89. that.nodevice = false;
  90. that.show = true;
  91. }
  92. });
  93. },
  94. fail: (err2) => {
  95. console.log(err2,'err2');
  96. }
  97. });
  98. },
  99. fail: (err) => {
  100. console.log(err,'初始化失败');
  101. }
  102. });
  103. }catch(e){
  104. console.log(e,'e');
  105. }
  106. },
  107. funListenDeviceMsgEvent: function(options) {
  108. switch (options.type) {
  109. case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
  110. console.log(options)
  111. break;
  112. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
  113. if (options.result)
  114. _this.devicesList = options.data;
  115. let ly = _this.devicesList.find(d=>d.name.indexOf('cx-')>-1);
  116. if(!ly) ly = _this.devicesList.find(d=>d.name.indexOf('BLUFI_DEVICE')>-1);
  117. if(ly){
  118. console.log(ly,'找到设备')
  119. _this.lanya = ly;
  120. _this.nodevice = false;
  121. _this.show = true;
  122. }
  123. break;
  124. case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
  125. if (options.result) {
  126. wx.hideLoading()
  127. wx.showToast({
  128. title: '连接成功',
  129. icon: 'none'
  130. })
  131. console.log(options.data,'连接成功')
  132. wx.navigateTo({
  133. url: '/pagesMy/wifiSet?deviceId=' + options.data.deviceId + '&name=' + options
  134. .data.name+ '&type=' + _this.type
  135. });
  136. } else {
  137. wx.hideLoading()
  138. wx.showModal({
  139. title: '提示',
  140. content: '连接失败',
  141. showCancel: false
  142. });
  143. }
  144. break;
  145. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
  146. if (!options.result) {
  147. wx.showToast({
  148. title: '蓝牙未开启',
  149. icon: 'none'
  150. })
  151. } else {
  152. //蓝牙搜索开始
  153. _this.searching = true;
  154. }
  155. break;
  156. case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
  157. if (options.result) {
  158. //蓝牙停止搜索ok
  159. console.log('蓝牙停止搜索ok')
  160. } else {
  161. //蓝牙停止搜索失败
  162. console.log('蓝牙停止搜索失败')
  163. }
  164. _this.searching = false;
  165. break;
  166. }
  167. },
  168. Search: function() {
  169. if (this.searching) {
  170. xBlufi.notifyStartDiscoverBle({
  171. 'isStart': false
  172. })
  173. } else {
  174. xBlufi.notifyStartDiscoverBle({
  175. 'isStart': true
  176. })
  177. }
  178. },
  179. connectWiFi: function() {
  180. // let that = this;
  181. // wx.createBLEConnection({
  182. // deviceId: that.lanya.deviceId,
  183. // success: (res) => {
  184. // wx.navigateTo({
  185. // url: '/pagesMy/wifiSet?deviceId=' + that.lanya.deviceId + '&name=' + that.lanya.name
  186. // })
  187. // },
  188. // fail: (err) => {
  189. // console.log(err,'createBLEConnection-err');
  190. // }
  191. // });
  192. // return
  193. //停止搜索
  194. xBlufi.notifyStartDiscoverBle({
  195. 'isStart': false
  196. })
  197. xBlufi.notifyConnectBle({
  198. isStart: true,
  199. deviceId: _this.lanya.deviceId,
  200. name:_this.lanya.name
  201. });
  202. wx.showLoading({
  203. title: '连接蓝牙设备中...',
  204. })
  205. }
  206. }
  207. }
  208. </script>
  209. <style scoped lang="less">
  210. .page{
  211. width: 100%;
  212. padding: 0 0 300rpx;
  213. background: #FFFFFF;
  214. box-sizing: border-box;
  215. .search{
  216. image{
  217. width: 620rpx;
  218. height: 620rpx;
  219. margin-top: 120rpx;
  220. }
  221. p{
  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-top: 80rpx;
  229. }
  230. }
  231. .empty{
  232. .title{
  233. font-family: PingFang-SC, PingFang-SC;
  234. font-weight: bold;
  235. font-size: 36rpx;
  236. color: #111111;
  237. line-height: 36rpx;
  238. text-align: center;
  239. margin-top: 158rpx;
  240. }
  241. &>image{
  242. width: 400rpx;
  243. height: 366rpx;
  244. margin-top: 48rpx;
  245. }
  246. .tip{
  247. font-family: PingFang-SC, PingFang-SC;
  248. font-weight: bold;
  249. font-size: 32rpx;
  250. color: #111111;
  251. line-height: 36rpx;
  252. text-align: center;
  253. margin-top: 53rpx;
  254. }
  255. .warn{
  256. background: rgba(27,80,255,0.06);
  257. border-radius: 28rpx;
  258. padding: 10rpx 24rpx;
  259. margin-top: 48rpx;
  260. image{
  261. width: 26rpx;
  262. height: 26rpx;
  263. }
  264. span{
  265. font-family: PingFangSC, PingFang SC;
  266. font-weight: 400;
  267. font-size: 26rpx;
  268. color: #1B50FF;
  269. line-height: 37rpx;
  270. margin-left: 8rpx;
  271. }
  272. }
  273. }
  274. .zt_btn{
  275. width: calc(100% - 120rpx);
  276. position: fixed;
  277. left: 60rpx;
  278. bottom: 201rpx;
  279. }
  280. .alert{
  281. padding: 54rpx 40rpx 0;
  282. .title{
  283. font-family: PingFang-SC, PingFang-SC;
  284. font-weight: bold;
  285. font-size: 36rpx;
  286. color: #111111;
  287. line-height: 36rpx;
  288. text-align: center;
  289. margin-bottom: 19rpx;
  290. }
  291. p{
  292. font-family: PingFangSC, PingFang SC;
  293. font-weight: 400;
  294. font-size: 30rpx;
  295. color: #111111;
  296. line-height: 65rpx;
  297. text-align: left;
  298. margin-top: 24rpx;
  299. }
  300. .btn{
  301. width: calc(100% - 108rpx);
  302. height: 90rpx;
  303. background: #D9F159;
  304. border-radius: 16rpx;
  305. font-family: PingFang-SC, PingFang-SC;
  306. font-weight: bold;
  307. font-size: 32rpx;
  308. color: #252525;
  309. line-height: 90rpx;
  310. text-align: center;
  311. margin: 113rpx 54rpx 0;
  312. letter-spacing: 2rpx;
  313. }
  314. }
  315. .connect{
  316. padding: 66rpx 40rpx 30rpx;
  317. .title{
  318. font-family: PingFangSC, PingFang SC;
  319. font-weight: 600;
  320. font-size: 36rpx;
  321. color: #111111;
  322. line-height: 36rpx;
  323. text-align: center;
  324. }
  325. image{
  326. width: 504rpx;
  327. height: 254rpx;
  328. margin-top: 37rpx;
  329. }
  330. .tip{
  331. font-family: PingFangSC, PingFang SC;
  332. font-weight: 400;
  333. font-size: 30rpx;
  334. color: #111111;
  335. line-height: 36rpx;
  336. margin-top: 40rpx;
  337. }
  338. .btn{
  339. width: 100%;
  340. height: 90rpx;
  341. background: #D9F159;
  342. border-radius: 16rpx;
  343. font-family: PingFang-SC, PingFang-SC;
  344. font-weight: bold;
  345. font-size: 32rpx;
  346. color: #252525;
  347. line-height: 90rpx;
  348. text-align: center;
  349. margin-top: 101rpx;
  350. letter-spacing: 2rpx;
  351. }
  352. }
  353. }
  354. </style>