feat: 后端版本迁移修改
This commit is contained in:
+23
-24
@@ -56,39 +56,43 @@ Page({
|
||||
|
||||
// ======== User Info ========
|
||||
loadUserInfo() {
|
||||
request.get('/profile/detail').then(res => {
|
||||
request.get('/plant/profile/detail').then(res => {
|
||||
if (!res) return;
|
||||
|
||||
// Map stats and level info
|
||||
const avatarUrl = res.avatar && res.avatar.url ? res.avatar.url : '';
|
||||
const levelInfo = res.level || {};
|
||||
const levelTag = levelInfo.level ? `Lv.${levelInfo.level} ${levelInfo.title || ''}` : '';
|
||||
// Backend returns PlantUserProfile: {nickName, avatarId, levelId, currentSunlight, ...}
|
||||
// Fetch avatar URL from file service if avatarId exists
|
||||
const avatarId = res.avatarId || '';
|
||||
let avatarUrl = '';
|
||||
if (avatarId) {
|
||||
request.get('/file/' + avatarId).then(fileInfo => {
|
||||
if (fileInfo && fileInfo.url) {
|
||||
this.setData({ userAvatar: fileInfo.url });
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
this.setData({
|
||||
userName: res.nickname || '植物爱好者',
|
||||
userName: res.nickName || '植物爱好者',
|
||||
userAvatar: avatarUrl,
|
||||
currentAvatarId: res.avatarId || (res.avatar ? res.avatar.id : ''),
|
||||
currentAvatarId: avatarId,
|
||||
|
||||
// Stats
|
||||
plantCount: res.plantCount || 0,
|
||||
taskDoneCount: res.careCount || 0,
|
||||
postCount: res.postCount || 0,
|
||||
|
||||
// Level (if available)
|
||||
userLevel: levelInfo.level || 0,
|
||||
userLevelTag: levelTag,
|
||||
// Level (just store levelId, detail fetched on badges page)
|
||||
userLevel: res.levelId || '',
|
||||
userLevelTag: '',
|
||||
|
||||
// EXP / Sunlight
|
||||
userExp: res.currentSunlight || 0,
|
||||
userSunlight: res.currentSunlight || 0,
|
||||
joinedDays: calculateDaysSince(res.createdAt)
|
||||
joinedDays: 0 // createdAt not available in profile response
|
||||
});
|
||||
|
||||
// Update global cache
|
||||
const info = {
|
||||
...res,
|
||||
avatarId: res.avatarId || (res.avatar ? res.avatar.id : '')
|
||||
};
|
||||
const info = { ...res, avatarId: avatarId };
|
||||
app.globalData.userInfo = info;
|
||||
wx.setStorageSync('userInfo', info);
|
||||
|
||||
@@ -216,9 +220,7 @@ Page({
|
||||
// Upload new avatar if changed
|
||||
if (isAvatarChanged) {
|
||||
const uploadRes = await request.upload(tempAvatar);
|
||||
if (uploadRes && uploadRes.file && uploadRes.file.id) {
|
||||
finalAvatarId = uploadRes.file.id;
|
||||
} else if (uploadRes && uploadRes.id) {
|
||||
if (uploadRes && uploadRes.id) {
|
||||
finalAvatarId = uploadRes.id;
|
||||
} else {
|
||||
throw new Error('Avatar upload failed, no ID returned');
|
||||
@@ -232,7 +234,7 @@ Page({
|
||||
};
|
||||
|
||||
// Call API
|
||||
await request.post('/profile/update', updatePayload);
|
||||
await request.post('/plant/profile/update', updatePayload);
|
||||
|
||||
// Update UI State
|
||||
this.setData({
|
||||
@@ -246,13 +248,10 @@ Page({
|
||||
|
||||
// Update Global Data
|
||||
const userInfo = app.globalData.userInfo || {};
|
||||
userInfo.nickname = finalNickname;
|
||||
userInfo.name = finalNickname;
|
||||
// Update avatar structure in global store too
|
||||
userInfo.nickName = finalNickname;
|
||||
if (isAvatarChanged) {
|
||||
userInfo.avatar = { ...(userInfo.avatar || {}), url: tempAvatar, id: finalAvatarId };
|
||||
userInfo.avatarId = finalAvatarId;
|
||||
}
|
||||
userInfo.avatarId = finalAvatarId;
|
||||
|
||||
app.globalData.userInfo = userInfo;
|
||||
wx.setStorageSync('userInfo', userInfo);
|
||||
|
||||
Reference in New Issue
Block a user