detail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // pages/deviceDetail/detail.js
  2. const {
  3. BtHelper
  4. } = require('../../devices/bt_helper');
  5. const { deviceVersion } = require('../../request/deviceListRequest')
  6. import { EnumCmdEvent, CmdEvent } from '../../devices/cmd_key_event';
  7. import EventManager from '../../utils/event_bus'
  8. import route_util from '../../utils/route_util';
  9. Page({
  10. data: {
  11. nvabarData: {
  12. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  13. title: '设备详情', //导航栏 中间的标题
  14. },
  15. hasNew: false,
  16. // 页面数据
  17. device: {},
  18. btHelper: null,
  19. updateData: {},
  20. powerOpen: false,
  21. },
  22. checkOtaVersion(device) {
  23. let _this = this;
  24. deviceVersion(device.clienlType, device.connectType, device.version).then(res => {
  25. console.log(res);
  26. let updateData = res.data ?? {};
  27. let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
  28. _this.setData({
  29. hasNew: hasNewVersion,
  30. updateData: updateData
  31. });
  32. })
  33. },
  34. goToWallpaper: function () {
  35. let newParam = JSON.stringify(this.data.device);
  36. route_util.jumpParam('/pages/piano/wallpaper/wallpaper', newParam)
  37. },
  38. goToOta: function () {
  39. if (this.data.hasNew) {
  40. let param = {
  41. "device": this.data.device,
  42. "otaData": this.data.updateData,
  43. }
  44. let newParam = JSON.stringify(param);
  45. // wx.navigateTo({
  46. // url: '/pages/ota/ota' + "?param=" + param
  47. // });
  48. route_util.jumpParam('/pages/ota/ota', newParam)
  49. } else {
  50. wx.showToast({
  51. title: '没有新版本',
  52. })
  53. }
  54. },
  55. powerTap(e) {
  56. console.log(e)
  57. let btHelper = BtHelper.getInstance();
  58. btHelper.setPauseSleep(!this.data.powerOpen ? 1200 : -1)
  59. this.setData({
  60. powerOpen: !this.data.powerOpen
  61. })
  62. },
  63. questionTap() {
  64. wx.showModal({
  65. title: '省电模式',
  66. content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
  67. showCancel: false,
  68. complete: (res) => {
  69. if (res.cancel) {
  70. }
  71. if (res.confirm) {
  72. // setSleepAfterPlayPause
  73. const btHelper = BtHelper.getInstance();
  74. btHelper.setPauseSleep(1200)
  75. }
  76. }
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. let device = JSON.parse(options.param);
  84. console.log("设备详情", device)
  85. let isConnect = device.state === 'online'
  86. if (!isConnect) {
  87. // btHelper
  88. wx.showToast({
  89. title: '设备已经失去连接',
  90. })
  91. return;
  92. }
  93. this.setData({
  94. device: device,
  95. })
  96. const btHelper = BtHelper.getInstance();
  97. btHelper.getVersion()
  98. btHelper.getPauseSleep()
  99. let _this = this;
  100. EventManager.addNotification(CmdEvent.eventName, function (event) {
  101. let name = event.cmdEvent;
  102. console.log("详情页:", event)
  103. switch (name) {
  104. case EnumCmdEvent.version:
  105. _this.data.device.version = event.version;
  106. _this.checkOtaVersion(_this.data.device);
  107. break;
  108. }
  109. }, this)
  110. },
  111. onUnload() {
  112. EventManager.removeNotification(CmdEvent.eventName, this)
  113. },
  114. })