fix(core): comprehensive fix for state loss across activity, ticket, workspace, favorites and community

这个提交包含在:
xcbyy
2026-10-13 16:01:19 +08:00
父节点 497fb65359
当前提交 1853e653fb
共有 7 个文件被更改,包括 242 次插入 和 61 次删除

查看文件

@@ -121,7 +121,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { getActivityDetail, verifyActivityCheckin, getMyActivities, leaveActivity } from '@/common/api.js';
import { encodeCode128B } from '@/common/barcode.js';
import { generateQRCodeMatrix } from '@/common/qrcode.js';
@@ -140,6 +140,14 @@ const isCheckedIn = ref(false);
const currentTime = ref('');
const hasTicket = ref(true);
const currentUserId = computed(() => {
try {
return Number(uni.getStorageSync('userId')) || 1001;
} catch (_) {
return 1001;
}
});
const ticketSn = computed(() => {
const actId = ticketData.value && ticketData.value.id ? ticketData.value.id : '101';
return `TICKET-${actId}-${verifyCode.value}`;
@@ -170,7 +178,9 @@ const updateTime = () => {
currentTime.value = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
};
onLoad(async (query) => {
let savedQuery = null;
const loadTicketData = async (query = savedQuery) => {
if (query && query.code) {
verifyCode.value = String(query.code);
}
@@ -199,17 +209,18 @@ onLoad(async (query) => {
// 2. 若无传参,真实拉取当前用户的已报名组局列表
try {
const myActs = await getMyActivities(1001);
const uid = currentUserId.value;
const myActs = await getMyActivities(uid);
const joinedList = myActs.joined || [];
if (joinedList.length > 0) {
let targetAct = joinedList.find(act => {
const myP = (act.participants || []).find(p => p.userId === 1001 || p.nickname === '同城局长' || p.verifyCode);
const myP = (act.participants || []).find(p => Number(p.userId) === uid || p.nickname === '同城局长' || p.verifyCode);
return myP && !myP.checkedIn;
}) || joinedList[0];
ticketData.value = targetAct;
if (targetAct.participants && targetAct.participants.length > 0) {
const myP = targetAct.participants.find(p => p.userId === 1001 || p.verifyCode);
const myP = targetAct.participants.find(p => Number(p.userId) === uid || p.verifyCode);
if (myP && myP.verifyCode) {
verifyCode.value = String(myP.verifyCode);
isCheckedIn.value = Boolean(myP.checkedIn);
@@ -235,8 +246,16 @@ onLoad(async (query) => {
}
}
} catch (_) {}
};
onLoad(async (query) => {
savedQuery = query;
await loadTicketData(query);
});
onShow(async () => {
await loadTicketData();
});
onMounted(() => {
updateTime();
@@ -251,7 +270,7 @@ const toggleCheckIn = async () => {
if (!isCheckedIn.value) {
try {
uni.showLoading({ title: '正在核销签到...' });
await verifyActivityCheckin(ticketData.value.id, verifyCode.value, 1001);
await verifyActivityCheckin(ticketData.value.id, verifyCode.value, currentUserId.value);
uni.hideLoading();
isCheckedIn.value = true;
uni.showToast({
@@ -291,7 +310,7 @@ const handleCancelTicket = () => {
try {
uni.showLoading({ title: '正在办理退票...' });
const actId = ticketData.value && ticketData.value.id ? ticketData.value.id : 'act_101';
await leaveActivity(actId, 1001);
await leaveActivity(actId, currentUserId.value);
uni.hideLoading();
uni.showToast({ title: '退票成功,款项已退回钱包', icon: 'success' });
setTimeout(() => {