deviceList.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const app = getApp()
  2. import dRequest from '../../request/deviceListRequest'
  3. import routeUtil from '../../utils/route_util'
  4. import route_constant from '../../utils/route_constant.js'
  5. import strings from '../../utils/strings.js';
  6. import store from '../../utils/store.js';
  7. import lexin_devices from '../../utils/lexin/devices';
  8. Page({
  9. data: {
  10. nvabarData: {
  11. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  12. title: '设备列表', //导航栏 中间的标题
  13. },
  14. deviceList: app.globalData.classifyProducts,
  15. },
  16. onLoad(options) {
  17. var that = this
  18. var classifyProducts = app.globalData.classifyProducts;
  19. if (!strings.isEmpty(classifyProducts)) {
  20. that.setDeviceList(classifyProducts, false);
  21. }
  22. ///数据请求
  23. dRequest.deviceList({
  24. unShowLoad: true
  25. }).then((res) => {
  26. if (res) {
  27. console.log("gadsfqwerqwerqr===" + JSON.stringify(res));
  28. that.setDeviceList(res, true);
  29. }
  30. });
  31. },
  32. ///设备列表赋值
  33. setDeviceList(res, isLoad) {
  34. var that = this;
  35. try {
  36. // {"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":"MW-SR1(4G_WIFI)","firstVersion":"1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0}
  37. var devices = res;
  38. // var devices = [];
  39. // var clientTypes = lexin_devices.clientTypes;
  40. // res.forEach(element => {
  41. // ///MW-SR1(4G_WIFI),MW-2AX(WIFI)
  42. // for (var i = 0; i < clientTypes.length; i++) {
  43. // if (element.clientType == clientTypes[i]) {
  44. // if (!devices.includes(element)) {
  45. // devices.push(element);
  46. // }
  47. // break;
  48. // }
  49. // }
  50. // });
  51. if (isLoad) {
  52. store.setStore("classifyProducts", res);
  53. app.globalData.classifyProducts = devices;
  54. }
  55. console.log(devices);
  56. that.setData({
  57. deviceList: devices
  58. });
  59. } catch (e) {}
  60. },
  61. deviceTap(e) {
  62. var device = e.currentTarget.dataset.device;
  63. console.log(device)
  64. if (!device) {
  65. console.log("设备为空")
  66. return;
  67. }
  68. var clientTypes = lexin_devices.clientTypes;
  69. if (clientTypes.includes(device.clientType)) {
  70. var param = JSON.stringify(device);
  71. routeUtil.jumpParam(route_constant.deviceConnect0, param);
  72. } else if (device.clientType === "MW-S2" || device.clientType === "猫王妙播黑胶音箱(BLE)") {
  73. let json = JSON.stringify(device)
  74. routeUtil.jumpParam(route_constant.connectBle, json)
  75. } else {
  76. wx.showToast({
  77. title: '暂不支持该设备',
  78. })
  79. }
  80. },
  81. })