fix: 修复游客/用户/管理员三态报名逻辑
- 游客态:首页卡片显示「报名活动」按钮,点击弹可取消登录引导;详情页 isJoined 不再被服务端 user-1 fallback 污染,底部正确显示「立即报名」 - 用户态:活动大厅(more-activities)补齐报名/取消/编辑按钮与处理器,报名状态真实切换并更新参与人数 - 管理员态:编辑入口三处(首页/大厅/详情页)统一 isAdmin 门禁,create-activity 编辑回填链路已验证 - checkin 页:游客进入显示 need_login 状态卡片(可自由返回),不再裸调签到接口
This commit is contained in:
@@ -75,8 +75,9 @@ Page({
|
||||
const userId = getUserId();
|
||||
this.setData({
|
||||
activity,
|
||||
isJoined: res.data.isJoined || false,
|
||||
isCreator: res.data.creatorId === userId,
|
||||
// 未登录时服务端会回退到默认用户导致 isJoined 污染,前端强制清零
|
||||
isJoined: isLoggedIn() ? (res.data.isJoined || false) : false,
|
||||
isCreator: !!userId && res.data.creatorId === userId,
|
||||
});
|
||||
// 加载AI建议
|
||||
this.loadAIRecommendation();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// pages/checkin/index.js
|
||||
const { getCheckinStatus, checkin } = require('../../api/activity');
|
||||
const { formatDateTime, formatDuration } = require('../../utils/helpers');
|
||||
const { isLoggedIn } = require('../../utils/auth');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
activityId: '',
|
||||
status: 'not_started', // not_started, can_checkin, expired, already_checked_in
|
||||
status: 'not_started', // need_login, not_started, can_checkin, expired, already_checked_in
|
||||
activity: null,
|
||||
checkinWindow: null,
|
||||
countdown: null,
|
||||
@@ -18,13 +19,28 @@ Page({
|
||||
const { id } = options;
|
||||
if (id) {
|
||||
this.setData({ activityId: id });
|
||||
// 签到需要身份:游客展示登录引导卡片,不自动弹窗、可自由返回
|
||||
if (!isLoggedIn()) {
|
||||
this.setData({ status: 'need_login' });
|
||||
return;
|
||||
}
|
||||
this.loadCheckinStatus();
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (this.data.activityId) {
|
||||
this.loadCheckinStatus();
|
||||
// 登录返回后重新进入正常签到流程
|
||||
if (!isLoggedIn()) {
|
||||
this.setData({ status: 'need_login' });
|
||||
return;
|
||||
}
|
||||
if (this.data.status !== 'need_login') {
|
||||
this.loadCheckinStatus();
|
||||
} else {
|
||||
this.setData({ status: 'not_started' });
|
||||
this.loadCheckinStatus();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -78,6 +94,13 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 跳转登录
|
||||
handleGoLogin() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/index',
|
||||
});
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '拆约 - 活动签到',
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
<view class="checkin-page">
|
||||
<!-- 需要登录(游客可自由返回,不强制弹窗) -->
|
||||
<view class="status-card" wx:if="{{status === 'need_login'}}">
|
||||
<view class="status-icon status-icon-blue">🔐</view>
|
||||
<text class="status-title">需要登录</text>
|
||||
<text class="status-desc">登录后即可查看签到状态并完成签到</text>
|
||||
<button
|
||||
class="checkin-btn"
|
||||
bindtap="handleGoLogin"
|
||||
>
|
||||
去登录
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 未开始 -->
|
||||
<view class="status-card" wx:if="{{status === 'not_started'}}">
|
||||
<view class="status-icon status-icon-gray">⏰</view>
|
||||
|
||||
@@ -183,6 +183,7 @@ Page({
|
||||
console.log('loadActivities 响应:', res);
|
||||
|
||||
if (res && res.success) {
|
||||
const loggedIn = isLoggedIn();
|
||||
const currentUserId = getUserId();
|
||||
const list = (res.data?.list || []).map((item) => {
|
||||
const status = getActivityStatus(item.startTime, item.duration || 1);
|
||||
@@ -191,8 +192,9 @@ Page({
|
||||
coverUrl: getFullImageUrl(item.coverUrl, true),
|
||||
startTimeFormatted: formatDateTime(item.startTime),
|
||||
isExpired: status === 'expired',
|
||||
isJoined: item.isJoined || false,
|
||||
isCreator: item.creatorId === currentUserId,
|
||||
// 未登录时服务端会回退到默认用户导致 isJoined 污染,前端强制清零
|
||||
isJoined: loggedIn ? (item.isJoined || false) : false,
|
||||
isCreator: loggedIn && item.creatorId === currentUserId,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -152,8 +152,8 @@
|
||||
<text class="participant-count">{{item.participantCount || 0}}</text>
|
||||
<text class="participant-text">人参与</text>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="activity-action" wx:if="{{!item.isExpired && isLoggedIn}}">
|
||||
<!-- 操作按钮(游客也显示,点击时引导登录) -->
|
||||
<view class="activity-action" wx:if="{{!item.isExpired}}">
|
||||
<view
|
||||
wx:if="{{item.isCreator}}"
|
||||
class="join-btn edit-btn"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// pages/more-activities/index.js
|
||||
const { getActivities } = require('../../api/activity');
|
||||
const { getFullImageUrl } = require('../../utils/helpers');
|
||||
const { getActivities, joinActivity, cancelJoin } = require('../../api/activity');
|
||||
const { getFullImageUrl, getActivityStatus } = require('../../utils/helpers');
|
||||
const { isLoggedIn, getUserId, getIsAdmin } = require('../../utils/auth');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -15,6 +16,9 @@ Page({
|
||||
pageSize: 10,
|
||||
// 标题
|
||||
title: '更多活动',
|
||||
// 登录与管理员状态
|
||||
isLoggedIn: false,
|
||||
isAdmin: false,
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
@@ -23,10 +27,12 @@ Page({
|
||||
this.setData({ currentTab: tab });
|
||||
this.updateTitle(tab);
|
||||
}
|
||||
this.setData({ isAdmin: getIsAdmin() });
|
||||
this.loadActivities();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.setData({ isAdmin: getIsAdmin() });
|
||||
this.loadActivities(true);
|
||||
},
|
||||
|
||||
@@ -79,9 +85,16 @@ Page({
|
||||
});
|
||||
|
||||
if (res.success) {
|
||||
const loggedIn = isLoggedIn();
|
||||
this.setData({ isLoggedIn: loggedIn });
|
||||
const currentUserId = getUserId();
|
||||
const list = (res.data.list || []).map((item) => ({
|
||||
...item,
|
||||
coverUrl: getFullImageUrl(item.coverUrl, refresh),
|
||||
isExpired: getActivityStatus(item.startTime, item.duration || 1) === 'expired',
|
||||
// 未登录时服务端会回退到默认用户导致 isJoined 污染,前端强制清零
|
||||
isJoined: loggedIn ? (item.isJoined || false) : false,
|
||||
isCreator: loggedIn && item.creatorId === currentUserId,
|
||||
}));
|
||||
|
||||
this.setData({
|
||||
@@ -108,6 +121,104 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
// 编辑活动(仅管理员)
|
||||
handleEditActivity(e) {
|
||||
if (!this.data.isAdmin) {
|
||||
wx.showToast({ title: '仅管理员可编辑活动', icon: 'none', duration: 2000 });
|
||||
return;
|
||||
}
|
||||
const { id } = e.currentTarget.dataset;
|
||||
wx.navigateTo({
|
||||
url: `/pages/create-activity/index?id=${id}&mode=edit`,
|
||||
});
|
||||
},
|
||||
|
||||
// 快速报名/取消报名
|
||||
async handleQuickJoin(e) {
|
||||
const { id } = e.currentTarget.dataset;
|
||||
const activity = this.data.activities.find(a => a.id === id);
|
||||
|
||||
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',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
wx.showLoading({ title: '处理中...', mask: true });
|
||||
|
||||
let res;
|
||||
if (activity.isJoined) {
|
||||
// 取消报名
|
||||
const confirm = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定要取消报名吗?',
|
||||
success: resolve,
|
||||
});
|
||||
});
|
||||
if (!confirm.confirm) {
|
||||
wx.hideLoading();
|
||||
return;
|
||||
}
|
||||
res = await cancelJoin(id);
|
||||
} else {
|
||||
// 报名
|
||||
res = await joinActivity(id);
|
||||
}
|
||||
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.success) {
|
||||
wx.showToast({
|
||||
title: activity.isJoined ? '已取消报名' : '报名成功',
|
||||
icon: 'success',
|
||||
});
|
||||
|
||||
// 更新活动列表中的报名状态
|
||||
const activities = this.data.activities.map(item => {
|
||||
if (item.id === id) {
|
||||
return {
|
||||
...item,
|
||||
isJoined: !activity.isJoined,
|
||||
participantCount: activity.isJoined
|
||||
? Math.max(0, (item.participantCount || 1) - 1)
|
||||
: (item.participantCount || 0) + 1
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
this.setData({ activities });
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res.message || '操作失败',
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: err.message || '操作失败',
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '拆约 - 拆书活动邀约平台',
|
||||
|
||||
@@ -41,6 +41,25 @@
|
||||
<text class="participant-count">{{item.participantCount || 0}}</text>
|
||||
<text class="participant-text">人参与</text>
|
||||
</view>
|
||||
<!-- 操作按钮(游客也显示,点击时引导登录) -->
|
||||
<view class="activity-action" wx:if="{{!item.isExpired}}">
|
||||
<view
|
||||
wx:if="{{item.isCreator}}"
|
||||
class="join-btn edit-btn"
|
||||
data-id="{{item.id}}"
|
||||
catchtap="handleEditActivity"
|
||||
>
|
||||
<text>编辑活动</text>
|
||||
</view>
|
||||
<view
|
||||
wx:else
|
||||
class="join-btn {{item.isJoined ? 'joined' : ''}}"
|
||||
data-id="{{item.id}}"
|
||||
catchtap="handleQuickJoin"
|
||||
>
|
||||
<text>{{item.isJoined ? '取消' : '报名活动'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -108,6 +108,32 @@
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
/* 活动操作按钮 */
|
||||
.activity-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.join-btn {
|
||||
padding: 12rpx 32rpx;
|
||||
background: linear-gradient(135deg, #4A90E2, #7AB3F0);
|
||||
border-radius: 32rpx;
|
||||
}
|
||||
|
||||
.join-btn text {
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.join-btn.joined {
|
||||
background: linear-gradient(135deg, #e53e3e, #fc8181);
|
||||
}
|
||||
|
||||
.join-btn.edit-btn {
|
||||
background: linear-gradient(135deg, #38a169, #68d391);
|
||||
}
|
||||
|
||||
/* 加载更多 */
|
||||
.load-more {
|
||||
text-align: center;
|
||||
|
||||
Reference in New Issue
Block a user