feat: 完善人生轨迹详情页功能及微信小程序登录优化

This commit is contained in:
2026-06-15 10:17:30 +08:00
parent cb3c5e6724
commit 74a2c15b6b
37 changed files with 1974 additions and 516 deletions
+17
View File
@@ -40,6 +40,22 @@ export const login = async ({ phone, smsCode }) => {
return response
}
export const wechatLogin = async ({ code, nickname, avatar }) => {
const response = await post('/auth/wechat/login', { code, nickname, avatar })
if (response.data) {
const { accessToken, refreshToken } = response.data
if (accessToken) {
uni.setStorageSync('access_token', accessToken)
}
if (refreshToken) {
uni.setStorageSync('refresh_token', refreshToken)
}
}
return response
}
/**
* 用户登出
* @returns {Promise<void>}
@@ -120,6 +136,7 @@ export const checkPhone = async (phone) => {
export default {
getSmsCode,
login,
wechatLogin,
logout,
refreshToken,
validateToken,
+16 -1
View File
@@ -95,6 +95,10 @@ const transformToBackendFormat = (frontendData) => {
character,
events,
plotJson,
conversationId,
parentScriptId,
revisionIndex,
revisionOf,
useSocialInsights
} = frontendData
@@ -112,7 +116,14 @@ const transformToBackendFormat = (frontendData) => {
plotTurning: frontendData.plotTurning || '',
plotClimax: frontendData.plotClimax || '',
plotEnding: frontendData.plotEnding || '',
plotJson: plotJson || (content ? { fullContent: content } : null),
plotJson: {
...(content ? { fullContent: content } : {}),
...(plotJson || {}),
...(conversationId ? { conversationId } : {}),
...(parentScriptId ? { parentScriptId } : {}),
...(revisionIndex ? { revisionIndex } : {}),
...(revisionOf ? { revisionOf } : {})
},
isSelected,
characterInfo,
lifeEventsSummary,
@@ -171,6 +182,10 @@ export const transformToFrontendFormat = (backendData) => {
date: createTime ? String(createTime).slice(0, 10) : new Date().toLocaleDateString(),
mode: plotJson?.mode || 'custom',
prompt: plotJson?.prompt || '',
conversationId: plotJson?.conversationId || '',
parentScriptId: plotJson?.parentScriptId || '',
revisionIndex: plotJson?.currentRevisionIndex || plotJson?.revisionIndex || 0,
revisionOf: plotJson?.revisionOf || '',
wordCount: content ? content.length : 0
}
}
+27 -9
View File
@@ -6,6 +6,24 @@
import { get, post, put } from './request.js'
const normalizeDate = (value) => {
if (!value) return ''
return String(value).slice(0, 10)
}
const parseJsonArray = (value) => {
if (Array.isArray(value)) return value
if (!value) return []
if (typeof value !== 'string') return []
try {
const parsed = JSON.parse(value)
return Array.isArray(parsed) ? parsed : []
} catch (error) {
console.warn('[userProfile] JSON array parse failed', error)
return []
}
}
/**
* 获取当前用户档案
* @returns {Promise<Object|null>} 用户档案
@@ -85,9 +103,9 @@ const transformToBackendFormat = (frontendData) => {
futureVision: future?.vision || null,
// 理想生活状态
idealLife: future?.ideal || null,
city: city || null,
industry: industry || null,
company: company || null,
city: city ?? '',
industry: industry ?? '',
company: company ?? '',
personalityTags: Array.isArray(personalityTags) ? JSON.stringify(personalityTags) : personalityTags,
birthday: birthday || null
}
@@ -134,20 +152,20 @@ export const transformToFrontendFormat = (backendData) => {
profession: profession || '',
mbti: mbti || '',
// 兴趣爱好从JSON字符串解析
hobbies: hobbies ? (typeof hobbies === 'string' ? JSON.parse(hobbies) : hobbies) : [],
hobbies: parseJsonArray(hobbies),
// 童年经历
childhood: {
date: childhoodDate || '',
date: normalizeDate(childhoodDate),
text: childhoodContent || ''
},
// 高光时刻
joy: {
date: peakDate || '',
date: normalizeDate(peakDate),
text: peakContent || ''
},
// 低谷时期
low: {
date: valleyDate || '',
date: normalizeDate(valleyDate),
text: valleyContent || ''
},
// 未来期许
@@ -158,8 +176,8 @@ export const transformToFrontendFormat = (backendData) => {
city: city || '',
industry: industry || '',
company: company || '',
personalityTags: personalityTags ? (typeof personalityTags === 'string' ? JSON.parse(personalityTags) : personalityTags) : [],
birthday: birthday || ''
personalityTags: parseJsonArray(personalityTags),
birthday: normalizeDate(birthday)
}
}