fix: no revote, blind result after voting, admin 1.5 vote weight
This commit is contained in:
@@ -23,20 +23,22 @@ const PollsPage = {
|
||||
renderPoll(p) {
|
||||
const opts = p.options || [];
|
||||
const max = Math.max(1, ...Object.values(p.votes || {}));
|
||||
const showResult = Auth.isOwner() || !p.voted;
|
||||
return `<div class="card" id="poll-${p.id}">
|
||||
<div class="card-h"><span>${U.esc(p.title)}</span><span class="ts tm">${p.total||0} 票</span></div>
|
||||
<div class="card-b">
|
||||
${p.description?`<p class="tm mb-4">${U.esc(p.description)}</p>`:''}
|
||||
${p.voted && !showResult ? `<div class="alert alert-s"><i class="fas fa-check-circle"></i> 已投票,结果仅在投票结束后向服主公开</div>` : ''}
|
||||
<div style="display:flex;flex-direction:column;gap:8px">
|
||||
${opts.map((o,i) => {
|
||||
const v = p.votes?.[i] || 0;
|
||||
const pct = p.total ? Math.round(v/p.total*100) : 0;
|
||||
const v = showResult ? (p.votes?.[i] || 0) : 0;
|
||||
const pct = showResult && p.total ? Math.round(v/p.total*100) : 0;
|
||||
const my = p.my_vote === i;
|
||||
return `<div class="poll-opt" style="position:relative;overflow:hidden;border:1px solid var(--g200);border-radius:var(--r);cursor:pointer" data-poll="${p.id}" data-idx="${i}">
|
||||
<div style="position:absolute;top:0;left:0;bottom:0;width:${pct}%;background:${my?'var(--pl)':'var(--g2)'};transition:width .3s;z-index:0"></div>
|
||||
return `<div class="poll-opt" style="position:relative;overflow:hidden;border:1px solid var(--g200);border-radius:var(--r);${p.voted?'cursor:default':'cursor:pointer'}" data-poll="${p.id}" data-idx="${i}">
|
||||
${showResult ? `<div style="position:absolute;top:0;left:0;bottom:0;width:${pct}%;background:${my?'var(--pl)':'var(--g2)'};transition:width .3s;z-index:0"></div>` : ''}
|
||||
<div style="position:relative;z-index:1;display:flex;justify-content:space-between;align-items:center;padding:10px 14px;font-size:13px">
|
||||
<span>${my?'<i class="fas fa-check" style="color:var(--p)"></i> ':''}${U.esc(o)}</span>
|
||||
<span class="fb">${v}票 ${pct}%</span>
|
||||
${showResult ? `<span class="fb">${v}票 ${pct}%</span>` : ''}
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('')}
|
||||
@@ -46,6 +48,7 @@ const PollsPage = {
|
||||
},
|
||||
|
||||
bindVote(p) {
|
||||
if (p.voted) return;
|
||||
const card = document.getElementById('poll-'+p.id);
|
||||
if (!card) return;
|
||||
card.querySelectorAll('.poll-opt').forEach(el => {
|
||||
|
||||
Reference in New Issue
Block a user