feat: 后端版本迁移修改

This commit is contained in:
Blizzard
2026-05-24 01:38:28 +08:00
parent 058a575e10
commit f8d71ee800
29 changed files with 304 additions and 291 deletions
+2 -2
View File
@@ -27,8 +27,8 @@ Page({
try {
// Parallel Fetch: Config Tree & User Badges
const [treeRes, userBadgesRes] = await Promise.all([
request.get('/config/badge/tree'),
request.get('/profile/badge')
request.get('/plant/config/badge/tree'),
request.get('/plant/profile/badge')
]);
const list = Array.isArray(treeRes) ? treeRes : (treeRes.data || []);
+2 -2
View File
@@ -30,8 +30,8 @@ Page({
wx.showLoading({ title: '加载中...' });
try {
const [levelRes, profileRes] = await Promise.all([
request.get('/config/level/list'),
request.get('/profile/detail')
request.get('/plant/config/level/list'),
request.get('/plant/profile/detail')
]);
this.processData(levelRes, profileRes);
} catch (e) {
+2 -2
View File
@@ -25,7 +25,7 @@ Page({
wx.showLoading({ title: '加载中...' });
try {
// Fetch levels
const levelRes = await request.get('/config/level/list');
const levelRes = await request.get('/plant/config/level/list');
let list = [];
@@ -47,7 +47,7 @@ Page({
// Fetch profile if sunlight not passed
let currentSunlight = passedSunlight;
if (currentSunlight === undefined) {
const profileRes = await request.get('/profile/detail');
const profileRes = await request.get('/plant/profile/detail');
currentSunlight = profileRes.totalSunlight || 0;
this.setData({ currentSunlight });
+10 -38
View File
@@ -30,7 +30,7 @@ Page({
async fetchProfile() {
try {
const res = await request.get('/profile/detail');
const res = await request.get('/plant/profile/detail');
if (res) {
this.setData({ currentSunlight: res.currentSunlight || 0 });
}
@@ -44,7 +44,7 @@ Page({
this.setData({ isLoading: true, current: 1, items: [] });
}
try {
const res = await request.get('/exchange/list', {
const res = await request.get('/plant/exchange/list', {
current: this.data.current,
pageSize: this.data.pageSize,
type: this.data.activeType
@@ -52,35 +52,11 @@ Page({
const rawList = (res && res.list) ? res.list : [];
const total = (res && res.total) ? res.total : 0;
const now = Date.now();
const list = rawList.map(item => {
const hasStart = !!item.startTime;
const hasEnd = !!item.endTime;
const startTs = hasStart ? new Date(item.startTime).getTime() : 0;
const endTs = hasEnd ? new Date(item.endTime).getTime() : 0;
const notStarted = hasStart && now < startTs;
const hasEnded = hasEnd && now > endTs;
const isActive = !notStarted && !hasEnded;
let timeLabel = '';
if (hasStart && hasEnd) {
timeLabel = this.formatDate(item.startTime) + ' ~ ' + this.formatDate(item.endTime);
} else if (hasStart) {
timeLabel = this.formatDate(item.startTime) + ' 起';
} else if (hasEnd) {
timeLabel = '截止 ' + this.formatDate(item.endTime);
}
return {
...item,
hasTimeLimit: hasStart || hasEnd,
timeLabel,
notStarted,
hasEnded,
isActive
};
});
// Backend ExchangeItemInfo: {id, name, desc, imgId, cost, stock, status}
const list = rawList.map(item => ({
...item,
isActive: item.status === 1 || !item.status
}));
this.setData({
items: append ? [...this.data.items, ...list] : list,
@@ -115,12 +91,8 @@ Page({
// Redeem Flow
onItemTap(e) {
const item = e.currentTarget.dataset.item;
if (item.notStarted) {
wx.showToast({ title: '活动尚未开始', icon: 'none' });
return;
}
if (item.hasEnded) {
wx.showToast({ title: '活动已结束', icon: 'none' });
if (!item.isActive) {
wx.showToast({ title: '当前不可兑换', icon: 'none' });
return;
}
if (item.stock === 0) {
@@ -164,7 +136,7 @@ Page({
wx.showLoading({ title: '兑换中...', mask: true });
try {
await request.post('/exchange/redeem', {
await request.post('/plant/exchange/redeem', {
itemId: item.id,
quantity: 1,
...this.data.redeemForm
+1 -1
View File
@@ -44,7 +44,7 @@ Page({
if (this.data.activeStatus) {
params.status = this.data.activeStatus;
}
const res = await request.get('/exchange/orders', params);
const res = await request.get('/plant/exchange/orders', params);
let list = (res && res.list) ? res.list : [];
const total = (res && res.total) ? res.total : 0;
+2 -2
View File
@@ -33,7 +33,7 @@ Page({
if (this.data.favTab === 'plant') classType = 1;
if (this.data.favTab === 'post') classType = 2;
request.post('/profile/star', {
request.post('/plant/profile/star', {
current,
pageSize: this.data.pageSize,
class: classType
@@ -111,7 +111,7 @@ Page({
const item = e.currentTarget.dataset.item;
const { id, type } = item;
const apiPath = type === 'plant' ? '/wiki/star' : '/post/star';
const apiPath = type === 'plant' ? '/plant/wiki/star' : '/plant/post/star';
wx.showModal({
title: '提示',
+2 -2
View File
@@ -18,7 +18,7 @@ Page({
async loadRecords() {
this.setData({ loading: true });
try {
const res = await request.post('/classify/myClassifyLog', {
const res = await request.post('/plant/classify/myClassifyLog', {
page: this.data.page,
pageSize: this.data.pageSize,
});
@@ -89,7 +89,7 @@ Page({
success: (res) => {
if (res.confirm) {
wx.showLoading({ title: '删除中' });
request.post('/classify/deleteClassifyLog', { ids: [id] }).then(() => {
request.post('/plant/classify/deleteClassifyLog', { ids: [id] }).then(() => {
wx.hideLoading();
wx.showToast({ title: '删除成功', icon: 'success' });
const newRecords = this.data.records.filter(r => r.id !== id);
+23 -24
View File
@@ -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);
+2 -2
View File
@@ -36,7 +36,7 @@ Page({
const { pageSize } = this.data;
try {
const res = await request.post('/post/myPost', {
const res = await request.post('/plant/post/myPost', {
current,
pageSize
});
@@ -107,7 +107,7 @@ Page({
wx.showLoading({ title: '删除中...' });
// Use new API: POST /post/delete with ids array
request.post('/post/delete', { ids: [postId] }).then(() => {
request.post('/plant/post/delete', { ids: [postId] }).then(() => {
wx.hideLoading();
wx.showToast({ title: '已删除', icon: 'success' });
// Remove from list locally