detail.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // pages/deviceDetail/detail.js
  2. const {
  3. BtHelper
  4. } = require('../../devices/bt_helper');
  5. const { deviceVersion } = require('../../request/deviceListRequest')
  6. import { EnumCmdEvent } 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: true,
  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. }
  50. },
  51. powerTap(e) {
  52. console.log(e)
  53. let btHelper = BtHelper.getInstance();
  54. btHelper.setPauseSleep(powerOpen ? 60 * 20 : -1)
  55. this.setData({
  56. powerOpen: !powerOpen
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. let device = JSON.parse(options.param);
  64. console.log("设备详情", device)
  65. let isConnect = device.state === 'online'
  66. if (!isConnect) {
  67. // btHelper
  68. wx.showToast({
  69. title: '设备已经失去连接',
  70. })
  71. return;
  72. }
  73. this.setData({
  74. device: device,
  75. })
  76. const btHelper = BtHelper.getInstance();
  77. btHelper.getVersion()
  78. let _this = this;
  79. EventManager.addNotification(CmdEvent.eventName, function (event) {
  80. let name = event.name;
  81. console.log("详情页:", event)
  82. switch (name) {
  83. case EnumCmdEvent.version:
  84. _this.data.device.version = event.version;
  85. _this.checkOtaVersion(_this.data.device);
  86. break;
  87. }
  88. }, this)
  89. },
  90. questionTap() {
  91. wx.showModal({
  92. title: '省电模式',
  93. content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
  94. showCancel: false,
  95. complete: (res) => {
  96. if (res.cancel) {
  97. }
  98. if (res.confirm) {
  99. }
  100. }
  101. })
  102. },
  103. onUnload() {
  104. EventManager.removeNotification(CmdEvent.eventName, this)
  105. },
  106. })