deviceConnect0.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/deviceConnect0/deviceConnect0.ts
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. scopeBluetooth: false,
  9. userFuzzyLocation: true,
  10. nvabarData: {
  11. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  12. title: '连接配网', //导航栏 中间的标题
  13. callback() {
  14. wx.navigateBack({
  15. delta: 1,
  16. })
  17. }
  18. },
  19. isNotruter: false
  20. },
  21. onShow() {
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. wx.offAppShow(this.getSetting);
  28. wx.onAppShow(this.getSetting);
  29. this.getSetting();
  30. if (options.isLognlink) {
  31. this.setData({
  32. isNotruter: true,
  33. nvabarData: {
  34. showCapsule: 1,
  35. title: '连接配网',
  36. callback: () => {
  37. wx.switchTab({
  38. url: "./../index/index"
  39. })
  40. }
  41. },
  42. })
  43. }
  44. },
  45. getBluetoothStatusCallck(v) {
  46. this.setData({
  47. scopeBluetooth: v
  48. })
  49. },
  50. getSetting() {
  51. const _this = this;
  52. wx.getSetting({
  53. success(res) {
  54. if (res.authSetting["scope.userFuzzyLocation"]) {
  55. // 成功
  56. app.getBluetoothStatus();
  57. _this.setData({
  58. userFuzzyLocation: true,
  59. });
  60. } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  61. wx.authorize({
  62. scope: "scope.userFuzzyLocation",
  63. success() {
  64. _this.getSetting();
  65. }
  66. });
  67. } else {
  68. _this.setData({
  69. userFuzzyLocation: false,
  70. });
  71. wx.showModal({
  72. title: '请打开系统位置获取',
  73. success(res) {
  74. if (res.confirm) {
  75. console.log('用户点击确定')
  76. wx.openSetting({
  77. complete() {
  78. // _this.getSetting();
  79. }
  80. })
  81. } else if (res.cancel) {
  82. console.log('用户点击取消');
  83. }
  84. }
  85. })
  86. }
  87. }
  88. })
  89. },
  90. next() {
  91. const _this = this;
  92. wx.openBluetoothAdapter({
  93. success(res) {
  94. if (_this.data.scopeBluetooth && _this.data.userFuzzyLocation) {
  95. wx.navigateTo({
  96. url: './../deviceConnect1/deviceConnect1',
  97. });
  98. }
  99. },
  100. fail(res) {
  101. if (res.errCode === 10001) {
  102. wx.showToast({
  103. title: '蓝牙未打开',
  104. icon: "none",
  105. duration: 2000
  106. })
  107. }
  108. }
  109. });
  110. },
  111. setBluetooth() {
  112. wx.openSetting({
  113. complete() {
  114. // app.getBluetoothStatus();
  115. }
  116. })
  117. },
  118. setUserFuzzyLocation() {
  119. const _this = this;
  120. wx.openSetting({
  121. complete() {
  122. // _this.getSetting();
  123. }
  124. })
  125. },
  126. notRoter() {
  127. getCurrentPages()[0].onLoad();
  128. wx.switchTab({
  129. url: "./../index/index"
  130. });
  131. },
  132. /**
  133. * 生命周期函数--监听页面初次渲染完成
  134. */
  135. onReady() {
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow() {
  141. },
  142. /**
  143. * 生命周期函数--监听页面隐藏
  144. */
  145. onHide() {
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload() {
  151. wx.offAppShow(this.getSetting);
  152. },
  153. /**
  154. * 页面相关事件处理函数--监听用户下拉动作
  155. */
  156. onPullDownRefresh() {
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom() {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage() {
  167. }
  168. })