detail.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // pages/deviceDetail/detail.js
  2. const BtHelper = require('../../devices/bt_helper');
  3. const { deviceVersion } = require('../../request/deviceListRequest')
  4. import { CmdEvent } from '../../devices/cmd_key_event';
  5. import EventManager from '../../utils/event_bus'
  6. import route_util from '../../utils/route_util';
  7. Page({
  8. data: {
  9. nvabarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '设备详情', //导航栏 中间的标题
  12. },
  13. hasNew: true,
  14. // 页面数据
  15. device: getApp().globalData.device,
  16. btHelper: null,
  17. updateData: {},
  18. },
  19. checkOtaVersion(device) {
  20. let _this = this;
  21. deviceVersion(device.clienlType, device.connectType, device.version).then(res => {
  22. console.log(res);
  23. let updateData = res.data ?? {};
  24. let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
  25. _this.setData({
  26. hasNew: hasNewVersion,
  27. });
  28. })
  29. },
  30. goToWallpaper: function () {
  31. wx.navigateTo({
  32. url: '/pages/piano/wallpaper/wallpaper'
  33. });
  34. },
  35. goToOta: function () {
  36. if (this.data.hasNew) {
  37. let param = JSON.stringify(this.data.updateData) ?? {};
  38. // wx.navigateTo({
  39. // url: '/pages/ota/ota' + "?param=" + param
  40. // });
  41. route_util.jumpParam('/pages/ota/ota', param)
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function () {
  48. let device = getApp().globalData.device ?? {};
  49. let isConnect = device.state === 'online'
  50. if (!isConnect) {
  51. // btHelper
  52. wx.showToast({
  53. title: '设备已经失去连接',
  54. })
  55. return;
  56. }
  57. const btHelper = BtHelper.getInstance();
  58. btHelper.getVersion()
  59. EventManager.addNotification(CmdEvent.eventName, listenEvent, this)
  60. },
  61. listenEvent(event) {
  62. let name = event.name;
  63. console.log(event)
  64. switch (name) {
  65. case CmdEvent.version:
  66. this.data.device.version = event.version;
  67. this.checkOtaVersion(this.data.device);
  68. break;
  69. }
  70. },
  71. onUnload() {
  72. EventManager.removeNotification(CmdEvent.eventName, listenEvent, this)
  73. },
  74. })