deviceDetail.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. const {
  2. BtHelper
  3. } = require('../../../devices/bt_helper');
  4. const {
  5. deviceVersion
  6. } = require('../../../request/deviceListRequest')
  7. import {
  8. EnumCmdEvent,
  9. CmdEvent
  10. } from '../../../devices/cmd_key_event';
  11. import EventManager from '../../../utils/event_bus'
  12. import route_constant from '../../../utils/route_constant';
  13. import route_util from '../../../utils/route_util';
  14. Page({
  15. data: {
  16. nvabarData: {
  17. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  18. title: '设备详情', //导航栏 中间的标题
  19. },
  20. // 页面数据
  21. device: {},
  22. btHelper: null,
  23. updateData: {},
  24. powerOpen: false,
  25. isShowWallpaper: false,
  26. },
  27. onLoad: function (options) {
  28. // let device = JSON.parse(options.param);
  29. console.log(getApp().globalData.mDeviceList.length)
  30. let device = JSON.parse(options.param);
  31. // let device = getApp().globalData.mDeviceList[0] ?? JSON.parse(options.param);
  32. if (device.connectType != '1') {
  33. return
  34. }
  35. device.clientType = device.clientType ?? device.ProdModel
  36. console.log("设备详情", device)
  37. let isConnect = device.state === 'online'
  38. if (!isConnect) {
  39. // btHelper
  40. wx.showToast({
  41. title: '设备已经失去连接',
  42. })
  43. return;
  44. }
  45. this.setData({
  46. device: device,
  47. powerOpen: (device.pauseSleep ?? -1) > 0,
  48. isShowWallpaper: device.clientType === 'MW-S2'
  49. })
  50. const btHelper = BtHelper.getInstance();
  51. let isShowOta = device.clientType === 'MW-S2'
  52. if (isShowOta) {
  53. btHelper.getVersion()
  54. // this.checkOtaVersion(device);
  55. }
  56. // btHelper.getPauseSleep()
  57. let _this = this;
  58. EventManager.addNotification(CmdEvent.eventName, function (event) {
  59. let name = event.cmdEvent;
  60. // console.log("详情页:", name, event)
  61. switch (name) {
  62. case EnumCmdEvent.version:
  63. _this.data.device.version = event.version;
  64. console.log("详情页1:", event.version)
  65. _this.checkOtaVersion(_this.data.device);
  66. break;
  67. case EnumCmdEvent.authSleepStatus:
  68. let value = event.pauseSleep;
  69. console.log("详情页2:", value)
  70. _this.setData({
  71. powerOpen: (value ?? -1) > 0
  72. })
  73. break;
  74. case EnumCmdEvent.onoffline:
  75. console.log("详情页3:")
  76. //目前只有下线
  77. _this.data.device.state = "offline"
  78. break;
  79. }
  80. }, this);
  81. },
  82. checkOtaVersion(device) {
  83. let _this = this;
  84. device.clientType = "MW-S2"
  85. deviceVersion(device.clientType, device.connectType, device.version ?? "1.0.0").then(res => {
  86. console.log("OTA2:", res);
  87. let updateData = res ?? {};
  88. let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
  89. updateData.hasNewVersion = hasNewVersion;
  90. _this.setData({
  91. updateData: updateData
  92. });
  93. })
  94. },
  95. goToWallpaper: function () {
  96. var param = '?param=' + JSON.stringify(this.data.device);
  97. route_util.jumpParam(route_constant.wallpaper, param);
  98. },
  99. goToOta: function () {
  100. if (this.data.updateData.hasNewVersion != 1) {
  101. wx.showToast({
  102. title: '当前已是最新版本',
  103. icon: 'none'
  104. })
  105. return
  106. }
  107. let p = {
  108. "device": this.data.device,
  109. "otaData": this.data.updateData,
  110. }
  111. var param = '?param=' + JSON.stringify(p);
  112. route_util.jumpParam(route_constant.ota, param);
  113. },
  114. powerTap(e) {
  115. console.log(e)
  116. let btHelper = BtHelper.getInstance();
  117. btHelper.setPauseSleep(!this.data.powerOpen ? 1200 : 0)
  118. this.setData({
  119. powerOpen: !this.data.powerOpen
  120. })
  121. },
  122. questionTap() {
  123. wx.showModal({
  124. title: '省电模式',
  125. content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
  126. showCancel: false,
  127. complete: (res) => {
  128. if (res.cancel) {
  129. }
  130. if (res.confirm) {
  131. // setSleepAfterPlayPause
  132. const btHelper = BtHelper.getInstance();
  133. btHelper.setPauseSleep(1200)
  134. }
  135. }
  136. })
  137. },
  138. onUnload() {
  139. EventManager.removeNotification(CmdEvent.eventName, this)
  140. },
  141. })