Files
gongshi_kanban/templates/project.html
T

174 lines
6.9 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>{{ project.title }}</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f5f7fa; color: #222; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.card { background: #fff; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.06); padding: 14px; margin-bottom: 12px; }
h1 { margin: 0; font-size: 20px; }
.toolbar { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 12px; }
label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
input { width: 100%; border: 1px solid #d9d9d9; border-radius: 8px; padding: 10px; }
button { border: none; border-radius: 8px; background: #1677ff; color: #fff; padding: 10px 14px; cursor: pointer; }
.meta { font-size: 13px; color: #666; margin-top: 8px; line-height: 1.7; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #f0f0f0; padding: 10px 8px; text-align: left; font-size: 14px; }
th { color: #555; font-weight: 600; background: #fafafa; }
tr.current-user { border: 2px solid #52c41a; }
tr.current-user td { background: #f6ffed; }
.tag { display: inline-block; font-size: 12px; color: #237804; border: 1px solid #95de64; background: #f6ffed; border-radius: 999px; padding: 2px 8px; }
.empty { color: #999; font-size: 14px; padding: 16px 0; }
.ok-tip { color: #237804; font-size: 13px; margin-top: 8px; }
.muted { color: #888; }
.back-link { display:inline-block; margin-bottom:8px; color:#1677ff; text-decoration:none; font-size:13px; }
.project-subtitle { font-size:13px; color:#666; margin-top:8px; line-height:1.7; }
</style>
</head>
<body>
<div class="wrap">
<div class="card">
<a class="back-link" href="/{% if user_uuid %}?uuid={{ user_uuid|urlencode }}{% endif %}">返回主页</a>
<h1>{{ project.title }}</h1>
<div class="project-subtitle">{{ project.subtitle }}</div>
<div class="toolbar">
<div>
<label for="dateInput">选择日期</label>
<input id="dateInput" type="date" value="{{ today }}">
</div>
<div>
<label for="uuidInput">用户 UUID(从页面链接自动带入)</label>
<input id="uuidInput" value="{{ user_uuid }}" placeholder="可手动输入查询定位">
</div>
<div style="display:flex; align-items:flex-end;">
<button id="queryBtn" type="button">查询</button>
</div>
</div>
<div class="meta" id="metaText">-</div>
<div class="ok-tip" id="userTip"></div>
</div>
<div class="card">
<table>
<thead>
<tr>
<th style="width: 52px;">序号</th>
<th>workid</th>
{% if project.get('query_sql_list') %}
{% for b in project.get('query_sql_list') %}
<th style="width: 100px;">{{ b.get('label') or b.get('key', '') }}</th>
{% endfor %}
<th style="width: 110px;">总量</th>
{% else %}
<th style="width: 120px;">完成量</th>
{% endif %}
<th style="width: 120px;">标记</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
<div class="empty" id="emptyText" style="display:none;">当前日期暂无数据</div>
</div>
</div>
<script>
function $(id) { return document.getElementById(id); }
function getQueryParam(name) {
try {
var usp = new URLSearchParams(window.location.search || '');
return String(usp.get(name) || '').trim();
} catch (e) {
return '';
}
}
function renderRows(rows, breakdowns) {
var tb = $('tableBody');
var empty = $('emptyText');
tb.innerHTML = '';
if (!rows || !rows.length) {
empty.style.display = 'block';
return false;
}
empty.style.display = 'none';
var hasCurrentUserRow = false;
breakdowns = breakdowns || [];
rows.forEach(function(row, idx) {
var tr = document.createElement('tr');
if (row.is_current_user) {
tr.className = 'current-user';
tr.id = 'currentUserRow';
hasCurrentUserRow = true;
}
var mark = row.is_current_user ? '<span class="tag">当前用户</span>' : '<span class="muted">-</span>';
var cells = '<td>' + (idx + 1) + '</td>' + '<td>' + (row.workid || '') + '</td>';
if (breakdowns.length) {
breakdowns.forEach(function(b) {
cells += '<td>' + (row['count_' + b.key] || 0) + '</td>';
});
cells += '<td>' + (row.count || 0) + '</td>';
} else {
cells += '<td>' + (row.count || 0) + '</td>';
}
cells += '<td>' + mark + '</td>';
tr.innerHTML = cells;
tb.appendChild(tr);
});
return hasCurrentUserRow;
}
async function queryData() {
var dateVal = String(($('dateInput').value || '')).trim();
var uuidVal = String(($('uuidInput').value || '')).trim();
var meta = $('metaText');
var tip = $('userTip');
tip.textContent = '';
meta.textContent = '查询中...';
try {
var qs = new URLSearchParams();
if (dateVal) { qs.set('date', dateVal); }
if (uuidVal) { qs.set('uuid', uuidVal); }
var resp = await fetch('/api/project/{{ project_key }}/stats?' + qs.toString(), { method: 'GET' });
var data = await resp.json();
if (!data || !data.success) {
meta.textContent = '查询失败:' + ((data && data.error) ? data.error : '未知错误');
renderRows([]);
return;
}
meta.textContent = '日期:' + data.date + ',总人数:' + data.total + ',总完成量:' + data.sum_count;
var hasCurrentUserRow = renderRows(data.rows || [], data.breakdowns || []);
if (uuidVal) {
if (data.has_current_user) {
tip.textContent = '已定位到你的数据,绿色高亮行即当前登录 UUID 的统计。';
if (hasCurrentUserRow) {
var targetRow = $('currentUserRow');
if (targetRow && typeof targetRow.scrollIntoView === 'function') {
targetRow.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
} else {
tip.textContent = '未匹配到当前 UUID 的数据。';
}
}
} catch (e) {
meta.textContent = '查询失败:网络或服务异常';
renderRows([]);
}
}
(function init() {
var fromUrlUuid = getQueryParam('uuid');
if (fromUrlUuid && !$('uuidInput').value) {
$('uuidInput').value = fromUrlUuid;
}
$('queryBtn').addEventListener('click', queryData);
queryData();
})();
</script>
</body>
</html>