chore(training): AI 跟练识别诊断面板默认关闭

诊断面板和 console 识别摘要改为编译时设置 VITE_POSE_DIAG=1 才开启(与远程日志 VITE_POSE_LOG_URL 一致),
开发版平时不再显示,需要真机排查时再打开。
This commit is contained in:
2026-10-31 12:18:40 +08:00
parent 1129620c21
commit 99388aa58b
3 changed files with 16 additions and 13 deletions
@@ -81,8 +81,8 @@
</view>
</view>
<!-- 开发版真机排查:识别数据面板(只在摄像头识别模式显示,发行版不渲染) -->
<view v-if="IS_DEV && mode === 'vision'" class="diag">
<!-- 真机排查用的识别数据面板:默认关闭,开发版编译时设置 VITE_POSE_DIAG=1 才显示 -->
<view v-if="poseDiagEnabled && mode === 'vision'" class="diag">
<text class="diag__text">{{ diagText }}</text>
</view>
@@ -186,7 +186,7 @@ import { useCoachVoice } from '../pose/useCoachVoice'
import { useBgm } from '../pose/useBgm'
import type { BgmState } from '../pose/bgm'
import { appendHistory, uniStorage } from '../pose/history'
import { remoteLogEnabled, rlog, rlogSession } from '../pose/remoteLog'
import { poseDiagEnabled, remoteLogEnabled, rlog, rlogSession } from '../pose/remoteLog'
const IS_DEV = process.env.NODE_ENV === 'development'
const MIRROR_KEY = 'pose_coach_overlay_mirror'
+9 -5
View File
@@ -1,15 +1,19 @@
/**
* 开发版真机排查:把跟练的识别数据批量发到电脑上的日志服务,边练边看。
*
* 地址在编译时用环境变量 VITE_POSE_LOG_URL 指定(如 http://192.168.8.11:8787/log),不写进代码;
* 没设置或发行版时整个模块是空操作。需要项目关闭合法域名校验(manifest 里 urlCheck: false)。
* 开发版真机排查(默认全部关闭,编译时用环境变量打开,发行版始终不生效):
* - VITE_POSE_DIAG=1:跟练页显示识别诊断面板,console 每 2 秒输出识别摘要
* - VITE_POSE_LOG_URL=http://电脑局域网IP:端口/log:把识别数据批量发到电脑上的日志服务,边练边看。
* 地址不写进代码;需要项目关闭合法域名校验(manifest 里 urlCheck: false)
*/
const LOG_URL: string = ((import.meta as any).env?.VITE_POSE_LOG_URL as string | undefined) || ''
const FLUSH_MS = 1000
/** 断网时最多攒这么多条,超出丢最旧的 */
const MAX_QUEUE = 600
export const remoteLogEnabled = Boolean(LOG_URL) && process.env.NODE_ENV === 'development'
const IS_DEV = process.env.NODE_ENV === 'development'
export const remoteLogEnabled = Boolean(LOG_URL) && IS_DEV
/** 识别诊断面板和 console 摘要 */
export const poseDiagEnabled = IS_DEV && Boolean((import.meta as any).env?.VITE_POSE_DIAG)
let queue: Record<string, unknown>[] = []
let timer: ReturnType<typeof setTimeout> | null = null
@@ -9,7 +9,7 @@
*/
import { ref, shallowRef, onUnmounted } from 'vue'
import { anchorToPose, smoothPose, type Pose } from './keypoints.ts'
import { rlog } from './remoteLog.ts'
import { poseDiagEnabled, rlog } from './remoteLog.ts'
export type CameraStatus = 'idle' | 'starting' | 'running' | 'unsupported' | 'denied' | 'error'
@@ -36,7 +36,6 @@ export type PoseDiag = {
raw: string
}
const IS_DEV = process.env.NODE_ENV === 'development'
export function usePoseCamera(onPose?: (pose: Pose | null) => void) {
const status = ref<CameraStatus>('idle')
@@ -106,7 +105,7 @@ export function usePoseCamera(onPose?: (pose: Pose | null) => void) {
/** 记下原始 anchor 的摘要;第一次识别到人时把完整原始数据打到 console,便于核对字段格式 */
function recordRaw(anchor: any) {
if (IS_DEV && !firstAnchorLogged) {
if (poseDiagEnabled && !firstAnchorLogged) {
firstAnchorLogged = true
// anchor 是原生对象,字段不可枚举,直接 JSON.stringify 得到 {};逐个取出再序列化,NaN 显式写出来
const json = JSON.stringify(plainAnchor(anchor))
@@ -120,7 +119,7 @@ export function usePoseCamera(onPose?: (pose: Pose | null) => void) {
if (now - lastDiagAt < DIAG_REFRESH_MS) return
lastDiagAt = now
diag.value = { events: { ...events }, latencyMs, raw: lastRaw }
if (IS_DEV && now - lastLogAt >= DIAG_LOG_MS) {
if (poseDiagEnabled && now - lastLogAt >= DIAG_LOG_MS) {
lastLogAt = now
const e = events
console.log(
@@ -212,7 +211,7 @@ export function usePoseCamera(onPose?: (pose: Pose | null) => void) {
})
} catch (e) {
events.error += 1
if (IS_DEV) console.warn('[跟练诊断] detectBody 异常', e)
if (poseDiagEnabled) console.warn('[跟练诊断] detectBody 异常', e)
rlog('detect_err', { err: String((e as any)?.message || e) })
clearPending()
}