Files
zyt/TUICallKit-Vue3/training/pages/components/pose-summary.vue
T
long c3f4d726e0 feat: 新增 AI 跟练(训练分包)
- 页面:pose-hub 选择动作,pose-coach 跟练(教练小甄示范 + 摄像头动作识别计数)
- 动作:徒手深蹲、原地高抬腿、低冲击开合、站姿侧平举
- VisionKit 人体识别,按动作幅度计数、评分、纠错;没有摄像头或识别不可用时自动进入领练模式
- 教练逐帧动画:分包内置 600px 帧,COS 高清帧全部加载完后无缝切换
- 语音报数与口令(WechatSI),舒缓背景音乐(COS,教练说话时自动压低,可关闭)
- 逻辑单测:npm run test:pose
2026-10-31 10:33:25 +08:00

411 lines
10 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>
<view class="summary" :style="{ '--accent': exercise.color, '--accent-soft': soft }">
<scroll-view scroll-y class="summary__scroll">
<view class="summary__hero">
<view class="summary__mascot">
<CoachSprite mode="gesture" :gesture="summary.stars >= 2 ? 'cheer' : 'thumbs'" />
</view>
<text class="summary__title">{{ title }}</text>
<view class="summary__stars">
<text v-for="i in 3" :key="i" class="summary__star" :class="{ 'is-on': i <= summary.stars }">★</text>
</view>
<text class="summary__sub">{{ exercise.name }} · {{ summary.reps }}/{{ summary.targetReps }} 次</text>
</view>
<view class="summary__card summary__score">
<view class="score-ring" :style="{ background: ringBg }">
<view class="score-ring__inner">
<text class="score-ring__value">{{ summary.scores.length ? summary.avgScore : '--' }}</text>
<text class="score-ring__label">动作评分</text>
</view>
</view>
<view class="stats">
<view class="stats__item">
<text class="stats__value">{{ summary.reps }}</text>
<text class="stats__label">完成次数</text>
</view>
<view class="stats__item">
<text class="stats__value">{{ duration }}</text>
<text class="stats__label">训练用时</text>
</view>
<view class="stats__item">
<text class="stats__value">{{ summary.bestCombo }}</text>
<text class="stats__label">最高连击</text>
</view>
<view class="stats__item">
<text class="stats__value">{{ summary.kcal }}</text>
<text class="stats__label">约消耗千卡</text>
</view>
</view>
</view>
<view v-if="summary.scores.length" class="summary__card">
<view class="card-head">
<text class="card-head__title">每次动作质量</text>
<view class="legend">
<view class="legend__dot is-perfect" /><text class="legend__text">完美</text>
<view class="legend__dot is-good" /><text class="legend__text">不错</text>
<view class="legend__dot is-ok" /><text class="legend__text">待改进</text>
</view>
</view>
<view class="bars">
<view
v-for="(s, i) in summary.scores"
:key="i"
class="bars__bar"
:class="gradeClass(s)"
:style="{ height: barHeight(s) }"
/>
</view>
</view>
<view class="summary__card advice">
<view class="advice__icon"><text>{{ summary.adviceKind === 'tip' ? '练' : '赞' }}</text></view>
<view class="advice__body">
<text class="advice__title">{{ summary.adviceKind === 'tip' ? '下次注意' : '教练点评' }}</text>
<text class="advice__text">{{ summary.advice }}</text>
</view>
</view>
<text class="summary__note">千卡为估算值(按 60kg 体重),仅供参考</text>
<view class="summary__spacer" />
</scroll-view>
<view class="summary__actions-bg" />
<view class="summary__actions">
<view class="btn btn--ghost" @click="emit('change')"><text>换个动作</text></view>
<view class="btn btn--primary" @click="emit('restart')"><text>再练一组</text></view>
</view>
<view class="summary__done" @click="emit('done')"><text>完成</text></view>
</view>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import CoachSprite from './coach-sprite.vue'
import type { SessionSummary } from '../../pose/session'
import type { ExerciseInfo } from '../../pose/exercises'
const props = defineProps<{ summary: SessionSummary; exercise: ExerciseInfo }>()
const emit = defineEmits<{ (e: 'restart'): void; (e: 'change'): void; (e: 'done'): void }>()
const title = computed(() => {
if (props.summary.stars === 3) return '完美完成!'
if (props.summary.stars === 2) return '完成得不错!'
return props.summary.reps > 0 ? '今天也动起来了' : '下次再接再厉'
})
const duration = computed(() => {
const s = props.summary.durationSec
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`
})
const soft = computed(() => `${props.exercise.color}1f`)
const ringBg = computed(() => {
const deg = Math.round((props.summary.avgScore / 100) * 360)
return `conic-gradient(${props.exercise.color} ${deg}deg, #e6ece8 ${deg}deg)`
})
function gradeClass(s: number) {
return s >= 90 ? 'is-perfect' : s >= 75 ? 'is-good' : 'is-ok'
}
function barHeight(s: number) {
return `${Math.max(18, Math.round(((s - 50) / 50) * 120))}rpx`
}
</script>
<style lang="scss" scoped>
.summary {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 50;
background: linear-gradient(180deg, var(--accent-soft) 0%, #f4fbf4 38%, #f4fbf4 100%);
display: flex;
flex-direction: column;
}
.summary__scroll {
flex: 1;
height: 0;
}
.summary__hero {
display: flex;
flex-direction: column;
align-items: center;
padding-top: calc(env(safe-area-inset-top) + 60rpx);
}
.summary__mascot {
width: 420rpx;
height: 420rpx;
margin-bottom: -20rpx;
}
.summary__title {
margin-top: 8rpx;
font-size: 48rpx;
font-weight: 800;
color: #161d19;
}
.summary__stars {
display: flex;
gap: 12rpx;
margin-top: 12rpx;
}
.summary__star {
font-size: 52rpx;
color: #dde4dd;
&.is-on {
color: #fbbf24;
}
}
.summary__sub {
margin-top: 8rpx;
font-size: 26rpx;
color: #3c4a42;
}
.summary__card {
margin: 28rpx 32rpx 0;
padding: 32rpx;
background: #fff;
border-radius: 36rpx;
box-shadow: 0 12rpx 40rpx rgba(22, 29, 25, 0.06);
}
.summary__score {
display: flex;
align-items: center;
gap: 32rpx;
}
.score-ring {
width: 200rpx;
height: 200rpx;
border-radius: 50%;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.score-ring__inner {
width: 164rpx;
height: 164rpx;
border-radius: 50%;
background: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.score-ring__value {
font-size: 60rpx;
font-weight: 800;
color: var(--accent);
line-height: 1.1;
}
.score-ring__label {
font-size: 22rpx;
color: #6c7a71;
}
.stats {
flex: 1;
display: flex;
flex-wrap: wrap;
row-gap: 24rpx;
}
.stats__item {
width: 50%;
display: flex;
flex-direction: column;
}
.stats__value {
font-size: 40rpx;
font-weight: 700;
color: #161d19;
}
.stats__label {
font-size: 22rpx;
color: #6c7a71;
margin-top: 4rpx;
}
.card-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24rpx;
}
.card-head__title {
font-size: 30rpx;
font-weight: 700;
color: #161d19;
}
.legend {
display: flex;
align-items: center;
gap: 8rpx;
}
.legend__dot {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
}
.legend__text {
font-size: 20rpx;
color: #6c7a71;
margin-right: 8rpx;
}
.bars {
display: flex;
align-items: flex-end;
gap: 8rpx;
height: 130rpx;
overflow: hidden;
}
.bars__bar {
flex: 1;
max-width: 36rpx;
border-radius: 10rpx 10rpx 4rpx 4rpx;
}
.is-perfect {
background: #10b981;
}
.is-good {
background: #6ee7b7;
}
.is-ok {
background: #fbbf24;
}
.advice {
display: flex;
align-items: center;
gap: 24rpx;
}
.advice__icon {
width: 72rpx;
height: 72rpx;
border-radius: 24rpx;
background: var(--accent-soft);
color: var(--accent);
font-size: 30rpx;
font-weight: 800;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.advice__body {
display: flex;
flex-direction: column;
}
.advice__title {
font-size: 24rpx;
color: #6c7a71;
}
.advice__text {
font-size: 30rpx;
font-weight: 600;
color: #161d19;
margin-top: 6rpx;
}
.summary__note {
display: block;
text-align: center;
font-size: 22rpx;
color: #93a39a;
margin-top: 28rpx;
}
.summary__spacer {
height: 260rpx;
}
/* 底部操作区:渐变底色把滚动内容衬到按钮下方,避免文字与按钮叠在一起 */
.summary__actions-bg {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: calc(env(safe-area-inset-bottom) + 260rpx);
background: linear-gradient(180deg, rgba(244, 251, 244, 0) 0%, #f4fbf4 36%);
pointer-events: none;
}
.summary__actions {
position: absolute;
left: 32rpx;
right: 32rpx;
bottom: calc(env(safe-area-inset-bottom) + 110rpx);
display: flex;
gap: 24rpx;
}
.btn {
height: 100rpx;
border-radius: 50rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 32rpx;
font-weight: 700;
}
.btn--ghost {
flex: 1;
background: #fff;
color: #161d19;
box-shadow: 0 8rpx 24rpx rgba(22, 29, 25, 0.08);
}
.btn--primary {
flex: 1.4;
background: linear-gradient(135deg, #10b981, #006c49);
color: #fff;
box-shadow: 0 12rpx 32rpx rgba(0, 108, 73, 0.3);
}
.summary__done {
position: absolute;
left: 0;
right: 0;
bottom: calc(env(safe-area-inset-bottom) + 30rpx);
text-align: center;
font-size: 28rpx;
color: #3c4a42;
padding: 16rpx;
}
</style>