deviceConnect0.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. _this.setData({
  62. userFuzzyLocation: false,
  63. });
  64. wx.authorize({
  65. scope: "scope.userFuzzyLocation",
  66. success () {
  67. _this.getSetting();
  68. }
  69. });
  70. }else {
  71. _this.setData({
  72. userFuzzyLocation: false,
  73. });
  74. wx.showModal({
  75. title: '请打开系统位置获取',
  76. success (res) {
  77. if (res.confirm) {
  78. console.log('用户点击确定')
  79. wx.openSetting({
  80. complete () {
  81. // _this.getSetting();
  82. }
  83. })
  84. } else if (res.cancel) {
  85. console.log('用户点击取消');
  86. }
  87. }
  88. })
  89. }
  90. }
  91. })
  92. },
  93. next(){
  94. const _this = this;
  95. wx.openBluetoothAdapter({
  96. success (res) {
  97. if(_this.data.scopeBluetooth && _this.data.userFuzzyLocation){
  98. wx.navigateTo({
  99. url: './../deviceConnect1/deviceConnect1',
  100. });
  101. }
  102. },
  103. fail(res) {
  104. if(res.errCode === 10001) {
  105. wx.showToast({
  106. title: '蓝牙未打开',
  107. icon: "none",
  108. duration: 2000
  109. })
  110. }
  111. }
  112. });
  113. },
  114. setBluetooth(){
  115. wx.openSetting({
  116. complete () {
  117. // app.getBluetoothStatus();
  118. }
  119. })
  120. },
  121. setUserFuzzyLocation(){
  122. const _this = this;
  123. wx.openSetting({
  124. complete () {
  125. // _this.getSetting();
  126. }
  127. })
  128. },
  129. notRoter(){
  130. getCurrentPages()[0].onLoad();
  131. wx.switchTab({
  132. url: "./../index/index"
  133. });
  134. },
  135. /**
  136. * 生命周期函数--监听页面初次渲染完成
  137. */
  138. onReady() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面显示
  142. */
  143. onShow() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide() {
  149. },
  150. /**
  151. * 生命周期函数--监听页面卸载
  152. */
  153. onUnload() {
  154. wx.offAppShow(this.getSetting);
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh() {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom() {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage() {
  170. }
  171. })