wifiSearch.vue 8.9 KB

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