feat: 更新 CLAUDE.md 文件及多个组件以优化用户体验和功能
- 更新 CLAUDE.md 文件,重构架构部分,增加认证和数据层的描述 - 在 GoalsScreen 中新增目标模板选择功能,支持用户选择和创建目标 - 在 CreateGoalModal 中添加初始数据支持,优化目标创建体验 - 新增 GoalTemplateModal 组件,提供目标模板选择界面 - 更新 NotificationHelpers,支持构建深度链接以便于导航 - 在 CoachScreen 中处理路由参数,增强用户交互体验 - 更新多个组件的样式和逻辑,提升整体用户体验 - 删除不再使用的中文回复规则文档
This commit is contained in:
@@ -118,8 +118,17 @@ const CardType = {
|
||||
type CardType = typeof CardType[keyof typeof CardType];
|
||||
|
||||
|
||||
// 定义路由参数类型
|
||||
type CoachScreenParams = {
|
||||
name?: string;
|
||||
action?: 'diet' | 'weight' | 'mood' | 'workout';
|
||||
subAction?: 'record' | 'photo' | 'text' | 'card';
|
||||
meal?: 'breakfast' | 'lunch' | 'dinner' | 'snack';
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export default function CoachScreen() {
|
||||
const params = useLocalSearchParams<{ name?: string }>();
|
||||
const params = useLocalSearchParams<CoachScreenParams>();
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
const { isLoggedIn, pushIfAuthedElseLogin } = useAuthGuard();
|
||||
@@ -389,6 +398,69 @@ export default function CoachScreen() {
|
||||
};
|
||||
}, [insets.bottom]);
|
||||
|
||||
// 处理路由参数动作
|
||||
useEffect(() => {
|
||||
// 确保用户已登录且消息已加载
|
||||
if (!isLoggedIn || messages.length === 0) return;
|
||||
|
||||
// 检查是否有动作参数
|
||||
if (params.action) {
|
||||
const executeAction = async () => {
|
||||
try {
|
||||
switch (params.action) {
|
||||
case 'diet':
|
||||
if (params.subAction === 'card') {
|
||||
// 插入饮食记录卡片
|
||||
insertDietInputCard();
|
||||
} else if (params.subAction === 'record' && params.message) {
|
||||
// 直接发送预设的饮食记录消息
|
||||
const mealPrefix = params.meal ? `${getMealDisplayName(params.meal)}` : '';
|
||||
const message = `#记饮食:${mealPrefix}${decodeURIComponent(params.message)}`;
|
||||
await sendStream(message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'weight':
|
||||
if (params.subAction === 'card') {
|
||||
// 插入体重记录卡片
|
||||
insertWeightInputCard();
|
||||
} else if (params.subAction === 'record' && params.message) {
|
||||
// 直接发送预设的体重记录消息
|
||||
const message = `#记体重:${decodeURIComponent(params.message)}`;
|
||||
await sendStream(message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mood':
|
||||
// 跳转到心情记录页面
|
||||
pushIfAuthedElseLogin('/mood/calendar');
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn('未知的动作类型:', params.action);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('执行路由动作失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 延迟执行,确保页面已完全加载
|
||||
const timer = setTimeout(executeAction, 500);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [params.action, params.subAction, params.meal, params.message, isLoggedIn, messages.length]);
|
||||
|
||||
// 获取餐次显示名称
|
||||
const getMealDisplayName = (meal: string): string => {
|
||||
const mealNames: Record<string, string> = {
|
||||
breakfast: '早餐',
|
||||
lunch: '午餐',
|
||||
dinner: '晚餐',
|
||||
snack: '加餐'
|
||||
};
|
||||
return mealNames[meal] || '';
|
||||
};
|
||||
|
||||
const streamAbortRef = useRef<{ abort: () => void } | null>(null);
|
||||
|
||||
// 组件卸载时清理流式请求和定时器
|
||||
|
||||
Reference in New Issue
Block a user