From 1853e653fb7cbdf182452223e581afa2dbff2d37 Mon Sep 17 00:00:00 2001 From: xcbyy <2578898740@qq.com> Date: Tue, 13 Oct 2026 16:01:19 +0800 Subject: [PATCH] fix(core): comprehensive fix for state loss across activity, ticket, workspace, favorites and community --- pwuniapp/common/api.js | 43 +++++++---- pwuniapp/pages/activity/detail.vue | 30 +++++--- pwuniapp/pages/activity/my-ticket.vue | 33 ++++++-- pwuniapp/pages/community/index.vue | 106 +++++++++++++++++++------- pwuniapp/pages/expert/detail.vue | 18 ++++- pwuniapp/pages/expert/workspace.vue | 4 +- server/tests/content-security.spec.ts | 69 +++++++++++++++++ 7 files changed, 242 insertions(+), 61 deletions(-) diff --git a/pwuniapp/common/api.js b/pwuniapp/common/api.js index 23a8a07..7712c96 100644 --- a/pwuniapp/common/api.js +++ b/pwuniapp/common/api.js @@ -169,9 +169,10 @@ export async function leaveActivity(activityId, userId = 2001) { /** * 获取“我的组局”(发起的 + 报名的) */ -export async function getMyActivities(userId = 1001) { +export async function getMyActivities(userId) { + const uid = normalizeUserId(userId); try { - const res = await http.get(`/users/${userId}/my-activities`); + const res = await http.get(`/users/${uid}/my-activities`); if (res) { return { created: (res.created || []).map(formatActivityData), @@ -477,7 +478,13 @@ export async function likePost(id, action, userId) { * 规范化用户ID,自动兼容历史测试账号映射 (将虚拟陪伴师 101 映射至真实用户 2006) */ function normalizeUserId(uid) { - const n = Number(uid); + let target = uid; + if (!target && target !== 0) { + try { + target = uni.getStorageSync('userId'); + } catch (_) {} + } + const n = Number(target); if (n === 101) return 2006; return (!isNaN(n) && n > 0) ? n : 1001; } @@ -952,9 +959,10 @@ export async function updateExpertServiceStatus(expertId = 101, serviceId, statu /** * 获取用户收藏的陪玩列表 */ -export async function getFavorites(userId = 1001) { +export async function getFavorites(userId) { + const uid = normalizeUserId(userId); try { - const res = await http.get(`/favorites?userId=${userId}`); + const res = await http.get(`/favorites?userId=${uid}`); return res || []; } catch (err) { console.warn('[API] 获取收藏列表异常:', err.message); @@ -965,9 +973,10 @@ export async function getFavorites(userId = 1001) { /** * 探测是否已收藏特定陪玩 */ -export async function checkFavorite(expertId, userId = 1001) { +export async function checkFavorite(expertId, userId) { + const uid = normalizeUserId(userId); try { - const res = await http.get(`/favorites/check?userId=${userId}&expertId=${expertId}`); + const res = await http.get(`/favorites/check?userId=${uid}&expertId=${expertId}`); return res && res.isFavorite; } catch (err) { console.warn('[API] 探测收藏状态异常:', err.message); @@ -978,9 +987,10 @@ export async function checkFavorite(expertId, userId = 1001) { /** * 添加收藏 */ -export async function addFavorite(expertId, userId = 1001) { +export async function addFavorite(expertId, userId) { + const uid = normalizeUserId(userId); try { - const res = await http.post('/favorites', { userId, expertId }); + const res = await http.post('/favorites', { userId: uid, expertId }); return res; } catch (err) { console.warn('[API] 添加收藏异常:', err.message); @@ -991,9 +1001,10 @@ export async function addFavorite(expertId, userId = 1001) { /** * 取消收藏 */ -export async function removeFavorite(expertId, userId = 1001) { +export async function removeFavorite(expertId, userId) { + const uid = normalizeUserId(userId); try { - const res = await http.delete(`/favorites/${expertId}?userId=${userId}`); + const res = await http.delete(`/favorites/${expertId}?userId=${uid}`); return res; } catch (err) { console.warn('[API] 取消收藏异常:', err.message); @@ -1004,9 +1015,10 @@ export async function removeFavorite(expertId, userId = 1001) { /** * 获取分销团队列表 (一级与二级成员) */ -export async function getDistributionTeam(userId = 1001) { +export async function getDistributionTeam(userId) { + const uid = normalizeUserId(userId); try { - const res = await http.get(`/distribution/team?userId=${userId}`); + const res = await http.get(`/distribution/team?userId=${uid}`); return res || { directCount: 0, indirectCount: 0, totalTeamCount: 0, directList: [], indirectList: [] }; } catch (err) { console.warn('[API] 获取分销团队异常:', err.message); @@ -1017,9 +1029,10 @@ export async function getDistributionTeam(userId = 1001) { /** * 获取分销返佣订单记录 */ -export async function getDistributionRecords(userId = 1001) { +export async function getDistributionRecords(userId) { + const uid = normalizeUserId(userId); try { - const res = await http.get(`/distribution/records?userId=${userId}`); + const res = await http.get(`/distribution/records?userId=${uid}`); return res || []; } catch (err) { console.warn('[API] 获取分销返佣记录异常:', err.message); diff --git a/pwuniapp/pages/activity/detail.vue b/pwuniapp/pages/activity/detail.vue index c9bc73b..c6b47ad 100644 --- a/pwuniapp/pages/activity/detail.vue +++ b/pwuniapp/pages/activity/detail.vue @@ -137,12 +137,12 @@ 满员即成局 - + {{ p.nickname }} - 我的席位 + 我的席位 出价: ¥{{ p.priceAtJoin }} @@ -158,7 +158,7 @@ {{ p.checkedIn ? '已核销到场' : '待现场核销' }} - + 退席 @@ -384,18 +384,26 @@ import { import { ICONS } from '@/common/icons.js'; import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js'; -const CURRENT_USER_ID = 1001; +const currentUserId = computed(() => { + try { + return Number(uni.getStorageSync('userId')) || 1001; + } catch (_) { + return 1001; + } +}); +const currentActId = ref('1'); const verifyCodeInput = ref(''); const currentThemeKey = ref(getCurrentThemeKey()); const isHost = computed(() => { if (!activity.value) return false; - return Number(activity.value.creatorId) === CURRENT_USER_ID; + return Number(activity.value.creatorId) === currentUserId.value; }); const myParticipantInfo = computed(() => { if (!activity.value || !activity.value.participants) return null; - return activity.value.participants.find(p => Number(p.userId) === CURRENT_USER_ID || Number(p.id) === CURRENT_USER_ID); + const uid = currentUserId.value; + return activity.value.participants.find(p => Number(p.userId) === uid || Number(p.id) === uid); }); const isJoined = computed(() => !!myParticipantInfo.value); @@ -421,6 +429,9 @@ onMounted(() => { onShow(() => { currentThemeKey.value = getCurrentThemeKey(); applyThemeToNativeUI(currentThemeKey.value); + if (currentActId.value) { + loadLiveDetail(currentActId.value); + } }); onUnmounted(() => { @@ -458,6 +469,7 @@ const loadLiveDetail = async (id) => { onLoad((query) => { const targetId = (query && query.id) ? query.id : '1'; + currentActId.value = targetId; loadLiveDetail(targetId); }); @@ -639,7 +651,7 @@ const handleHostVerify = async () => { } try { uni.showLoading({ title: '正在核销签到...' }); - await verifyActivityCheckin(activity.value.id, code, CURRENT_USER_ID); + await verifyActivityCheckin(activity.value.id, code, currentUserId.value); uni.hideLoading(); verifyCodeInput.value = ''; uni.showToast({ title: '核销成功!搭子已签到', icon: 'success' }); @@ -675,7 +687,7 @@ const handleHostCancel = () => { if (res.confirm) { try { uni.showLoading({ title: '正在解散并全额退款...' }); - await cancelActivity(activity.value.id, CURRENT_USER_ID, '局长主动解散组局'); + await cancelActivity(activity.value.id, currentUserId.value, '局长主动解散组局'); uni.hideLoading(); uni.showToast({ title: '组局已成功解散', icon: 'success' }); activity.value.status = 'CANCELLED'; @@ -703,7 +715,7 @@ const handleLeave = () => { if (res.confirm) { try { uni.showLoading({ title: '正在办理退席...' }); - await leaveActivity(activity.value.id, CURRENT_USER_ID); + await leaveActivity(activity.value.id, currentUserId.value); uni.hideLoading(); uni.showToast({ title: '已退席,款项已退回钱包', icon: 'success' }); loadLiveDetail(activity.value.id); diff --git a/pwuniapp/pages/activity/my-ticket.vue b/pwuniapp/pages/activity/my-ticket.vue index 0fd85e3..0f6cd50 100644 --- a/pwuniapp/pages/activity/my-ticket.vue +++ b/pwuniapp/pages/activity/my-ticket.vue @@ -121,7 +121,7 @@