bug修复
This commit is contained in:
@@ -42,6 +42,7 @@ const LoginPage = () => {
|
||||
|
||||
/**
|
||||
* 处理登录提交
|
||||
* 登录成功后根据用户档案状态决定跳转目标
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (phone.length !== 11) {
|
||||
@@ -56,9 +57,14 @@ const LoginPage = () => {
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// 尝试调用后端登录
|
||||
await login(phone, code);
|
||||
navigate('/onboarding');
|
||||
// 尝试调用后端登录,返回值包含 hasProfile 标识
|
||||
const result = await login(phone, code);
|
||||
// 根据用户档案状态决定跳转:已有档案直接进入首页,否则进入入站流程
|
||||
if (result.hasProfile) {
|
||||
navigate('/dashboard');
|
||||
} else {
|
||||
navigate('/onboarding');
|
||||
}
|
||||
} catch (error) {
|
||||
// 后端不可用时,使用本地验证
|
||||
if (code === '888888') {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PromptTagGroup } from '../components/PromptTag';
|
||||
import useStore from '../store/useStore';
|
||||
import { inspirationClusters } from '../utils/constants';
|
||||
import * as dictionaryService from '../services/dictionary';
|
||||
import * as lifeEventService from '../services/lifeEvent';
|
||||
|
||||
/**
|
||||
* OnboardingPage 组件
|
||||
@@ -83,6 +84,28 @@ const OnboardingPage = () => {
|
||||
updateRegistration(dataToSave);
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存生命事件到后端
|
||||
* @param {Object} eventData - 事件数据 { date, text }
|
||||
* @param {string} eventType - 事件类型标识
|
||||
* @param {string} title - 事件标题
|
||||
*/
|
||||
const saveLifeEvent = async (eventData, eventType, title) => {
|
||||
if (!eventData?.date || !eventData?.text) return;
|
||||
|
||||
try {
|
||||
await lifeEventService.createEvent({
|
||||
title,
|
||||
time: eventData.date,
|
||||
content: eventData.text,
|
||||
eventType: 'milestone',
|
||||
tags: [eventType]
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`保存${title}失败:`, error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNext = async () => {
|
||||
saveStepData();
|
||||
if (currentStep < 5) {
|
||||
@@ -90,7 +113,19 @@ const OnboardingPage = () => {
|
||||
} else {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
// 保存用户档案
|
||||
await saveUserProfile();
|
||||
|
||||
// 保存生命事件(童年记忆、开心经历、低谷时期)
|
||||
const eventsToSave = [
|
||||
{ data: formData.childhood, type: 'childhood', title: '童年记忆' },
|
||||
{ data: formData.joy, type: 'joy', title: '光芒闪耀的时刻' },
|
||||
{ data: formData.low, type: 'low', title: '在暗夜中潜行' }
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
eventsToSave.map(({ data, type, title }) => saveLifeEvent(data, type, title))
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('保存档案失败:', error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user