dinner_vote/templates/dinner.html

179 lines
7.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html lang="zh">
<head>
<title>晚餐吃什么鸭</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/bootstrap.min.css">
</head>
<body>
<div class="container text-center pt-5">
<p>每天8:00-17:30间开放匿名投票更新17:30以后允许发起抽签抽签结果确定后不可更改</p>
<p>第一名与第二名得票数相差不超过10%时随机抽签,按其得票数决定中签概率,否则选择第一名</p>
<p>投票结果仅供参考,最终解释权归部门总经理、副总经理所有</p>
{% for last_result in last_results %}
<p>今日{{ last_result }}最终得票数降低{{ 2 + loop.index0 }}0%</p>
{% endfor %}
<form id="inputForm" class="form-inline">
<div class="form-group">
<div class="input-group mb-3">
<label class="input-group-text" for="inputName" id="basic-addon1">姓名</label>
<input type="text" class="form-control"
id="inputName" name="nickname" value="{{ nickname }}">
</div>
<div class="input-group mb-2">
<span class="input-group-addon">我选择</span>
</div>
{% for choice in all_choice %}
<div class="input-group">
<label for="range{{ loop.index }}" class="form-label">
<span>{{ choice['label'] }} - </span>
<span class="percentage">{{ '{:.2f}'.format((menu.get(choice['name']) or 0) * 100) }}</span>%
</label>
<input type="range" class="form-range"
id="range{{ loop.index }}" name="{{ choice['name'] }}"
min="0" max="10" step="1"
value="{{ (menu.get(choice['name']) or 0) * 10 }}">
</div>
{% endfor %}
</div>
</form>
<button type="button" class="btn btn-primary" onclick="update()">更新</button>
<button type="button" class="btn btn-secondary" onclick="clearValue()">不吃</button>
<button type="button" id="btnRoll"
class="btn btn-secondary{{ "" if can_roll == True else ' disabled="disabled"' | safe }}"
onclick="roll()">开始抽签
</button>
<div class="pt-3">
<label>大家的选择 - 总票数:{{ '{:.2f}'.format(total_vote | round(2)) }}</label>
<ul class="list-group pt-2 mb-4">
{% for key in summary_keys %}
<li class="list-group-item{{ " active" if result == key else "" }} {{ " list-group-item-primary" if predict_result == key else "" }}">
<div class="row justify-content-between">
<span class="col-5">{{ key }}</span>
<span class="col-3">{{ '{:.2f}'.format(summary[key] | round(2)) }}票</span>
<span class="col-3">{{ '{:.2f}'.format(summary[key] / total_vote * 100 | round(2)) }}%</span>
</div>
</li>
{% endfor %}
</ul>
</div>
{% if (users|length) > 3 %}
<div class="pt-1 mb-3">
<label>参与投票人员</label>
<ul class="list-group list-group-horizontal">
{% for user in users %}
<li class="list-group-item">{{ user }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<div class="row">
<div class="col-12">
<a class="link-secondary link-offset-2"
href="https://git.zaneyork.cn:8443/ZaneYork/dinner_vote">本项目抽签完全公开透明,源码开放欢迎随时审查</a>
</div>
</div>
<div class="row">
<div class="col-12">
<span style="font-size: 0.7rem">Copyright © <script>document.write(new Date().getFullYear().toString())</script> Zane York. All Rights Reserved.</span>
</div>
</div>
</div>
</footer>
</div>
<script src="/static/jquery-3.2.1.min.js"></script>
<script src="/static/jquery.serializejson.js"></script>
<script src="/static/bootstrap.bundle.min.js"></script>
<!--suppress JSUnresolvedReference -->
<script>
document.addEventListener('keydown', function (event) {
if (event.key === 'Enter' || event.keyCode === 13) {
update();
}
});
$("input[type=range]").change(function () {
const values = $("input[type=range]").map(function () {
return $(this).val();
}).get();
const summary = values.reduce((a, b) => parseInt(a) + parseInt(b));
const spans = $(".percentage")
for (let i = 0; i < values.length; i++) {
spans[i].innerHTML = summary > 0 ? (parseFloat(values[i]) * 100 / summary).toFixed(2) : 0;
}
});
function update() {
const data = $('#inputForm').serializeJSON();
const nickname = data.nickname;
data.nickname = undefined;
$.ajax({
url: 'dinner/update?nickname=' + nickname + '&value=' + JSON.stringify(data),
dataType: 'json',
success: function (result) {
if (result.code === 0) {
window.location.reload();
} else {
alert('更新失败: ' + result.data)
}
}
})
}
function clearValue() {
$.ajax({
url: 'dinner/update?value=',
dataType: 'json',
success: function (result) {
if (result.code === 0) {
window.location.reload();
} else {
alert('更新失败: ' + result.data)
}
}
})
}
function roll() {
$.ajax({
url: 'dinner/roll',
dataType: 'json',
success: function (result) {
if (result.code === 0) {
window.location.reload();
} else {
alert('更新失败: ' + result.data)
}
}
})
}
$(function () {
const counterId = window.setInterval(counter, 1000);
function counter() {
const now = new Date();
const targetTime = new Date(
now.getFullYear(), now.getMonth(), now.getDate(),
17, 30, 0, 0
);
const diff = targetTime - now;
const btn = $("#btnRoll");
if (diff <= 0) {
window.clearInterval(counterId);
btn.text('开始抽签');
btn.attr('disabled', null)
return;
}
// Convert diff to hours, minutes, and seconds
const hours = Math.floor(diff / (1000 * 60 * 60)).toString().padStart(2, '0');
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)).toString().padStart(2, '0');
const seconds = Math.floor((diff % (1000 * 60)) / 1000).toString().padStart(2, '0');
btn.text(hours + ':' + minutes + ':' + seconds)
}
});
</script>
</body>
</html>