feat: M0-M2 骨架落地(服务端/前端/宿主/数据库/积分引擎)
- server: Go 单二进制骨架,embed 内嵌前端,配置/迁移/HTTP 路由 - store: system.db + event.db 两套迁移,业务表 + 种子数据 - domain: 积分引擎(并列三口径/计分通道/流水/排名/破纪录)+ 68 个测试 - web: Vite + Vue 三入口骨架 + shared 层(类型/API/WebSocket 客户端) - console: Electron 宿主骨架(选屏/防熄屏/进程守护/托盘)
This commit is contained in:
1 parent
a61d793d79
commit
7d5d94f815
76 files changed
+10131
No files matched your search
@@ -0,0 +1,130 @@
|
||||
'use strict'
|
||||
|
||||
const el = {
|
||||
version: document.getElementById('app-version'),
|
||||
stateDot: document.getElementById('state-dot'),
|
||||
stateLabel: document.getElementById('state-label'),
|
||||
stateDetail: document.getElementById('state-detail'),
|
||||
url: document.getElementById('k-url'),
|
||||
pid: document.getElementById('k-pid'),
|
||||
restarts: document.getElementById('k-restarts'),
|
||||
power: document.getElementById('k-power'),
|
||||
exe: document.getElementById('k-exe'),
|
||||
config: document.getElementById('k-config'),
|
||||
configWarning: document.getElementById('config-warning'),
|
||||
displayList: document.getElementById('display-list'),
|
||||
log: document.getElementById('log'),
|
||||
autoscroll: document.getElementById('autoscroll'),
|
||||
btnStart: document.getElementById('btn-start'),
|
||||
btnStop: document.getElementById('btn-stop'),
|
||||
btnRestart: document.getElementById('btn-restart'),
|
||||
btnRelayout: document.getElementById('btn-relayout'),
|
||||
btnOpenAdmin: document.getElementById('btn-open-admin'),
|
||||
btnClearLog: document.getElementById('btn-clear-log')
|
||||
}
|
||||
|
||||
const DOT_CLASS = {
|
||||
running: 'ok',
|
||||
starting: 'warn',
|
||||
stopping: 'warn',
|
||||
crashed: 'err',
|
||||
stopped: ''
|
||||
}
|
||||
|
||||
let lastStatus = null
|
||||
|
||||
function renderStatus(status) {
|
||||
lastStatus = status
|
||||
el.version.textContent = status.appVersion ? `v${status.appVersion}` : ''
|
||||
|
||||
el.stateDot.className = `dot ${status.healthy ? 'ok' : DOT_CLASS[status.state] || ''}`
|
||||
el.stateLabel.textContent = status.stateLabel || status.state
|
||||
el.stateDetail.textContent = status.healthy
|
||||
? '健康检查通过'
|
||||
: status.lastError || (status.state === 'stopped' ? '服务未运行' : '等待健康检查')
|
||||
|
||||
el.url.textContent = status.url || '—'
|
||||
el.pid.textContent = status.pid || '—'
|
||||
el.restarts.textContent = status.restarts ? `${status.restarts} 次` : '0 次'
|
||||
el.power.textContent = status.powerSaveBlocked ? '已启用(阻止显示器休眠)' : '未启用'
|
||||
el.exe.textContent = status.exePath || '—'
|
||||
el.config.textContent = status.configPath || '—'
|
||||
|
||||
if (status.configWarning) {
|
||||
el.configWarning.hidden = false
|
||||
el.configWarning.textContent = status.configWarning
|
||||
} else {
|
||||
el.configWarning.hidden = true
|
||||
}
|
||||
|
||||
const busy = ['starting', 'running', 'stopping'].includes(status.state)
|
||||
el.btnStart.disabled = busy
|
||||
el.btnStop.disabled = !busy
|
||||
el.btnRestart.disabled = !busy
|
||||
|
||||
renderDisplays(status.displays || [])
|
||||
}
|
||||
|
||||
function renderDisplays(displays) {
|
||||
el.displayList.textContent = ''
|
||||
if (!displays.length) {
|
||||
const li = document.createElement('li')
|
||||
li.className = 'muted'
|
||||
li.textContent = '尚未打开大屏窗口'
|
||||
el.displayList.append(li)
|
||||
return
|
||||
}
|
||||
for (const item of displays) {
|
||||
const li = document.createElement('li')
|
||||
const page = document.createElement('span')
|
||||
page.className = 'page'
|
||||
page.textContent = `屏 ${item.displayId} · ${item.page}`
|
||||
const url = document.createElement('span')
|
||||
url.className = 'url'
|
||||
url.textContent = item.url || '(加载中)'
|
||||
li.append(page, url)
|
||||
el.displayList.append(li)
|
||||
}
|
||||
}
|
||||
|
||||
function appendLog(line) {
|
||||
const atBottom = el.log.scrollTop + el.log.clientHeight >= el.log.scrollHeight - 8
|
||||
el.log.textContent += `${line}\n`
|
||||
if (el.autoscroll.checked && atBottom) {
|
||||
el.log.scrollTop = el.log.scrollHeight
|
||||
}
|
||||
}
|
||||
|
||||
function setLog(lines) {
|
||||
el.log.textContent = lines.length ? `${lines.join('\n')}\n` : ''
|
||||
el.log.scrollTop = el.log.scrollHeight
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
renderStatus(await window.consoleApi.getStatus())
|
||||
}
|
||||
|
||||
function bindActions() {
|
||||
el.btnStart.addEventListener('click', async () => renderStatus(await window.consoleApi.startService()))
|
||||
el.btnStop.addEventListener('click', async () => renderStatus(await window.consoleApi.stopService()))
|
||||
el.btnRestart.addEventListener('click', async () => renderStatus(await window.consoleApi.restartService()))
|
||||
el.btnRelayout.addEventListener('click', async () => renderStatus(await window.consoleApi.relayoutDisplays()))
|
||||
el.btnClearLog.addEventListener('click', async () => {
|
||||
await window.consoleApi.clearLog()
|
||||
setLog([])
|
||||
})
|
||||
el.btnOpenAdmin.addEventListener('click', () => {
|
||||
const url = (lastStatus && lastStatus.adminUrl) || 'http://127.0.0.1:8080/admin'
|
||||
window.consoleApi.openExternal(url)
|
||||
})
|
||||
}
|
||||
|
||||
async function boot() {
|
||||
bindActions()
|
||||
window.consoleApi.onStatus(renderStatus)
|
||||
window.consoleApi.onLog(appendLog)
|
||||
setLog(await window.consoleApi.getLog())
|
||||
await refresh()
|
||||
}
|
||||
|
||||
boot()
|
||||
@@ -0,0 +1,103 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'none'"
|
||||
/>
|
||||
<title>Scoreboard Console · 启动管理</title>
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<span class="brand-mark"></span>
|
||||
<div>
|
||||
<h1>Scoreboard Console</h1>
|
||||
<p class="brand-sub">赛事积分榜 · 桌面宿主</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span id="app-version" class="muted"></span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<h2>服务端状态</h2>
|
||||
<div class="actions">
|
||||
<button id="btn-start" class="btn primary" type="button">启动服务</button>
|
||||
<button id="btn-stop" class="btn" type="button">停止服务</button>
|
||||
<button id="btn-restart" class="btn" type="button">重启服务</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-row">
|
||||
<span id="state-dot" class="dot"></span>
|
||||
<strong id="state-label">已停止</strong>
|
||||
<span id="state-detail" class="muted"></span>
|
||||
</div>
|
||||
|
||||
<dl class="kv">
|
||||
<div>
|
||||
<dt>服务地址</dt>
|
||||
<dd id="k-url">—</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>进程 PID</dt>
|
||||
<dd id="k-pid">—</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>自动重启</dt>
|
||||
<dd id="k-restarts">—</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>防熄屏</dt>
|
||||
<dd id="k-power">—</dd>
|
||||
</div>
|
||||
<div class="wide">
|
||||
<dt>服务端程序</dt>
|
||||
<dd id="k-exe" class="mono">—</dd>
|
||||
</div>
|
||||
<div class="wide">
|
||||
<dt>配置文件</dt>
|
||||
<dd id="k-config" class="mono">—</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<p id="config-warning" class="warning" hidden></p>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<h2>大屏窗口</h2>
|
||||
<div class="actions">
|
||||
<button id="btn-relayout" class="btn" type="button">重新排布</button>
|
||||
<button id="btn-open-admin" class="btn" type="button">打开服务端管理面板</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint">
|
||||
单屏时窗口化、按 F11 切换全屏;多屏时除主屏外每块屏一个 kiosk 窗口,各锁一页。
|
||||
</p>
|
||||
<ul id="display-list" class="display-list">
|
||||
<li class="muted">尚未打开大屏窗口</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="card log-card">
|
||||
<div class="card-head">
|
||||
<h2>运行日志</h2>
|
||||
<div class="actions">
|
||||
<label class="check"><input id="autoscroll" type="checkbox" checked /> 自动滚动</label>
|
||||
<button id="btn-clear-log" class="btn" type="button">清空</button>
|
||||
</div>
|
||||
</div>
|
||||
<pre id="log" class="log"></pre>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
|
||||
// 渲染层是纯静态页面,能力全部经这里白名单暴露,不开 nodeIntegration
|
||||
const subscribe = (channel, callback) => {
|
||||
const handler = (_event, payload) => callback(payload)
|
||||
ipcRenderer.on(channel, handler)
|
||||
return () => ipcRenderer.removeListener(channel, handler)
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('consoleApi', {
|
||||
getStatus: () => ipcRenderer.invoke('service:get-status'),
|
||||
startService: () => ipcRenderer.invoke('service:start'),
|
||||
stopService: () => ipcRenderer.invoke('service:stop'),
|
||||
restartService: () => ipcRenderer.invoke('service:restart'),
|
||||
getLog: () => ipcRenderer.invoke('log:tail'),
|
||||
clearLog: () => ipcRenderer.invoke('log:clear'),
|
||||
relayoutDisplays: () => ipcRenderer.invoke('display:relayout'),
|
||||
openExternal: (url) => ipcRenderer.invoke('app:open-external', url),
|
||||
onLog: (callback) => subscribe('log:line', callback),
|
||||
onStatus: (callback) => subscribe('service:status', callback)
|
||||
})
|
||||
@@ -0,0 +1,270 @@
|
||||
:root {
|
||||
--bg: #0f1420;
|
||||
--panel: #161d2d;
|
||||
--panel-2: #1d2637;
|
||||
--border: #27314a;
|
||||
--text: #e6ecf7;
|
||||
--muted: #8b98b4;
|
||||
--accent: #4fd8ff;
|
||||
--ok: #3ddc97;
|
||||
--warn: #ffb454;
|
||||
--err: #ff6b6b;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font: 14px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 20px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.brand-mark {
|
||||
width: 10px;
|
||||
height: 34px;
|
||||
border-radius: 5px;
|
||||
background: linear-gradient(180deg, var(--accent), #1b6bb8);
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.brand-sub {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 16px 20px 20px;
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-rows: auto auto minmax(160px, 1fr);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.card {
|
||||
grid-column: span 2;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.log-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--panel-2);
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.btn:hover:not(:disabled) {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn.primary {
|
||||
border-color: transparent;
|
||||
background: var(--accent);
|
||||
color: #06202b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--muted);
|
||||
}
|
||||
|
||||
.dot.ok {
|
||||
background: var(--ok);
|
||||
box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.15);
|
||||
}
|
||||
|
||||
.dot.warn {
|
||||
background: var(--warn);
|
||||
box-shadow: 0 0 0 4px rgba(255, 180, 84, 0.15);
|
||||
}
|
||||
|
||||
.dot.err {
|
||||
background: var(--err);
|
||||
box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.15);
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.kv {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 10px 16px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.kv > div.wide {
|
||||
grid-column: span 2;
|
||||
}
|
||||
|
||||
.kv dt {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.kv dd {
|
||||
margin: 2px 0 0;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.warning {
|
||||
margin: 12px 0 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 180, 84, 0.12);
|
||||
color: var(--warn);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 0 0 10px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.display-list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.display-list li {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
background: var(--panel-2);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.display-list .page {
|
||||
min-width: 96px;
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.display-list .url {
|
||||
color: var(--muted);
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.log {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin: 0;
|
||||
padding: 10px 12px;
|
||||
overflow: auto;
|
||||
border-radius: 8px;
|
||||
background: #0a0e17;
|
||||
color: #b9c6e0;
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
Reference in new issue
Block a user