样式优化

This commit is contained in:
ZaneYork 2024-09-20 15:48:58 +08:00
parent e3c9aacece
commit 6c77a4ba05
3 changed files with 143 additions and 102 deletions

View File

@ -7,10 +7,10 @@
{% endblock %} {% endblock %}
</head> </head>
<body> <body>
<div class="container text-center pt-5"> <div class="container-fluid text-center pt-5">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
<footer class="footer mt-auto py-3 bg-light"> <footer class="footer text-center mt-auto py-3 bg-light">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">

View File

@ -5,20 +5,18 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="pt-1 mb-3"> <div class="row">
<div class="row"> <div class="col-8">
<div class="col-8"> <select id="dateSelect" class="form-select" aria-label="日期选择">
<select id="dateSelect" class="form-select" aria-label="日期选择"> {% for recent_result in recent_results %}
{% for recent_result in recent_results %} <option value="{{ recent_result.datestr }}" {{ 'selected' if date==recent_result.datestr else '' }}>
<option value="{{ recent_result.datestr }}" {{ 'selected' if date==recent_result.datestr else '' }}> {{ recent_result.datestr }}
{{ recent_result.datestr }} </option>
</option> {% endfor %}
{% endfor %} </select>
</select> </div>
</div> <div class="col-4">
<div class="col-4"> <button type="button" class="btn btn-outline-secondary" onclick="back()">返回</button>
<button type="button" class="btn btn-outline-secondary" onclick="back()">返回</button>
</div>
</div> </div>
</div> </div>
<div id="main" style="width: 100%;height:400px;"></div> <div id="main" style="width: 100%;height:400px;"></div>

View File

