deviceConnect0.js 5.1 KB

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