From 99388aa58bfc6aa5b478123c77f33229db236144 Mon Sep 17 00:00:00 2001 From: long <452591453@qq.com> Date: Sat, 31 Oct 2026 12:18:40 +0800 Subject: [PATCH] =?UTF-8?q?chore(training):=20AI=20=E8=B7=9F=E7=BB=83?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E8=AF=8A=E6=96=AD=E9=9D=A2=E6=9D=BF=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 诊断面板和 console 识别摘要改为编译时设置 VITE_POSE_DIAG=1 才开启(与远程日志 VITE_POSE_LOG_URL 一致), 开发版平时不再显示,需要真机排查时再打开。 --- TUICallKit-Vue3/training/pages/pose-coach.vue | 6 +++--- TUICallKit-Vue3/training/pose/remoteLog.ts | 14 +++++++++----- TUICallKit-Vue3/training/pose/usePoseCamera.ts | 9 ++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/TUICallKit-Vue3/training/pages/pose-coach.vue b/TUICallKit-Vue3/training/pages/pose-coach.vue index 790cb81c3..0002bce67 100644 --- a/TUICallKit-Vue3/training/pages/pose-coach.vue +++ b/TUICallKit-Vue3/training/pages/pose-coach.vue @@ -81,8 +81,8 @@ - - + + {{ diagText }} @@ -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' diff --git a/TUICallKit-Vue3/training/pose/remoteLog.ts b/TUICallKit-Vue3/training/pose/remoteLog.ts index 7e77be405..d9b23e6cb 100644 --- a/TUICallKit-Vue3/training/pose/remoteLog.ts +++ b/TUICallKit-Vue3/training/pose/remoteLog.ts @@ -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[] = [] let timer: ReturnType | null = null diff --git a/TUICallKit-Vue3/training/pose/usePoseCamera.ts b/TUICallKit-Vue3/training/pose/usePoseCamera.ts index d24e0a3cb..f9e17c85c 100644 --- a/TUICallKit-Vue3/training/pose/usePoseCamera.ts +++ b/TUICallKit-Vue3/training/pose/usePoseCamera.ts @@ -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('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() }