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