deviceConnect0.js 5.1 KB

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