@ -18,98 +18,141 @@
</div> </div>
<form id="inputForm" class="form-inline" onsubmit="return false;"> <form id="inputForm" class="form-inline" onsubmit="return false;">
<div class="form-group"> <div class="form-group">
<div class="mb-3"> <div class="accordion">
<div class="input-group"> <div class="accordion-item">
<label class="input-group-text" for="inputName" id="basic-addon1">姓名</label> <h2 class="accordion-header">
<input type="text" <button class="accordion-button" type="button" data-bs-toggle="collapse"
class="form-control" {{ 'readonly="readonly"' if user_menu.nickname else '' | safe }} data-bs-target="#collapseMyChoice" aria-expanded="true"
id="inputName" name="nickname" value="{{ user_menu.nickname }}"> aria-controls="collapseMyChoice">
</div> 我选择
</div> </button>
<div class="mb-2"> </h2>
<label class="input-group-addon">我选择</label> <div id="collapseMyChoice" class="accordion-collapse collapse show">
</div> <div class="accordion-body">
<div class="mb-3 row p-2"> <div class="mb-3">
{% for choice in all_choice %} <div class="input-group">
<div class="col-6 mb-1 p-1 border rounded {{ loop.cycle("rounded-end-0", "border-start-0 rounded-start-0") }}"> <label class="input-group-text" for="inputName" id="basic-addon1">姓名</label>
<div class="row"> <input type="text"
<label for="range{{ loop.index }}" class="col-12"> class="form-control" {{ 'readonly="readonly"' if user_menu.nickname else '' | safe }}
<span>{{ choice.label }} - </span> id="inputName" name="nickname" value="{{ user_menu.nickname }}">
<span class="percentage">{{ '{:.2f}'.format((user_menu.menu.get(choice.name) or 0) * 100) }}</span> </div>
<span>%</span>
</label>
</div>
<div class="d-flex justify-content-between">
<div class="col-8">
<input type="range" class="form-range" data-skip-falsy="true"
id="range{{ loop.index }}" name="choice[{{ choice.name }}]:number"
min="0" max="10" step="1"
value="{{ (user_menu.menu.get(choice.name) or 0) * 10 }}">
</div> </div>
<div class="col-4"> <div class="mb-3 row p-2">
<input class="form-check-input" type="checkbox" name="dislike[]" {% for choice in all_choice %}
id="checkDislike{{ loop.index }}" value="{{ choice.name }}" <div class="col-6 mb-1 p-1 border rounded {{ loop.cycle("rounded-end-0", "border-start-0 rounded-start-0") }}">
{{ 'checked' if choice.name in user_menu.dislike else '' }}> <div class="row">
<label class="form-check-label" for="checkDislike{{ loop.index }}"> <label for="range{{ loop.index }}"
不吃 class="col-12 d-flex justify-content-between align-items-center">
</label> <span>{{ choice.label }}</span>
<span class="percentage">{{ '{:.1f}'.format((user_menu.menu.get(choice.name) or 0) * 100) }}%</span>
</label>
</div>
<div class="d-flex justify-content-between">
<div class="col-sm-8 col-md-9 col-lg-10">
<input type="range" class="form-range" data-skip-falsy="true"
id="range{{ loop.index }}"
name="choice[{{ choice.name }}]:number"
min="0" max="10" step="1"
value="{{ (user_menu.menu.get(choice.name) or 0) * 10 }}">
</div>
<div class="col-auto">
<input class="form-check-input" type="checkbox" name="dislike[]"
id="checkDislike{{ loop.index }}" value="{{ choice.name }}"
{{ 'checked' if choice.name in user_menu.dislike else '' }}>
<label class="form-check-label" for="checkDislike{{ loop.index }}">
不吃
</label>
</div>
</div>
</div>
{% endfor %}
</div>
<button type="button" class="btn btn-outline-primary" onclick="update()">更新</button>
<button type="button" class="btn btn-outline-secondary" onclick="clearValue()">不吃</button>
<button type="button" id="btnRoll"
class="btn btn-outline-secondary" {{ "" if can_roll == True else ' disabled="disabled"' | safe }}
onclick="roll()">开始抽签
</button>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseAllChoice" aria-expanded="true"
aria-controls="collapseAllChoice">
大家的选择
</button>
</h2>
<div id="collapseAllChoice" class="accordion-collapse collapse show">
<div class="accordion-body">
<label class="d-flex justify-content-between">
总投票人数:{{ total_vote }}
</label>
<ul class="list-group pt-2 mb-4">
{% for key in summary_keys %}
<li class="list-group-item d-flex justify-content-between align-items-center{{ " active" if result == key else "" }} {{ " list-group-item-primary" if predict_result == key else "" }}">
<span class="col-5">{{ key }}</span>
<span class="col-3">{{ '{:.1f}'.format(summary[key] | round(2)) }}票</span>
<span class="col-3">{{ '{:.1f}'.format(summary[key] / total_vote * 100 | round(2)) }}%</span>
</li>
{% else %}
<li class="list-group-item">
<span>大家还没有选择</span>
</li>
{% endfor %}
</ul>
{% if (users|length) > 3 %}
<div class="pt-1 mb-3">
<label class="mb-2">参与投票人员</label>
<ul class="list-group list-group-horizontal">
{% for user in users %}
<li class="list-group-item">{{ user }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if ((users|length) > 3 or result) %}
<div class="pt-1 mb-3">
<label class="mb-2">{{ ('如果吃' + predict_result) if predict_result else '' }}就餐人员</label>
<ul class="list-group list-group-horizontal">
{% for user in eat_users %}
<li class="list-group-item">{{ user }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseRecentResult" aria-expanded="false"
aria-controls="collapseRecentResult">
最近点餐结果
</button>
</h2>
<div id="collapseRecentResult" class="accordion-collapse collapse">
<div class="accordion-body">
<div class="pt-1 mb-3">
<ul class="list-group">
{% for recent_result in recent_results %}
<li onclick="viewChart('{{ recent_result.datestr }}')"
class="list-group-item d-flex justify-content-between align-items-center">
<span>{{ recent_result.value }}</span>
<span>{{ recent_result.datestr }}</span>
</li>
{% endfor %}
</ul>
</div> </div>
</div> </div>
</div> </div>
{% endfor %} </div>
</div> </div>
</div> </div>
</form> </form>
<button type="button" class="btn btn-outline-primary" onclick="update()">更新</button>
<button type="button" class="btn btn-outline-secondary" onclick="clearValue()">不吃</button>
<button type="button" id="btnRoll"
class="btn btn-outline-secondary" {{ "" if can_roll == True else ' disabled="disabled"' | safe }}
onclick="roll()">开始抽签
</button>
<div class="pt-3">
<label>大家的选择 - 总投票人数:{{ total_vote }}</label>
<ul class="list-group pt-2 mb-4">
{% for key in summary_keys %}
<li class="list-group-item d-flex justify-content-between align-items-center{{ " active" if result == key else "" }} {{ " list-group-item-primary" if predict_result == key else "" }}">
<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>
</li>
{% endfor %}
</ul>
</div>
{% if (users|length) > 3 %}
<div class="pt-1 mb-3">
<label class="mb-2">参与投票人员</label>
<ul class="list-group list-group-horizontal">
{% for user in users %}
<li class="list-group-item">{{ user }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if ((users|length) > 3 or result) %}
<div class="pt-1 mb-3">
<label class="mb-2">{{ ('如果吃' + predict_result) if predict_result else '' }}就餐人员</label>
<ul class="list-group list-group-horizontal">
{% for user in eat_users %}
<li class="list-group-item">{{ user }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="pt-1 mb-3">
<label class="mb-2">最近点餐结果</label>
<ul class="list-group">
{% for recent_result in recent_results %}
<li onclick="viewChart('{{ recent_result.datestr }}')"
class="list-group-item d-flex justify-content-between align-items-center">
<span>{{ recent_result.value }}</span>
<span>{{ recent_result.datestr }}</span>
</li>
{% endfor %}
</ul>
</div>
{% endblock %} {% endblock %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
@ -130,7 +173,7 @@
const summary = values.reduce((a, b) => parseInt(a) + parseInt(b)); const summary = values.reduce((a, b) => parseInt(a) + parseInt(b));
const spans = $(".percentage") const spans = $(".percentage")
for (let i = 0; i < values.length; i++) { for (let i = 0; i < values.length; i++) {
spans[i].innerHTML = summary > 0 ? (parseFloat(values[i]) * 100 / summary).toFixed(2) : '0.00'; spans[i].innerHTML = (summary > 0 ? (parseFloat(values[i]) * 100 / summary).toFixed(1) : '0.0') + '%';
if (values[i] > 0 && checkBoxs[i].checked) { if (values[i] > 0 && checkBoxs[i].checked) {
checkBoxs[i].checked = false; checkBoxs[i].checked = false;
} }