deviceConnect0.js 3.6 KB

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