deviceConnect0.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. const constant = require('../../../utils/constant.js');
  2. Page({
  3. data: {
  4. nvabarData: {
  5. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  6. title: '连接配网', //导航栏 中间的标题
  7. callback: () => {
  8. console.log("返回界面3:");
  9. }
  10. },
  11. scopeBluetooth: false,
  12. userFuzzyLocation: true,
  13. isNotruter: false,
  14. isFromRootPage: true,
  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. // 解码URL编码的参数,例如:%7B%22%22clientType%22:%22MW-2AXD%22%7D
  24. param = decodeURIComponent(param)
  25. console.log("设备参数:", param)
  26. if (!constant.strings.isEmpty(param)) {
  27. param = JSON.parse(param);
  28. var clientType = param["clientType"]
  29. if (Object.keys(param).length <= 1) {
  30. // 扫描进来的只有一个参数
  31. that.data.isFromRootPage = false;
  32. var classifyProducts = constant.app.globalData.classifyProducts;
  33. if (!constant.strings.isEmpty(classifyProducts)) {
  34. var fullDevice = classifyProducts.filter((v) => v.clientType == clientType);
  35. console.log("找到设备1", fullDevice);
  36. that.updateDeviceUrl(fullDevice[0] ?? param);
  37. } else {
  38. ///数据请求
  39. constant.dRequest.deviceList({
  40. unShowLoad: true
  41. }).then((res) => {
  42. if (res) {
  43. var fullDevice = res.filter((v) => v.clientType == clientType);
  44. that.setDeviceList(res, true);
  45. that.updateDeviceUrl(fullDevice[0] ?? param);
  46. }
  47. });
  48. }
  49. } else {
  50. that.updateDeviceUrl(param);
  51. }
  52. }
  53. wx.offAppShow(that.getSetting);
  54. wx.onAppShow(that.getSetting);
  55. that.getSetting();
  56. if (options.isLognlink) {
  57. that.setData({
  58. isNotruter: true,
  59. nvabarData: {
  60. showCapsule: 1,
  61. title: '连接配网',
  62. callback: () => {
  63. constant.routeUtil.goBackRoute(constant.routeRoot.index);
  64. }
  65. },
  66. })
  67. }
  68. },
  69. updateDeviceUrl(param) {
  70. var that = this
  71. that.data.connectDevice = param;
  72. var typeList = param["typeList"] ?? [];
  73. console.log("找到设备5", typeList);
  74. if (!constant.strings.isEmpty(typeList)) {
  75. console.log("找到设备3");
  76. typeList = typeList.filter((v) => v.connectType == 3);
  77. if (!constant.strings.isEmpty(typeList)) {
  78. console.log("找到设备4", typeList);
  79. that.setData({
  80. imageUrl: typeList[0].deviceLinkResp.icon1,
  81. });
  82. }
  83. }
  84. },
  85. callback() {
  86. // 重置小程序界面到首页
  87. console.log("返回界面4", constant.routePath.index);
  88. if (this.data.isFromRootPage) {
  89. constant.routeUtil.goBack();
  90. } else {
  91. console.log("返回界面4", constant.routePath.index);
  92. wx.reLaunch({
  93. // url: '/pages/index/index',
  94. url: constant.routePath.index,
  95. });
  96. }
  97. },
  98. ///获取定位服务
  99. getSetting() {
  100. var that = this;
  101. wx.getSetting({
  102. success(res) {
  103. if (res.authSetting["scope.userFuzzyLocation"]) {
  104. constant.app.getBluetoothStatus();
  105. that.setData({
  106. userFuzzyLocation: true,
  107. });
  108. } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  109. ///请求定位权限
  110. wx.authorize({
  111. scope: "scope.userFuzzyLocation",
  112. success() {
  113. that.getSetting();
  114. }
  115. });
  116. } else {
  117. that.setData({
  118. userFuzzyLocation: false,
  119. });
  120. wx.showModal({
  121. title: '请打开系统位置获取',
  122. success(res) {
  123. if (res.confirm) {
  124. wx.openSetting({
  125. complete() {
  126. // that.getSetting();
  127. }
  128. })
  129. } else if (res.cancel) { }
  130. }
  131. });
  132. }
  133. }
  134. })
  135. },
  136. ///检测蓝牙权限回调 true:false
  137. getBluetoothStatusCallck(v) {
  138. var that = this;
  139. that.setData({
  140. scopeBluetooth: v
  141. });
  142. },
  143. ///下一步
  144. next() {
  145. var that = this;
  146. ///初始化蓝牙
  147. wx.openBluetoothAdapter({
  148. success(res) {
  149. if (that.data.scopeBluetooth && that.data.userFuzzyLocation) {
  150. var param = "?param=" + JSON.stringify(that.data.connectDevice);
  151. constant.routeUtil.jumpParam(constant.routePath.deviceConnect1, param);
  152. }
  153. },
  154. fail(res) {
  155. if (res.errCode === 10001) {
  156. wx.showToast({
  157. title: '手机蓝牙未打开',
  158. icon: "none",
  159. duration: 2000
  160. })
  161. }
  162. }
  163. });
  164. },
  165. ///手动开启定位权限
  166. setUserFuzzyLocation() {
  167. const that = this;
  168. wx.openSetting({
  169. complete() {
  170. // that.getSetting();
  171. }
  172. })
  173. },
  174. //手动开启蓝牙
  175. setBluetooth() {
  176. wx.openSetting({
  177. complete() {
  178. //constant.app.getBluetoothStatus();
  179. }
  180. })
  181. },
  182. ///返回到首页
  183. notRoter() {
  184. constant.routeUtil.goBackRoute(constant.routeRoot.index);
  185. },
  186. ///设备列表赋值
  187. setDeviceList(res, isLoad) {
  188. var devices = res;
  189. if (isLoad) {
  190. constant.store.setStore("classifyProducts", res);
  191. constant.app.globalData.classifyProducts = devices;
  192. }
  193. },
  194. deviceTap(e) {
  195. var device = e.currentTarget.dataset.device;
  196. console.log(device)
  197. if (!device) {
  198. console.log("设备为空")
  199. return;
  200. }
  201. var clientTypes = constant.lexinDevices.clientTypes;
  202. if (clientTypes.includes(device.clientType)) {
  203. var param = "?param=" + JSON.stringify(device);
  204. // pages/pageB/deviceConnect0/deviceConnect0?param={"clientType":"MW-Mate X(4G_WIFI)"}
  205. // ?param={"applicationType":"[0, 1]","deviceId":432698392051714,"img":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102304552692164.png","offlineImg":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102740684077340.png","connectImg":null,"name":"X2 妙播音箱","bluetoothName":"猫王音响·Mate_X2","bluetoothNames":["猫王音响·Mate_X2","猫王音响·X2妙播音箱","猫王音响·Mate_X"],"isChannelsPlatforms":0,"platform":0,"typeList":[{"is5g":0,"type":1,"connectType":1,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102357244734373.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102404705282697.png","icon":null,"guideUrl":null}},{"is5g":0,"type":2,"connectType":3,"functionList":[1,3,6],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152650116909154.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152717095912088.png","icon":null,"guideUrl":null}},{"is5g":0,"type":4,"connectType":3,"functionList":[1,3,6],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152749792939577.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152759963002418.png","icon":null,"guideUrl":null}}],"clientType":"MW-Mate X(4G_WIFI)","firstVersion":"0.0.1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0}
  206. constant.routeUtil.jumpParam(constant.routePath.deviceConnect0, param);
  207. } else if (device.clientType === "MW-S2" || device.clientType === "猫王妙播黑胶音箱(BLE)") {
  208. var param = "?param=" + JSON.stringify(device);
  209. constant.routeUtil.jumpParam(constant.routePath.connectBle, param);
  210. } else {
  211. wx.showToast({
  212. title: '暂不支持该设备',
  213. })
  214. }
  215. },
  216. onUnload() {
  217. var that = this;
  218. ///传入的监听函数。不传此参数则移除所有监听函数
  219. wx.offAppShow(that.getSetting);
  220. },
  221. })