fix: 登录规范合规——游客可浏览,操作时懒登录
- create-activity: 移除进入页面即强制跳登录,改为提交时弹窗引导登录(可取消) - home: 创建活动入口对游客放行,快速报名改为弹窗引导登录(可取消) - activity-detail: 报名改为弹窗引导登录(可取消),游客可完整浏览详情 - request: 401 静默清除登录态,不再全局强制跳转登录页
This commit is contained in:
@@ -135,7 +135,18 @@ Page({
|
||||
},
|
||||
|
||||
async handleJoinOrCancel() {
|
||||
// 报名属于需要身份的操作:游客可浏览详情,仅报名时弹窗引导登录,可取消
|
||||
if (!this.data.isLoggedIn) {
|
||||
const confirm = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '需要登录',
|
||||
content: '登录后即可报名活动,是否前往登录?',
|
||||
confirmText: '去登录',
|
||||
cancelText: '暂不登录',
|
||||
success: (res) => resolve(res.confirm),
|
||||
});
|
||||
});
|
||||
if (!confirm) return;
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/index',
|
||||
});
|
||||
|
||||
@@ -50,7 +50,6 @@ Page({
|
||||
this.loadActivityData(id);
|
||||
}
|
||||
this.loadRecommendedTags();
|
||||
this.checkLoginStatus();
|
||||
this.loadUserInfo();
|
||||
// 异步再次确认审核模式
|
||||
this.verifyAuditMode();
|
||||
@@ -195,18 +194,6 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
checkLoginStatus() {
|
||||
if (!isLoggedIn()) {
|
||||
wx.showToast({
|
||||
title: '请先登录',
|
||||
icon: 'none',
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateTo({ url: '/pages/login/index' });
|
||||
}, 1500);
|
||||
}
|
||||
},
|
||||
|
||||
async loadRecommendedTags() {
|
||||
try {
|
||||
const res = await getRecommendedTags({ showLoading: false });
|
||||
@@ -326,6 +313,22 @@ Page({
|
||||
async handleSubmit() {
|
||||
const { form, mode, activityId } = this.data;
|
||||
|
||||
// 提交属于需要身份的操作:游客可自由浏览表单,仅在提交时引导登录,可取消
|
||||
if (!isLoggedIn()) {
|
||||
const confirm = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '需要登录',
|
||||
content: '登录后即可发布活动,是否前往登录?',
|
||||
confirmText: '去登录',
|
||||
cancelText: '暂不登录',
|
||||
success: (res) => resolve(res.confirm),
|
||||
});
|
||||
});
|
||||
if (!confirm) return;
|
||||
wx.navigateTo({ url: '/pages/login/index' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证表单
|
||||
if (!form.title) {
|
||||
wx.showToast({ title: '请输入活动标题', icon: 'none' });
|
||||
|
||||
@@ -218,8 +218,18 @@ Page({
|
||||
|
||||
if (!activity) return;
|
||||
|
||||
// 未登录则跳转登录
|
||||
// 未登录:报名属于需要身份的操作,弹窗引导登录,可取消后继续浏览
|
||||
if (!this.data.isLoggedIn) {
|
||||
const confirm = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '需要登录',
|
||||
content: '登录后即可报名活动,是否前往登录?',
|
||||
confirmText: '去登录',
|
||||
cancelText: '暂不登录',
|
||||
success: (res) => resolve(res.confirm),
|
||||
});
|
||||
});
|
||||
if (!confirm) return;
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/index',
|
||||
});
|
||||
@@ -322,10 +332,8 @@ Page({
|
||||
return;
|
||||
}
|
||||
if (!this.data.isLoggedIn) {
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/index',
|
||||
});
|
||||
return;
|
||||
// 游客可浏览:不强制登录,仅提示后放行进入创建页面
|
||||
wx.showToast({ title: '登录后才能发布,可先浏览', icon: 'none', duration: 2000 });
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/create-activity/index',
|
||||
|
||||
@@ -121,19 +121,12 @@ const request = (url, method = 'GET', data = {}, options = {}) => {
|
||||
const transformedData = transformKeysToCamelCase(res.data);
|
||||
resolve(transformedData);
|
||||
} else if (res.statusCode === 401) {
|
||||
// 未授权,清除登录信息
|
||||
// 未授权:静默清除登录状态,不强制跳转登录页,由用户后续操作时自主选择登录
|
||||
app.clearLoginInfo();
|
||||
wx.removeStorageSync('token');
|
||||
wx.removeStorageSync('userId');
|
||||
wx.showToast({
|
||||
title: '登录已过期,请重新登录',
|
||||
icon: 'none',
|
||||
});
|
||||
// 跳转到登录页
|
||||
wx.redirectTo({
|
||||
url: '/pages/login/index',
|
||||
});
|
||||
reject({ message: '登录已过期' });
|
||||
wx.removeStorageSync('isLoggedIn');
|
||||
reject({ message: '登录已过期,请重新登录', silent: true });
|
||||
} else {
|
||||
if (showError) {
|
||||
wx.showToast({
|
||||
|
||||
Reference in New Issue
Block a user