fix(core): comprehensive fix for state loss across activity, ticket, workspace, favorites and community
这个提交包含在:
@@ -80,8 +80,14 @@
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
<button v-else class="join-btn btn-active" @click="handleJoinParty(post)">
|
||||
{{ post.actionText || '聊一聊' }}
|
||||
<button
|
||||
v-else
|
||||
class="join-btn btn-active"
|
||||
:class="{ 'btn-applied': post.hasApplied }"
|
||||
:disabled="post.hasApplied"
|
||||
@click="handleJoinParty(post)"
|
||||
>
|
||||
{{ post.hasApplied ? '已申请' : (post.actionText || '聊一聊') }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -380,10 +386,18 @@ const loadRemotePosts = async () => {
|
||||
if (list && list.length > 0) {
|
||||
let localLikedIds = uni.getStorageSync('COMMUNITY_LIKED_POST_IDS') || [];
|
||||
if (!Array.isArray(localLikedIds)) localLikedIds = [];
|
||||
posts.value = list.map(item => ({
|
||||
...item,
|
||||
liked: item.liked !== undefined ? item.liked : localLikedIds.includes(String(item.id))
|
||||
}));
|
||||
let localAppliedIds = uni.getStorageSync('COMMUNITY_APPLIED_POST_IDS') || [];
|
||||
if (!Array.isArray(localAppliedIds)) localAppliedIds = [];
|
||||
|
||||
posts.value = list.map(item => {
|
||||
const isApplied = localAppliedIds.includes(String(item.id));
|
||||
return {
|
||||
...item,
|
||||
liked: item.liked !== undefined ? item.liked : localLikedIds.includes(String(item.id)),
|
||||
hasApplied: isApplied,
|
||||
actionText: isApplied ? '已申请' : (item.actionText || '加入车队')
|
||||
};
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[Community] 获取动态列表失败,保持本地列表:', err.message);
|
||||
@@ -416,20 +430,29 @@ const feedTabs = ref([
|
||||
|
||||
const currentTab = ref('all');
|
||||
|
||||
const syncInitialLikedState = (rawPosts) => {
|
||||
const syncInitialPostStates = (rawPosts) => {
|
||||
try {
|
||||
let localLikedIds = uni.getStorageSync('COMMUNITY_LIKED_POST_IDS') || [];
|
||||
if (!Array.isArray(localLikedIds) || localLikedIds.length === 0) return rawPosts;
|
||||
return rawPosts.map(p => ({
|
||||
...p,
|
||||
liked: localLikedIds.includes(String(p.id)) ? true : p.liked
|
||||
}));
|
||||
if (!Array.isArray(localLikedIds)) localLikedIds = [];
|
||||
let localAppliedIds = uni.getStorageSync('COMMUNITY_APPLIED_POST_IDS') || [];
|
||||
if (!Array.isArray(localAppliedIds)) localAppliedIds = [];
|
||||
|
||||
return rawPosts.map(p => {
|
||||
const isApplied = localAppliedIds.includes(String(p.id));
|
||||
return {
|
||||
...p,
|
||||
liked: localLikedIds.includes(String(p.id)) ? true : p.liked,
|
||||
hasApplied: isApplied,
|
||||
actionText: isApplied ? '已申请' : p.actionText
|
||||
};
|
||||
});
|
||||
} catch (_) {
|
||||
return rawPosts;
|
||||
}
|
||||
};
|
||||
const syncInitialLikedState = syncInitialPostStates;
|
||||
|
||||
const posts = ref(syncInitialLikedState([
|
||||
const posts = ref(syncInitialPostStates([
|
||||
{
|
||||
id: 1,
|
||||
author: '小甜橙',
|
||||
@@ -658,6 +681,13 @@ const handleDeletePost = (post) => {
|
||||
};
|
||||
|
||||
const handleJoinParty = (post) => {
|
||||
if (post.hasApplied) {
|
||||
uni.showToast({
|
||||
title: '已提交过约伴申请',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showModal({
|
||||
title: '搭子互动申请',
|
||||
content: `确定向【${post.author}】发起同城约伴 / 上车请求?`,
|
||||
@@ -666,24 +696,33 @@ const handleJoinParty = (post) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: '正在提交申请...' });
|
||||
const uid = Number(uni.getStorageSync('userId')) || 1001;
|
||||
const userInfo = uni.getStorageSync('userInfo') || {};
|
||||
const applicantName = userInfo.nickname || '搭子玩家';
|
||||
const applicantAvatar = userInfo.avatar || 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=120';
|
||||
try {
|
||||
await applyPostParty(post.id, {
|
||||
applicantId: 1001,
|
||||
applicantName: '电竞玩家 (我)',
|
||||
applicantAvatar: 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=120'
|
||||
});
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '申请已送达,等待房主确认!',
|
||||
icon: 'success'
|
||||
});
|
||||
} catch (_) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '申请已送达,等待房主确认!',
|
||||
icon: 'success'
|
||||
applicantId: uid,
|
||||
applicantName,
|
||||
applicantAvatar
|
||||
});
|
||||
} catch (_) {}
|
||||
|
||||
post.hasApplied = true;
|
||||
post.actionText = '已申请';
|
||||
let localAppliedIds = uni.getStorageSync('COMMUNITY_APPLIED_POST_IDS') || [];
|
||||
if (!Array.isArray(localAppliedIds)) localAppliedIds = [];
|
||||
const strId = String(post.id);
|
||||
if (!localAppliedIds.includes(strId)) {
|
||||
localAppliedIds.push(strId);
|
||||
uni.setStorageSync('COMMUNITY_APPLIED_POST_IDS', localAppliedIds);
|
||||
}
|
||||
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '申请已送达,等待房主确认!',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1212,6 +1251,13 @@ const submitPublishPost = async () => {
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
|
||||
&.btn-applied {
|
||||
background: rgba(148, 163, 184, 0.15);
|
||||
color: #94A3B8;
|
||||
border-color: rgba(148, 163, 184, 0.3);
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1769,6 +1815,12 @@ const submitPublishPost = async () => {
|
||||
background: rgba(234, 88, 12, 0.1);
|
||||
color: #EA580C;
|
||||
border-color: rgba(234, 88, 12, 0.3);
|
||||
|
||||
&.btn-applied {
|
||||
background: #F1F5F9;
|
||||
color: #94A3B8;
|
||||
border-color: #CBD5E1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户