123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // pages/deviceDetail/detail.js
- const {
- BtHelper
- } = require('../../devices/bt_helper');
- const { deviceVersion } = require('../../request/deviceListRequest')
- import { CmdEvent } from '../../devices/cmd_key_event';
- import EventManager from '../../utils/event_bus'
- import route_util from '../../utils/route_util';
- Page({
- data: {
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '设备详情', //导航栏 中间的标题
- },
- hasNew: true,
- // 页面数据
- device: {},
- btHelper: null,
- updateData: {},
- powerOpen: false,
- },
- checkOtaVersion(device) {
- let _this = this;
- deviceVersion(device.clienlType, device.connectType, device.version).then(res => {
- console.log(res);
- let updateData = res.data ?? {};
- let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
- _this.setData({
- hasNew: hasNewVersion,
- });
- })
- },
- goToWallpaper: function () {
- wx.navigateTo({
- url: '/pages/piano/wallpaper/wallpaper'
- });
- },
- goToOta: function () {
- if (this.data.hasNew) {
- let param = JSON.stringify(this.data.updateData) ?? {};
- // wx.navigateTo({
- // url: '/pages/ota/ota' + "?param=" + param
- // });
- route_util.jumpParam('/pages/ota/ota', param)
- }
- },
- powerTap(e) {
- console.log(e)
- this.setData({
- powerOpen: !powerOpen
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let device = JSON.parse(options.param);
- let isConnect = device.state === 'online'
- if (!isConnect) {
- // btHelper
- wx.showToast({
- title: '设备已经失去连接',
- })
- return;
- }
- const btHelper = BtHelper.getInstance();
- btHelper.getVersion()
- let _this = this;
- EventManager.addNotification(CmdEvent.eventName, function (event) {
- let name = event.name;
- console.log(event)
- switch (name) {
- case CmdEvent.version:
- _this.data.device.version = event.version;
- _this.checkOtaVersion(_this.data.device);
- break;
- }
- }, this)
- },
- questionTap() {
- wx.showModal({
- title: '省电模式',
- content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
- showCancel: false,
- complete: (res) => {
- if (res.cancel) {
- }
- if (res.confirm) {
- }
- }
- })
- },
- onUnload() {
- EventManager.removeNotification(CmdEvent.eventName, this)
- },
- })
|