detail.js 3.2 KB

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