feat(personal_collect,motion_reminder): 新增回收站与云端TTS语音功能

- 新增小程序个人收藏回收站页面,支持查看已删除收藏、恢复与彻底删除操作
- 修复个人收藏文件上传时的中文名乱码问题,新增原文件名透传参数
- 接入阿里云百炼TTS服务,实现运动提醒模块的云端语音合成与本地缓存,支持系统TTS与云端MP3双降级播放
- 新增语音引擎探测与异常预警UI,覆盖web端与移动端
- 优化web端订单盒页面布局,修复卡片操作按钮换行问题
- 新增调试探针脚本、ESLint配置与相关lint脚本
- 完善后端接口与路由,更新项目依赖与配置文件
This commit is contained in:
yangxiangyuan
2026-09-17 16:26:27 +08:00
parent d4bf3627fd
commit bbc7ca6523
29 changed files with 3228 additions and 163 deletions
@@ -13,6 +13,15 @@ import { motionReminderApi } from '../api';
import { useRunner } from '../hooks/useRunner';
import { CardEditor } from '../components/CardEditor';
import { RunnerModal } from '../components/RunnerModal';
import {
WELCOME_TEXT,
configureSpeechAudioMode,
confirmSpeechHeard,
getSpeechState,
prepareCardTTS,
probeSpeech,
subscribeSpeechState,
} from '../speech';
import { theme } from '../../../theme';
import { MotionCard, MotionSession, OrderBoxState } from '../../../types';
@@ -40,11 +49,59 @@ export const CardsScreen: React.FC<CardsScreenProps> = ({ onExit, serverState, o
const [loading, setLoading] = useState(true);
const [editorVisible, setEditorVisible] = useState(false);
const [editingCard, setEditingCard] = useState<MotionCard | null>(null);
const [speechState, setSpeechState] = useState(getSpeechState());
const [ttsRegenId, setTtsRegenId] = useState<string | null>(null);
const runner = useRunner(() => {
onRefresh();
});
useEffect(() => subscribeSpeechState(setSpeechState), []);
const askSpeechHeard = () => {
Alert.alert(
'语音检查',
`正在播报欢迎语:${WELCOME_TEXT}\n请确认是否听到声音。`,
[
{ text: '没听到', style: 'destructive', onPress: () => confirmSpeechHeard(false) },
{ text: '听到了', onPress: () => confirmSpeechHeard(true) },
]
);
};
const retrySpeechProbe = async () => {
const engineStarted = await probeSpeech(true);
if (engineStarted) askSpeechHeard();
};
/** 手动补救:强制重建该卡片的云端语音缓存(内容寻址,已存在的文本不会重复调用百炼) */
const regenCardTTS = async (card: MotionCard) => {
if (!card.steps.length) {
Alert.alert('无法生成', '当前卡片没有可执行步骤');
return;
}
setTtsRegenId(card.id);
try {
const result = await prepareCardTTS(card, true);
if (!result) {
Alert.alert('生成失败', '云端语音生成失败,请检查服务与网络后重试(详情见控制台日志)。');
return;
}
Alert.alert(`语音已重新生成(${result.success}/${result.total})`, '该卡片的云端语音缓存已强制重建。');
} finally {
setTtsRegenId(null);
}
};
// 进入运动 kit 时:先配置音频会话(iOS 静音键下也要能播 mp3),再播欢迎语探测系统 TTS
useEffect(() => {
void configureSpeechAudioMode();
void (async () => {
const engineStarted = await probeSpeech();
if (engineStarted) askSpeechHeard();
})();
}, []);
const loadData = useCallback(async () => {
try {
const nextCards = await motionReminderApi.listCards();
@@ -141,6 +198,16 @@ export const CardsScreen: React.FC<CardsScreenProps> = ({ onExit, serverState, o
</View>
) : null}
{speechState.warning ? (
<View style={[styles.warnCard, styles.voiceWarnCard]}>
<Text style={styles.warnCardTitle}>语音播报可能不可用</Text>
<Text style={styles.warnCardText}>{speechState.warning}</Text>
<TouchableOpacity style={styles.secondaryButton} onPress={retrySpeechProbe}>
<Text style={styles.secondaryButtonText}>重新检测</Text>
</TouchableOpacity>
</View>
) : null}
{loading ? (
<ActivityIndicator style={styles.loader} color={theme.colors.primary} />
) : (
@@ -177,6 +244,15 @@ export const CardsScreen: React.FC<CardsScreenProps> = ({ onExit, serverState, o
<TouchableOpacity style={styles.ghostActionButton} onPress={() => deleteCard(item)}>
<Text style={[styles.ghostActionButtonText, styles.dangerText]}>删除</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.ghostActionButton, ttsRegenId === item.id && styles.buttonDisabled]}
onPress={() => regenCardTTS(item)}
disabled={ttsRegenId === item.id}
>
<Text style={styles.ghostActionButtonText}>
{ttsRegenId === item.id ? '生成中…' : '重生语音'}
</Text>
</TouchableOpacity>
</View>
</View>
)}
@@ -347,6 +423,12 @@ const styles = StyleSheet.create({
dangerText: {
color: theme.colors.error,
},
voiceWarnCard: {
borderColor: theme.colors.error,
},
buttonDisabled: {
opacity: 0.5,
},
emptyCard: {
backgroundColor: theme.colors.surface,
borderRadius: theme.borderRadius.lg,