deviceConnect0.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const app = getApp();
  2. import route_constant from '../../utils/route_constant.js'
  3. import route_util from '../../utils/route_util.js';
  4. Page({
  5. data: {
  6. nvabarData: {
  7. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  8. title: '连接配网', //导航栏 中间的标题
  9. },
  10. scopeBluetooth: false,
  11. userFuzzyLocation: true,
  12. isNotruter: false
  13. },
  14. ///定位,蓝牙权限,蓝牙适配器
  15. onLoad(options) {
  16. var that = this;
  17. wx.offAppShow(that.getSetting);
  18. wx.onAppShow(that.getSetting);
  19. that.getSetting();
  20. if (options.isLognlink) {
  21. that.setData({
  22. isNotruter: true,
  23. nvabarData: {
  24. showCapsule: 1,
  25. title: '连接配网',
  26. callback: () => {
  27. route_util.goBackRoute(route_constant.indexRoot);
  28. }
  29. },
  30. })
  31. }
  32. },
  33. ///获取定位服务
  34. getSetting() {
  35. var that = this;
  36. wx.getSetting({
  37. success(res) {
  38. if (res.authSetting["scope.userFuzzyLocation"]) {
  39. app.getBluetoothStatus();
  40. that.setData({
  41. userFuzzyLocation: true,
  42. });
  43. } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  44. ///请求定位权限
  45. wx.authorize({
  46. scope: "scope.userFuzzyLocation",
  47. success() {
  48. that.getSetting();
  49. }
  50. });
  51. } else {
  52. that.setData({
  53. userFuzzyLocation: false,
  54. });
  55. wx.showModal({
  56. title: '请打开系统位置获取',
  57. success(res) {
  58. if (res.confirm) {
  59. wx.openSetting({
  60. complete() {
  61. // that.getSetting();
  62. }
  63. })
  64. } else if (res.cancel) {}
  65. }
  66. });
  67. }
  68. }
  69. })
  70. },
  71. ///检测蓝牙权限回调 true:false
  72. getBluetoothStatusCallck(v) {
  73. var that = this;
  74. that.setData({
  75. scopeBluetooth: v
  76. });
  77. },
  78. ///下一步
  79. next() {
  80. var that = this;
  81. ///初始化蓝牙
  82. wx.openBluetoothAdapter({
  83. success(res) {
  84. if (that.data.scopeBluetooth && that.data.userFuzzyLocation) {
  85. wx.navigateTo({
  86. url: './../deviceConnect1/deviceConnect1',
  87. });
  88. }
  89. },
  90. fail(res) {
  91. if (res.errCode === 10001) {
  92. wx.showToast({
  93. title: '蓝牙未打开',
  94. icon: "none",
  95. duration: 2000
  96. })
  97. }
  98. }
  99. });
  100. },
  101. ///手动开启定位权限
  102. setUserFuzzyLocation() {
  103. const that = this;
  104. wx.openSetting({
  105. complete() {
  106. // that.getSetting();
  107. }
  108. })
  109. },
  110. //手动开启蓝牙
  111. setBluetooth() {
  112. wx.openSetting({
  113. complete() {
  114. // app.getBluetoothStatus();
  115. }
  116. })
  117. },
  118. ///返回到首页
  119. notRoter() {
  120. route_util.goBackRoute(route_constant.indexRoot);
  121. },
  122. onUnload() {
  123. var that = this;
  124. ///传入的监听函数。不传此参数则移除所有监听函数
  125. wx.offAppShow(that.getSetting);
  126. },
  127. })