deviceDetail.js 3.1 KB

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