Files
akbleserver/components/blecommu.uvue.bak
2026-03-16 10:37:46 +08:00

81 lines
2.3 KiB
Plaintext

<template>
<view>
<view>
<button @tap="loadLogs('')">加载历史数据</button>
</view>
<view v-if="logs.length === 0">暂无数据</view>
<view v-for="item in logs" :key="item.key">
<text>{{ item.type }} | {{ item.timestamp }} | {{ item.data }}</text>
</view>
</view>
</template>
<script lang="uts">
import { sqliteContext } from '@/ak/sqlite.uts'
type LogItem = {
type: string;
timestamp: number;
data: string;
key: string;
};
export default {
name: "blecommu",
data() {
return {
logs: [] as LogItem[]
}
},
methods: {
loadLogs(deviceId: string = '') {
this.logs = [];
// 查询 ble_data_log
sqliteContext.selectSql({
sql: `SELECT id, device_id, service_id, char_id, direction, data, timestamp FROM ble_data_log ORDER BY timestamp DESC`,
success: (res) => {
console.log('查询 ble_data_log 成功', res);
if (Array.isArray(res.data) && res.data.length > 0) {
for (const row of res.data) {
this.logs.push({
type: row[4] === 'send' ? '发送' : '接收',
timestamp: parseInt(row[6]),
data: `service:${row[2]} char:${row[3]} data:${row[5]}`,
key: row[4] + '_' + row[0]
});
}
}
// 查询 ble_event_log
sqliteContext.selectSql({
sql: `SELECT id, device_id, event_type, detail, timestamp FROM ble_event_log WHERE device_id = '${deviceId}' ORDER BY timestamp DESC`,
success: (res2) => {
console.log('查询 ble_event_log 成功', res2);
if (Array.isArray(res2.data) && res2.data.length > 0) {
for (const row of res2.data) {
this.logs.push({
type: '事件',
timestamp: parseInt(row[4]),
data: `type:${row[2]} detail:${row[3]}`,
key: 'event_' + row[0]
});
}
}
this.logs.sort((a, b) => b.timestamp - a.timestamp);
},
fail: (err2) => {
console.log('查询 ble_event_log 失败', err2);
}
});
},
fail: (err) => {
console.log('查询 ble_data_log 失败', err);
}
});
}
}
}
</script>
<style>
</style>