-
+
{{ poll.question }}
+
+
+
{{ opt }}
+
+
+
+ {{ pollPercentages[idx] }}% ({{ pollVotes[idx] || 0 }})
+
+
+
+
+
+
+
-
100
+
{{ pollParticipants.length }}
投票人
@@ -373,6 +399,7 @@ const hasJoined = computed(() => {
return lotteryParticipants.value.some((p) => p.id === Number(authState.userId))
})
const pollParticipants = computed(() => poll.value?.participants || [])
+const pollOptionParticipants = computed(() => poll.value?.optionParticipants || {})
const pollVotes = computed(() => poll.value?.votes || {})
const totalPollVotes = computed(() => Object.values(pollVotes.value).reduce((a, b) => a + b, 0))
const pollPercentages = computed(() =>
@@ -391,6 +418,9 @@ const hasVoted = computed(() => {
if (!loggedIn.value) return false
return pollParticipants.value.some((p) => p.id === Number(authState.userId))
})
+watch([hasVoted, pollEnded], ([voted, ended]) => {
+ if (voted || ended) showPollResult.value = true
+})
const currentEndTime = computed(() => {
if (lottery.value && lottery.value.endTime) return lottery.value.endTime
if (poll.value && poll.value.endTime) return poll.value.endTime
@@ -908,6 +938,7 @@ const voteOption = async (idx) => {
if (res.ok) {
toast.success('投票成功')
await refreshPost()
+ showPollResult.value = true
} else {
toast.error(data.error || '操作失败')
}
@@ -1293,6 +1324,11 @@ onMounted(async () => {
align-items: center;
}
+.poll-option-result {
+ margin-bottom: 10px;
+ margin-right: 10px;
+}
+
.poll-option-input {
margin-right: 10px;
width: 18px;