feat: 更新前端多个页面和后端服务
- 前端: 更新AI营养师、计算器、打卡、食物详情等页面 - 前端: 更新食物百科、知识详情、营养知识页面 - 前端: 更新社区首页 - 后端: 更新ToolKieAIServiceImpl服务 - API: 更新models-api.js和user.js
This commit is contained in:
@@ -241,17 +241,20 @@ export default {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { setSignIntegral, getUserInfo } = await import('@/api/user.js');
|
||||
const { setSignIntegral, getFrontUserInfo, getUserInfo } = await import('@/api/user.js');
|
||||
const { getUserPoints } = await import('@/api/tool.js');
|
||||
|
||||
// 子问题 A:不得在 API 返回成功前修改 currentPoints,避免打卡前积分提前跳变
|
||||
// 子问题 B-1:打卡接口为 GET /api/front/user/sign/integral(setSignIntegral),与 /api/front/user/checkin 同属签到类接口
|
||||
// 打卡接口:GET /api/front/user/sign/integral(setSignIntegral),等同于 checkin 签到
|
||||
await setSignIntegral();
|
||||
|
||||
this.todaySigned = true;
|
||||
|
||||
// 子问题 B-2/B-3:仅用服务端返回值更新积分,禁止前端本地 +30。调用 GET /api/front/user(getUserInfo)刷新用户信息,将返回的 integral 赋给 currentPoints
|
||||
const userRes = await getUserInfo();
|
||||
// 子问题 B:仅在打卡成功后用服务端数据更新积分。先 GET /api/front/user/info 刷新用户积分,禁止硬编码 +30
|
||||
let userRes = null;
|
||||
try {
|
||||
userRes = await getFrontUserInfo(); // GET /api/front/user/info
|
||||
} catch (_) {
|
||||
userRes = await getUserInfo().catch(() => null);
|
||||
}
|
||||
if (userRes && userRes.data && (userRes.data.integral != null || userRes.data.points != null)) {
|
||||
this.currentPoints = userRes.data.integral ?? userRes.data.points ?? 0;
|
||||
} else {
|
||||
@@ -261,6 +264,9 @@ export default {
|
||||
this.currentPoints = serverPoints;
|
||||
}
|
||||
}
|
||||
|
||||
// 积分已从服务端更新后再更新打卡状态并跳转,避免“已打卡”与积分不同步
|
||||
this.todaySigned = true;
|
||||
} catch (e) {
|
||||
const msg = (typeof e === 'string' ? e : (e && (e.message || e.msg))) || '打卡失败';
|
||||
if (msg.includes('今日已签到') || msg.includes('不可重复')) {
|
||||
|
||||
Reference in New Issue
Block a user