fix: pk comment

This commit is contained in:
zzc
2026-06-15 19:59:07 +08:00
parent f256df8f94
commit 3c7e520062
4 changed files with 954 additions and 4 deletions

View File

@@ -79,7 +79,18 @@
</view>
</view>
<view v-else class="state-card">
<PkCommentSection
v-if="currentPair && hasVoted"
ref="commentSectionRef"
:pk-id="currentPair.id"
:current-pair="currentPair"
:selected-item-id="selectedItemId"
:selected-item-label="selectedItemLabel"
:visible="hasVoted"
@need-login="openLoginPopup('请先登录后再参与评论')"
/>
<view v-else-if="!currentPair" class="state-card">
<text class="state-title">暂时没有新的 PK 对局</text>
<text class="state-desc">当前没有可参与的随机对局稍后再来看看有没有新的组合</text>
<button class="state-btn" @tap="loadNextPair">重新获取</button>
@@ -96,6 +107,7 @@ import { onLoad, onPullDownRefresh, onShareAppMessage, onShareTimeline } from "@
import { getStatusBarHeight } from "@/utils/system";
import { fetchRandomTopicList, vote } from "@/api/pk";
import { FILE_BASE_URL } from "@/utils/constants";
import PkCommentSection from "@/components/PkCommentSection/PkCommentSection.vue";
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
import { useUserStore } from "@/stores/user";
import { getShareReward } from "@/api/system";
@@ -104,6 +116,7 @@ import { getShareToken } from "@/utils/common";
const userStore = useUserStore();
const statusBarHeight = ref(getStatusBarHeight() || 44);
const loginPopupRef = ref(null);
const commentSectionRef = ref(null);
const loading = ref(false);
const voting = ref(false);
const currentPair = ref(null);
@@ -112,6 +125,14 @@ const voteStats = ref({ leftPercent: 50, rightPercent: 50 });
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
const hasVoted = computed(() => !!selectedSide.value);
const selectedItemId = computed(() => {
if (!currentPair.value || !selectedSide.value) return "";
return selectedSide.value === "left" ? currentPair.value.left.id : currentPair.value.right.id;
});
const selectedItemLabel = computed(() => {
if (!currentPair.value || !selectedSide.value) return "";
return selectedSide.value === "left" ? currentPair.value.left.name : currentPair.value.right.name;
});
const buildAvatarUrl = (avatar) => {
if (!avatar) return "https://api.dicebear.com/7.x/avataaars/svg?seed=fallback";
@@ -269,7 +290,11 @@ const refreshPool = () => {
loadNextPair();
};
const handleLoginSuccess = () => {};
const handleLoginSuccess = async () => {
if (hasVoted.value) {
await commentSectionRef.value?.refreshComments?.();
}
};
onLoad(() => {
loadNextPair();