detail.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // pages/deviceDetail/detail.js
  2. const {
  3. BtHelper
  4. } = require('../../devices/bt_helper');
  5. const { deviceVersion } = require('../../request/deviceListRequest')
  6. import { 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: 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. });
  31. })
  32. },
  33. goToWallpaper: function () {
  34. wx.navigateTo({
  35. url: '/pages/piano/wallpaper/wallpaper'
  36. });
  37. },
  38. goToOta: function () {
  39. if (this.data.hasNew) {
  40. let param = JSON.stringify(this.data.updateData) ?? {};
  41. // wx.navigateTo({
  42. // url: '/pages/ota/ota' + "?param=" + param
  43. // });
  44. route_util.jumpParam('/pages/ota/ota', param)
  45. }
  46. },
  47. powerTap(e) {
  48. console.log(e)
  49. this.setData({
  50. powerOpen: !powerOpen
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad: function (options) {
  57. let device = JSON.parse(options.param);
  58. let isConnect = device.state === 'online'
  59. if (!isConnect) {
  60. // btHelper
  61. wx.showToast({
  62. title: '设备已经失去连接',
  63. })
  64. return;
  65. }
  66. const btHelper = BtHelper.getInstance();
  67. btHelper.getVersion()
  68. let _this = this;
  69. EventManager.addNotification(CmdEvent.eventName, function (event) {
  70. let name = event.name;
  71. console.log(event)
  72. switch (name) {
  73. case CmdEvent.version:
  74. _this.data.device.version = event.version;
  75. _this.checkOtaVersion(_this.data.device);
  76. break;
  77. }
  78. }, this)
  79. },
  80. questionTap() {
  81. wx.showModal({
  82. title: '省电模式',
  83. content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
  84. showCancel: false,
  85. complete: (res) => {
  86. if (res.cancel) {
  87. }
  88. if (res.confirm) {
  89. }
  90. }
  91. })
  92. },
  93. onUnload() {
  94. EventManager.removeNotification(CmdEvent.eventName, this)
  95. },
  96. })