deviceConnect0.js 5.0 KB

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