197 lines
3.7 KiB
Plaintext
197 lines
3.7 KiB
Plaintext
<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">Firmware</text>
|
|
<text class="infoValue">{{ version }}</text>
|
|
</view>
|
|
<view class="infoRow">
|
|
<text class="infoLabel">Bank Info</text>
|
|
<text class="infoValue">{{ bankInfo }}</text>
|
|
</view>
|
|
<view class="btnRow">
|
|
<button class="btn" size="mini" :disabled="loading" @tap="refreshAll">
|
|
{{ loading ? 'Loading...' : 'Refresh' }}
|
|
</button>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- sysinfo 控制台输出 -->
|
|
<view class="card">
|
|
<text class="consoleTitle">sysinfo (system runtime status)</text>
|
|
<text class="consoleText">{{ sysInfo }}</text>
|
|
</view>
|
|
</template>
|
|
|
|
</view>
|
|
<!-- #ifdef APP -->
|
|
</scroll-view>
|
|
<!-- #endif -->
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import { MyApiResult } from "@/uni_modules/android-ble"
|
|
import * as Ble from "../../src/BluetoothManager"
|
|
import * as McmCmd from "../../src/mcm/McmCommands.uts"
|
|
|
|
const connected = ref<boolean>(false)
|
|
const loading = ref<boolean>(false)
|
|
const version = ref<string>("--")
|
|
const bankInfo = ref<string>("--")
|
|
const sysInfo = ref<string>("--")
|
|
|
|
async function refreshAll() {
|
|
uni.stopPullDownRefresh()
|
|
if (!Ble.isConnected()) {
|
|
connected.value = false
|
|
return
|
|
}
|
|
connected.value = true
|
|
loading.value = true
|
|
|
|
const v = await McmCmd.getVersion()
|
|
version.value = v != null ? v : "--"
|
|
|
|
const b = await McmCmd.getBankInfo()
|
|
bankInfo.value = b != null ? b.trim() : "--"
|
|
|
|
const s = await McmCmd.getSysInfo()
|
|
sysInfo.value = s != null ? s : "--"
|
|
|
|
loading.value = false
|
|
}
|
|
|
|
// ================= 蓝牙状态监听 =================
|
|
|
|
function onBleStatueListener(state: number) {
|
|
if (state == 10000 || state == 10001) {
|
|
connected.value = false
|
|
version.value = "--"
|
|
bankInfo.value = "--"
|
|
sysInfo.value = "--"
|
|
}
|
|
}
|
|
|
|
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: UTSJSONObject | null) => {
|
|
subscribe()
|
|
})
|
|
|
|
onShow(() => {
|
|
subscribe()
|
|
if (Ble.isConnected()) {
|
|
refreshAll()
|
|
} else {
|
|
connected.value = false
|
|
}
|
|
})
|
|
|
|
onHide(() => {
|
|
unsubscribe()
|
|
})
|
|
|
|
onUnload(() => {
|
|
unsubscribe()
|
|
})
|
|
|
|
onPullDownRefresh(() => {
|
|
refreshAll()
|
|
})
|
|
</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;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
.btnRow {
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: flex-end;
|
|
margin-top: 16rpx;
|
|
}
|
|
|
|
.btn {
|
|
background-color: #3A6FA1;
|
|
color: #ffffff;
|
|
}
|
|
|
|
.consoleTitle {
|
|
font-size: 26rpx;
|
|
color: #888888;
|
|
margin-bottom: 12rpx;
|
|
}
|
|
|
|
.consoleText {
|
|
font-size: 22rpx;
|
|
color: #333333;
|
|
font-family: monospace;
|
|
line-height: 1.5;
|
|
}
|
|
</style>
|