123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // 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: getApp().globalData.device,
- btHelper: null,
- updateData: {},
- },
- 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)
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function () {
- let device = getApp().globalData.device ?? {};
- let isConnect = device.state === 'online'
- if (!isConnect) {
- // btHelper
- wx.showToast({
- title: '设备已经失去连接',
- })
- return;
- }
- const btHelper = BtHelper.getInstance();
- btHelper.getVersion()
- EventManager.addNotification(CmdEvent.eventName, listenEvent, this)
- },
- listenEvent(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;
- }
- },
- onUnload() {
- EventManager.removeNotification(CmdEvent.eventName, listenEvent, this)
- },
- })
|