deviceConnect0.js 9.3 KB

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