fix(guest): 游客点共拆搭子不再误报「不能分析自己」,改为引导登录
- 后端 collaboration-analysis 去掉 user-1 fallback,游客无身份返回 LOGIN_REQUIRED - requireEmail 无 x-user-id 时补 code:'LOGIN_REQUIRED'(前端可区分未登录/未绑邮箱) - 前端分析页去 user-1 fallback,游客弹窗「去登录」,取消按页面栈守卫返回 - 活动详情按钮「立即报名」改「报名」(四字换行不美观) - 本地 E2E 4/4;生产已部署验证(内外网 LOGIN_REQUIRED)
This commit is contained in:
@@ -164,7 +164,7 @@
|
||||
loading="{{joining}}"
|
||||
bindtap="{{isCreator ? 'goToEditActivity' : 'handleJoinOrCancel'}}"
|
||||
>
|
||||
{{isCreator ? '编辑活动' : (isJoined ? '取消' : '立即报名')}}
|
||||
{{isCreator ? '编辑活动' : (isJoined ? '取消' : '报名')}}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -25,6 +25,11 @@ Page({
|
||||
async loadAnalysis() {
|
||||
this.setData({ loading: true, error: '' });
|
||||
const { targetUserId, activityId } = this.data;
|
||||
// 游客引导登录后再查看共拆分析
|
||||
if (!wx.getStorageSync('userId')) {
|
||||
this.promptLogin();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
@@ -36,7 +41,7 @@ Page({
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-user-id': wx.getStorageSync('userId') || 'user-1',
|
||||
'x-user-id': wx.getStorageSync('userId'),
|
||||
},
|
||||
timeout: 60000,
|
||||
success: (r) => resolve(r.data),
|
||||
@@ -46,6 +51,8 @@ Page({
|
||||
if (res.success && res.data) {
|
||||
const analysis = this.prepareAnalysis(res.data);
|
||||
this.setData({ analysis, loading: false });
|
||||
} else if (res.code === 'LOGIN_REQUIRED') {
|
||||
this.promptLogin(res.message);
|
||||
} else {
|
||||
this.setData({ loading: false, error: res.message || '分析失败' });
|
||||
}
|
||||
@@ -55,6 +62,29 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 游客引导:弹窗去登录,取消则返回上一页
|
||||
promptLogin(message) {
|
||||
this.setData({ loading: false, error: '' });
|
||||
wx.showModal({
|
||||
title: '登录后查看',
|
||||
content: message || '登录后即可查看与 TA 的共拆潜力分析,还能报名活动、结识书友',
|
||||
confirmText: '去登录',
|
||||
cancelText: '暂不',
|
||||
success: (r) => {
|
||||
if (r.confirm) {
|
||||
wx.navigateTo({ url: '/pages/login/index' });
|
||||
} else {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
wx.navigateBack({ delta: 1 });
|
||||
} else {
|
||||
wx.switchTab({ url: '/pages/home/index' });
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
prepareAnalysis(data) {
|
||||
const analysis = {
|
||||
...data,
|
||||
|
||||
@@ -759,7 +759,7 @@ function verifyOtpStrict(email, code) {
|
||||
// 强制绑邮箱:无邮箱用户的关键业务写操作拦截(EMAIL_REQUIRED)
|
||||
function requireEmail(req, res, next) {
|
||||
const userId = req.headers["x-user-id"];
|
||||
if (!userId) return res.json({ success: false, message: "未登录" });
|
||||
if (!userId) return res.json({ success: false, code: "LOGIN_REQUIRED", message: "未登录" });
|
||||
const u = db.prepare("SELECT email FROM users WHERE id = ?").get(userId);
|
||||
if (!u || !u.email) {
|
||||
return res.json({ success: false, code: "EMAIL_REQUIRED", message: "请先绑定邮箱后再操作(邮箱为身份认定凭证,绑定后不可更改)" });
|
||||
@@ -1688,9 +1688,13 @@ app.delete('/ai/recommendations/:activityId', requireEmail, (req, res) => {
|
||||
// 合作可能性分析
|
||||
app.post('/ai/collaboration-analysis', requireEmail, async (req, res) => {
|
||||
try {
|
||||
const userId = req.headers['x-user-id'] || 'user-1';
|
||||
const userId = req.headers['x-user-id'];
|
||||
const { target_user_id } = req.body;
|
||||
|
||||
if (!userId) {
|
||||
return res.json({ success: false, code: 'LOGIN_REQUIRED', message: '登录后即可查看与 TA 的共拆潜力分析' });
|
||||
}
|
||||
|
||||
if (!target_user_id) {
|
||||
return res.json({ success: false, message: '缺少目标用户ID' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user