Skip to content

Commit 3ae459c

Browse files
committed
【博客端】优化:为投票选项添加最多投票标识,并调整相关样式
1 parent b80bfe6 commit 3ae459c

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

blog/components/VoteItem.vue

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
<div>
2828
<div class="mb-3" v-for="option in itemCom.options" :key="option._id">
2929
<div
30-
class="flex justify-between items-center rounded-md border border-solid border-gray-300 dark:border-gray-600 hover:border-primary/80 dark:hover:border-primary/80 transition-colors cursor-pointer vote-item-option"
30+
class="flex justify-between items-center rounded-md border border-solid border-gray-300 dark:border-gray-600 transition-all cursor-pointer vote-item-option"
3131
:class="{
3232
disabled: btnDisabled,
3333
active: optionIdList.includes(option._id),
34+
'max-vote': maxVoteIdList.includes(option._id),
3435
}"
3536
@click="handleSelect(option)"
3637
>
@@ -121,6 +122,28 @@ const itemCom = computed(() => {
121122
}
122123
})
123124
125+
// 投票最多的选项list
126+
const maxVoteIdList = computed(() => {
127+
if (!itemCom.value?.options || itemCom.value.options.length === 0) {
128+
return []
129+
}
130+
if (!itemCom.value?.votes || itemCom.value.votes <= 0) {
131+
return []
132+
}
133+
let maxVoteCount = -1
134+
let ids = []
135+
for (const option of itemCom.value.options) {
136+
const votes = option.votes || 0
137+
if (votes > maxVoteCount) {
138+
maxVoteCount = votes
139+
ids = [option._id]
140+
} else if (votes === maxVoteCount) {
141+
ids.push(option._id)
142+
}
143+
}
144+
return ids
145+
})
146+
124147
const voted = ref(false)
125148
const isExpired = ref(false)
126149
const bothIP = ref(false)
@@ -274,24 +297,39 @@ onUnmounted(() => {
274297
line-height: 1.25rem;
275298
padding: 0.4rem 0.5rem;
276299
}
300+
.vote-item-option:not(.disabled):hover {
301+
@apply border-primary-400 dark:border-primary-400;
302+
}
303+
:deep(.vote-item-option:not(.disabled):hover input[type='checkbox']) {
304+
@apply border-primary-400 dark:border-primary-400;
305+
}
277306
.vote-item-option.active {
278-
@apply border-primary-400 text-primary-500 dark:text-primary-400;
307+
@apply text-primary-500 dark:text-primary-400;
279308
}
280309
.vote-item-option.disabled {
281-
@apply cursor-default hover:border-gray-300 dark:hover:border-gray-600;
310+
@apply cursor-default;
282311
}
283-
.vote-item-option.active.disabled {
312+
.vote-item-option.disabled:hover {
313+
@apply border-gray-300 dark:border-gray-600;
314+
}
315+
/* .vote-item-option.active.disabled {
284316
@apply hover:border-primary-400 dark:hover:border-primary-400;
317+
} */
318+
.vote-item-option.max-vote {
319+
@apply border-primary-400 text-primary-500 dark:text-primary-400;
320+
}
321+
.vote-item-option.max-vote.disabled {
322+
@apply border-primary-400 dark:border-primary-400 text-primary-500 dark:text-primary-400;
285323
}
286324
.vote-item-option-votes {
287325
font-size: 0.75rem;
288326
white-space: nowrap;
289327
min-width: 6.2rem;
290328
text-align: right;
291329
}
292-
.vote-item-option.active .vote-item-option-votes {
330+
/* .vote-item-option.active .vote-item-option-votes {
293331
@apply text-primary-500 dark:text-primary-400;
294-
}
332+
} */
295333
.vote-item-option-votes {
296334
text-align: right;
297335
}
@@ -314,7 +352,10 @@ onUnmounted(() => {
314352
border-radius: 0.1rem;
315353
transition: width 0.3s;
316354
}
317-
.vote-item-option.active .vote-item-option-bar-inner {
355+
/* .vote-item-option.active .vote-item-option-bar-inner {
356+
@apply bg-primary-400/20;
357+
} */
358+
.vote-item-option.max-vote .vote-item-option-bar-inner {
318359
@apply bg-primary-400/20;
319360
}
320361
.vote-item-option-title,

0 commit comments

Comments
 (0)