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
+55 -8
View File
@@ -55,6 +55,15 @@ const resetAuthState = () => {
state.userProfile = null
}
const applyProfileResponse = (profileData) => {
const profile = userProfileService.transformToFrontendFormat(profileData)
state.userProfile = profile
if (profile) {
Object.assign(state.registrationData, profile)
}
return profile
}
const clearStoredTokens = () => {
uni.removeStorageSync('access_token')
uni.removeStorageSync('refresh_token')
@@ -98,14 +107,14 @@ const fetchUserProfile = async (options = {}) => {
try {
const res = await userProfileService.getCurrentProfile()
if (res.data) {
state.userProfile = userProfileService.transformToFrontendFormat(res.data)
Object.assign(state.registrationData, state.userProfile)
const profile = applyProfileResponse(res.data)
logAuth('profile:success', { hasProfile: true })
return profile
} else {
state.userProfile = null
logAuth('profile:empty', { hasProfile: false })
}
return res.data
return null
} catch (error) {
state.userProfile = null
logAuth('profile:fail', {
@@ -125,13 +134,17 @@ const saveUserProfile = async () => {
state.isLoading = true
try {
const dataToSave = { ...state.registrationData }
let response
if (state.userProfile?.id) {
await userProfileService.updateProfile({
response = await userProfileService.updateProfile({
id: state.userProfile.id,
...dataToSave
})
} else {
await userProfileService.createProfile(dataToSave)
response = await userProfileService.createProfile(dataToSave)
}
if (response?.data) {
applyProfileResponse(response.data)
}
await fetchUserProfile()
return { success: true }
@@ -243,8 +256,30 @@ const fetchScripts = async () => {
const createScript = async (scriptData) => {
try {
const res = await epicScriptService.createScript(scriptData)
const script = epicScriptService.transformToFrontendFormat(res.data)
await fetchScripts()
return { success: true, data: res.data }
return { success: true, data: script || res.data }
} catch (error) {
return { success: false, error: error.message }
}
}
const updateScript = async (scriptData) => {
try {
const res = await epicScriptService.updateScript(scriptData)
const script = epicScriptService.transformToFrontendFormat(res.data)
await fetchScripts()
return { success: true, data: script || res.data }
} catch (error) {
return { success: false, error: error.message }
}
}
const deleteScript = async (id) => {
try {
await epicScriptService.deleteScript(id)
await fetchScripts()
return { success: true }
} catch (error) {
return { success: false, error: error.message }
}
@@ -416,8 +451,18 @@ const initialize = async () => {
export const useAppStore = () => {
return readonly({
...state,
hasProfile,
get isLoggedIn() { return state.isLoggedIn },
get isLoading() { return state.isLoading },
get currentStep() { return state.currentStep },
get userInfo() { return state.userInfo },
get userProfile() { return state.userProfile },
get events() { return state.events },
get scripts() { return state.scripts },
get inspirationRecommendations() { return state.inspirationRecommendations },
get paths() { return state.paths },
get currentPath() { return state.currentPath },
get registrationData() { return state.registrationData },
get hasProfile() { return hasProfile.value },
login,
loginWithWechat,
logout,
@@ -436,6 +481,8 @@ export const useAppStore = () => {
getEventById,
fetchScripts,
createScript,
updateScript,
deleteScript,
fetchInspirationRecommendations,
fetchRandomInspirations,
generateScriptFromInspiration,