deviceConnect0.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const app = getApp();
  2. const constant = require('../../../utils/constant.js');
  3. Page({
  4. data: {
  5. nvabarData: {
  6. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  7. title: '连接配网', //导航栏 中间的标题
  8. },
  9. scopeBluetooth: false,
  10. userFuzzyLocation: true,
  11. isNotruter: false,
  12. connectDevice: {},
  13. imageUrl: "./../../../img/c.png",
  14. },
  15. ///定位,蓝牙权限,蓝牙适配器
  16. // {"applicationType":"[0, 1]","deviceId":430635766251545,"img":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113416291791429.png","offlineImg":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113421204031133.png","connectImg":null,"name":"猫王音响x阿基米德 SR1 妙播收音机","bluetoothName":"SR1妙播收音机","bluetoothNames":["SR1妙播收音机","猫王XOG·CyberRadio 001"],"isChannelsPlatforms":1,"platform":0,"typeList":[{"is5g":0,"type":1,"connectType":1,"functionList":[6,1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113427142232548.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113431143471942.png","icon":null,"guideUrl":null}},{"is5g":0,"type":2,"connectType":3,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113437930271177.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113441600058940.png","icon":null,"guideUrl":null}},{"is5g":0,"type":4,"connectType":3,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113446634000744.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113450885467009.png","icon":null,"guideUrl":null}}],"clientType":"猫王妙播黑胶音箱(BLE)","firstVersion":"1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0}
  17. onLoad(options) {
  18. var that = this;
  19. var param = options.param;
  20. if (!constant.strings.isEmpty(param)) {
  21. param = JSON.parse(param);
  22. that.data.connectDevice = param;
  23. if (!constant.strings.isEmpty(param.typeList)) {
  24. var typeList = param.typeList;
  25. typeList = typeList.filter((v) => v.connectType == 3);
  26. if (!constant.strings.isEmpty(typeList)) {
  27. that.setData({
  28. imageUrl: typeList[0].deviceLinkResp.icon1,
  29. });
  30. }
  31. }
  32. }
  33. wx.offAppShow(that.getSetting);
  34. wx.onAppShow(that.getSetting);
  35. that.getSetting();
  36. if (options.isLognlink) {
  37. that.setData({
  38. isNotruter: true,
  39. nvabarData: {
  40. showCapsule: 1,
  41. title: '连接配网',
  42. callback: () => {
  43. constant.routeUtil.goBackRoute(constant.routeRoot.indexRoot);
  44. }
  45. },
  46. })
  47. }
  48. },
  49. ///获取定位服务
  50. getSetting() {
  51. var that = this;
  52. wx.getSetting({
  53. success(res) {
  54. if (res.authSetting["scope.userFuzzyLocation"]) {
  55. app.getBluetoothStatus();
  56. that.setData({
  57. userFuzzyLocation: true,
  58. });
  59. } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  60. ///请求定位权限
  61. wx.authorize({
  62. scope: "scope.userFuzzyLocation",
  63. success() {
  64. that.getSetting();
  65. }
  66. });
  67. } else {
  68. that.setData({
  69. userFuzzyLocation: false,
  70. });
  71. wx.showModal({
  72. title: '请打开系统位置获取',
  73. success(res) {
  74. if (res.confirm) {
  75. wx.openSetting({
  76. complete() {
  77. // that.getSetting();
  78. }
  79. })
  80. } else if (res.cancel) {}
  81. }
  82. });
  83. }
  84. }
  85. })
  86. },
  87. ///检测蓝牙权限回调 true:false
  88. getBluetoothStatusCallck(v) {
  89. var that = this;
  90. that.setData({
  91. scopeBluetooth: v
  92. });
  93. },
  94. ///下一步
  95. next() {
  96. var that = this;
  97. ///初始化蓝牙
  98. wx.openBluetoothAdapter({
  99. success(res) {
  100. if (that.data.scopeBluetooth && that.data.userFuzzyLocation) {
  101. var param = "?param=" + JSON.stringify(that.data.connectDevice);
  102. constant.routeUtil.jumpParam(constant.routePath.deviceConnect1, param);
  103. }
  104. },
  105. fail(res) {
  106. if (res.errCode === 10001) {
  107. wx.showToast({
  108. title: '蓝牙未打开',
  109. icon: "none",
  110. duration: 2000
  111. })
  112. }
  113. }
  114. });
  115. },
  116. ///手动开启定位权限
  117. setUserFuzzyLocation() {
  118. const that = this;
  119. wx.openSetting({
  120. complete() {
  121. // that.getSetting();
  122. }
  123. })
  124. },
  125. //手动开启蓝牙
  126. setBluetooth() {
  127. wx.openSetting({
  128. complete() {
  129. // app.getBluetoothStatus();
  130. }
  131. })
  132. },
  133. ///返回到首页
  134. notRoter() {
  135. constant.routeUtil.goBackRoute(constant.routeRoot.indexRoot);
  136. },
  137. onUnload() {
  138. var that = this;
  139. ///传入的监听函数。不传此参数则移除所有监听函数
  140. wx.offAppShow(that.getSetting);
  141. },
  142. })