bleconnect.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // pages/bluConnect/bleconnect.js
  2. Page(
  3. {
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. scopeBluetooth: false,
  9. isScaning: false,
  10. connectStatus: 0,
  11. connectText: "连接中",
  12. connectPic: "",
  13. connectTips: "正在搜索设备,请保持开机状态...",
  14. buttonTips: "正在搜索设备",
  15. userFuzzyLocation: true,
  16. nvabarData: {
  17. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  18. title: '设备连接', //导航栏 中间的标题
  19. callback: () => {
  20. wx.switchTab({
  21. url: '../home/home',
  22. })
  23. }
  24. },
  25. isNotruter: false,
  26. deviceItem: {
  27. "pic": "../../img/g.png",
  28. "address": "",
  29. "name": "猫王钢琴音箱",
  30. "devName": "名称1", "state": "online", "power": 40
  31. }
  32. }, getBluetoothStatusCallck(v) {
  33. this.setData({
  34. scopeBluetooth: v,
  35. isScaning:v
  36. })
  37. },
  38. setBluetooth() {
  39. wx.openSetting({
  40. complete() {
  41. // app.getBluetoothStatus();
  42. }
  43. })
  44. }, connectDeviceTap() {
  45. var _this = this;
  46. const eventChannel = this.getOpenerEventChannel();
  47. eventChannel.emit('getBackData', {
  48. backData: _this.deviceItem});
  49. wx.navigateBack();
  50. if (!_this.isScaning) {
  51. return;
  52. }
  53. }, scanDevice() {
  54. this.isScaning = true;
  55. },
  56. /**
  57. * 生命周期函数--监听页面加载
  58. */
  59. onLoad(options) {
  60. if (options.isLognlink) {
  61. }
  62. this.buttonTips = this.isScaning ? "正在搜索设备" : "连接";
  63. this.connectStatus = 4;
  64. switch (this.connectStatus) {
  65. case 1:
  66. // 搜索中
  67. this.connectTips = "正在搜索设备,请保持开机状态...";
  68. break;
  69. case 2:
  70. // 连接中
  71. this.connectText = "连接中...";
  72. this.connectPic = "";
  73. case 3:
  74. // 连接失败
  75. this.connectText = "连接失败";
  76. this.connectPic = "../../img/i.png";
  77. break;
  78. case 4:
  79. // 连接成功
  80. this.connectText = "连接成功";
  81. this.connectPic = "../../img/h.png";
  82. this.deviceItem = {
  83. "pic": "../../img/g.png",
  84. "address": "xxxxxx",
  85. "name": "猫王钢琴音箱",
  86. "devName": "名称1", "state": "online", "power": 40
  87. };
  88. break;
  89. case 5:
  90. // 搜索成功
  91. this.connectTips = "搜索到" + this.deviceItem.name;
  92. var curPage = getCurrentPages();
  93. var homePage = curPage[curPage.length - 1];
  94. break;
  95. }
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady() {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload() {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh() {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage() {
  131. }
  132. })