deviceConnect0.js 3.0 KB

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