172 lines
3.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view class="page">
<view class="card" v-if="!connected">
<text class="tipText">Not connected. Please connect a CAIIC-MCM device on the Device tab first</text>
</view>
<template v-if="connected">
<!-- 当前设备信息 -->
<view class="card">
<view class="infoRow">
<text class="infoLabel">Current Firmware</text>
<text class="infoValue">{{ curVersion }}</text>
</view>
<view class="infoRow">
<text class="infoLabel">Bank</text>
<text class="infoValue">{{ bankInfo }}</text>
</view>
</view>
</template>
<!-- OTA 停用说明 -->
<view class="card">
<text class="sectionTitle">OTA Upgrade</text>
<text class="warnText">
OTA is temporarily unavailable: the current firmware's notify uplink is broken,
so upgrade acknowledgements cannot be returned to the phone.
This feature will be restored after a firmware update (SWD reflash).
</text>
<text class="warnText">
OTA 暂不可用:当前固件 notify 上行链路异常,升级应答无法回传,
待固件更新(SWD 烧录)后恢复。
</text>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { onLoad, onShow, onHide, onUnload } from '@dcloudio/uni-app'
import * as Ble from "../../src/BluetoothManager"
import * as McmCmd from "../../src/mcm/McmCommands"
const connected = ref<boolean>(false)
const curVersion = ref<string>("--")
const bankInfo = ref<string>("--")
// ================= 设备信息 =================
async function loadDeviceInfo() {
const v = await McmCmd.getVersion()
curVersion.value = v != null ? v : "--"
const b = await McmCmd.getBankInfo()
if (b != null) {
bankInfo.value = b.indexOf("APP2") >= 0 ? "APP2" : (b.indexOf("APP1") >= 0 ? "APP1" : "--")
}
}
// ================= 蓝牙状态监听 =================
function onBleStatueListener(state: number) {
if (state == 0) {
connected.value = true
loadDeviceInfo()
} else if (state == 10000 || state == 10001) {
connected.value = false
}
}
let subscribed = false
function subscribe() {
if (subscribed) return
uni.$on("bleState", onBleStatueListener)
subscribed = true
}
function unsubscribe() {
if (!subscribed) return
uni.$off("bleState", onBleStatueListener)
subscribed = false
}
// ================= 生命周期 =================
onLoad((options: any) => {
subscribe()
})
onShow(() => {
subscribe()
connected.value = Ble.isConnected()
if (connected.value) {
loadDeviceInfo()
}
})
onHide(() => {
unsubscribe()
})
onUnload(() => {
unsubscribe()
})
</script>
<style scoped>
.page{
display:flex;
flex-direction:column;
padding: 0 20rpx;
margin-bottom: 16px;
}
.card {
border-radius: 36rpx;
background-color: #ffffff;
padding: 24rpx;
margin-top: 20rpx;
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.08);
display: flex;
flex-direction: column;
}
.tipText {
font-size: 26rpx;
color: #999999;
text-align: center;
padding: 20rpx 0;
}
.sectionTitle {
font-size: 26rpx;
color: #888888;
margin-bottom: 12rpx;
}
.infoRow {
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 8rpx 0;
}
.infoLabel {
font-size: 26rpx;
color: #888888;
flex-shrink: 0;
}
.infoValue {
font-size: 24rpx;
color: #333333;
flex: 1;
text-align: right;
margin-left: 20rpx;
}
.warnText {
font-size: 24rpx;
color: #dd524d;
margin-top: 12rpx;
line-height: 1.5;
}
</style>