Files
gold-price-watcher/public/index.html
T

411 lines
24 KiB
HTML
Raw Normal View History

2026-11-24 16:37:13 +08:00
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>金价提醒 · Gold Price Watcher</title>
<link rel="stylesheet" href="/styles.css?v=20261124w" />
2026-11-24 16:37:13 +08:00
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="logo">Au</span>
<div class="brand-text">
<h1>金价提醒</h1>
<p>Gold Price Watcher · 本地监控</p>
</div>
</div>
<div class="status-bar">
<span class="pill" id="runPill"><i class="dot"></i><span id="runText">加载中…</span></span>
<span class="pill muted" id="quietPill" hidden>静默时段</span>
<span class="clock" id="serverTime">--:--:--</span>
<button class="btn ghost" id="btnRefresh">立即刷新</button>
<button class="btn primary" id="btnToggleRun">暂停监控</button>
</div>
</header>
<nav class="tabs" id="tabs">
<button class="tab active" data-tab="market">行情看板</button>
<button class="tab" data-tab="rules">提醒规则</button>
<button class="tab" data-tab="channels">通知设置</button>
<button class="tab" data-tab="alerts">提醒记录<span class="badge" id="alertBadge" hidden>0</span></button>
</nav>
<main>
<!-- ============ 行情看板 ============ -->
<section class="panel active" id="panel-market">
<div class="section-head">
<div>
<h2>监控品种</h2>
<p class="hint">每个品种可以单独设置刷新频率,价格变动后会按规则触发提醒。</p>
</div>
<button class="btn primary" id="btnAddInstrument">+ 添加品种</button>
</div>
<div class="grid" id="instrumentGrid"></div>
<p class="empty" id="instrumentEmpty" hidden>还没有监控品种,点击右上角「添加品种」开始。</p>
</section>
<!-- ============ 提醒规则 ============ -->
<section class="panel" id="panel-rules">
<div class="section-head">
<div>
<h2>提醒规则</h2>
<p class="hint">支持价格阈值、涨跌幅(可指定统计区间,如「近 10 分钟涨 0.5%」)、阶梯提醒(每涨/跌一个步长提醒一次)、两个品种之间的价差、定时提醒、请求失败告警(连续查询失败 N 次)六类规则;价格类规则还能限定生效时段并按冷却时间防轰炸,定时提醒按时刻去重。</p>
2026-11-24 16:37:13 +08:00
</div>
<button class="btn primary" id="btnAddRule">+ 新建规则</button>
</div>
<div class="rule-list" id="ruleList"></div>
<p class="empty" id="ruleEmpty" hidden>还没有规则。先添加一个「价格上破 800 元/克」试试。</p>
</section>
<!-- ============ 通知设置 ============ -->
<section class="panel" id="panel-channels">
<div class="section-head">
<div>
<h2>通知设置</h2>
<p class="hint">桌面通知走 Windows 原生 Toast;邮件走 SMTP;WebHook 支持内置 JSON 与钉钉机器人两种格式。配置只保存在本机。</p>
</div>
</div>
<div class="cards-2">
<div class="card setting-card">
<div class="card-head">
<h3>Windows 桌面通知</h3>
<label class="switch">
<input type="checkbox" id="desktopEnabled" />
<span></span>
</label>
</div>
<p class="hint">在右下角弹出系统通知,需要 Windows 10/11,且系统的「通知」未关闭。</p>
<div class="row">
<button class="btn ghost" id="btnTestDesktop">发送测试通知</button>
<span class="test-result" id="desktopTestResult"></span>
</div>
</div>
<div class="card setting-card">
<div class="card-head">
<h3>全局默认渠道</h3>
</div>
<p class="hint">规则没有单独指定渠道时,用这里的默认设置。</p>
<div class="row wrap">
<label class="check"><input type="checkbox" id="channelDesktop" /> 桌面通知</label>
<label class="check"><input type="checkbox" id="channelEmail" /> 邮件</label>
<label class="check"><input type="checkbox" id="channelWebhook" /> WebHook</label>
</div>
<div class="row">
<label class="field inline">
<span>默认刷新频率(秒)</span>
<input type="number" id="defaultInterval" min="5" max="86400" step="1" />
</label>
</div>
<div class="row wrap">
<label class="check"><input type="checkbox" id="quietEnabled" /> 静默时段只发邮件,不弹桌面通知</label>
<input type="text" id="quietRange" class="narrow" placeholder="23:00-07:00" />
<label class="check"><input type="checkbox" id="alertOnFirstCheck" /> 启动时已满足条件也提醒一次</label>
</div>
</div>
</div>
<div class="card setting-card" id="emailCard">
<div class="card-head">
<h3>邮箱提醒(SMTP)</h3>
<label class="switch">
<input type="checkbox" id="emailEnabled" />
<span></span>
</label>
</div>
<p class="hint">
常见填写:QQ 邮箱 <code>smtp.qq.com</code> + 465 + 授权码;163 邮箱 <code>smtp.163.com</code> + 465 + 授权码;
企业邮箱按服务商文档填写。密码处请填「授权码」而不是登录密码。
</p>
<div class="form-grid">
<label class="field"><span>SMTP 服务器</span><input type="text" id="emailHost" placeholder="smtp.qq.com" /></label>
<label class="field"><span>端口</span><input type="number" id="emailPort" placeholder="465" /></label>
<label class="field"><span>加密方式</span>
<select id="emailSecure">
<option value="true">SSL(端口 465)</option>
<option value="false">STARTTLS(端口 587)</option>
</select>
</label>
<label class="field"><span>发件邮箱</span><input type="text" id="emailUser" placeholder="you@qq.com" /></label>
<label class="field"><span>授权码 / 密码</span><input type="password" id="emailPass" placeholder="留空则不修改" autocomplete="new-password" /></label>
<label class="field"><span>发件人显示名</span><input type="text" id="emailFrom" placeholder="金价提醒 &lt;you@qq.com&gt;" /></label>
<label class="field wide"><span>收件人(多个用逗号或分号分隔)</span><input type="text" id="emailTo" placeholder="a@qq.com, b@163.com" /></label>
<label class="field"><span>邮件标题前缀</span><input type="text" id="emailPrefix" placeholder="【金价提醒】" /></label>
<label class="field check-field"><span>邮件正文附带行情快照</span><input type="checkbox" id="emailSnapshot" /></label>
</div>
<div class="row">
<button class="btn ghost" id="btnTestEmail">发送测试邮件</button>
<span class="test-result" id="emailTestResult"></span>
</div>
</div>
<div class="card setting-card" id="webhookCard">
<div class="card-head">
<h3>WebHook 推送</h3>
<label class="switch">
<input type="checkbox" id="webhookEnabled" />
<span></span>
</label>
</div>
<p class="hint">
触发提醒时向该地址 POST 一条消息。两种格式:<b>内置 JSON</b> 是本工具固定的字段结构,方便自建服务或自动化脚本消费;
<b>钉钉机器人</b> 直接填群机器人的 Webhook 地址即可,支持「加签」安全设置。
</p>
<div class="form-grid">
<label class="field wide"><span>WebHook 地址</span>
<input type="text" id="webhookUrl" placeholder="https://oapi.dingtalk.com/robot/send?access_token=xxx" />
</label>
<label class="field"><span>报文格式</span>
<select id="webhookFormat">
<option value="generic">内置 JSON(自定义服务)</option>
<option value="dingtalk">钉钉机器人(markdown)</option>
</select>
</label>
<label class="field" id="webhookSecretField"><span>钉钉加签密钥(可选)</span>
<input type="password" id="webhookSecret" placeholder="SEC 开头;机器人未启用加签可留空" autocomplete="new-password" />
</label>
<label class="field" id="webhookKeywordField"><span>钉钉自定义关键词(可选)</span>
<input type="text" id="webhookKeyword" placeholder="例如:金价(填机器人安全设置里的那个词)" />
</label>
<label class="field wide" id="webhookAtMobilesField"><span>钉钉 @ 手机号(多个用逗号分隔,可留空)</span>
<input type="text" id="webhookAtMobiles" placeholder="13800000000, 13900000000" />
</label>
<label class="field check-field" id="webhookMentionAllField"><span>钉钉 @所有人</span>
<input type="checkbox" id="webhookMentionAll" />
</label>
</div>
<p class="hint" id="webhookFormatHint"></p>
<div class="row">
<button class="btn ghost" id="btnTestWebhook">发送测试推送</button>
<span class="test-result" id="webhookTestResult"></span>
</div>
</div>
<div class="card setting-card">
<div class="card-head"><h3>服务与安全</h3></div>
<div class="form-grid">
<label class="field"><span>监听端口(改后需重启)</span><input type="number" id="appPort" min="1" max="65535" /></label>
<label class="field"><span>监听地址</span><input type="text" id="appHost" placeholder="127.0.0.1" /></label>
<label class="field wide"><span>访问令牌(留空表示本机免登录;非本机访问强烈建议设置)</span><input type="text" id="appToken" placeholder="自定义一串字符" /></label>
</div>
<div class="row">
<label class="check"><input type="checkbox" id="appOpenBrowser" /> 启动时自动打开浏览器</label>
</div>
<p class="hint" id="configPathHint"></p>
2026-11-24 17:22:08 +08:00
</div>
<!-- 配置备份:导出为 JSON 文件、导入前自动备份当前配置 -->
<div class="card setting-card">
<div class="card-head"><h3>配置备份</h3></div>
<p class="hint">导出成 JSON 文件,可用于换机迁移、分享给同事,或改坏配置后回滚;导入会<b>覆盖</b>当前全部配置(品种、规则、渠道、端口等),导入前程序会自动把现有配置备份到 <code>config/backups/</code>。</p>
<div class="row wrap">
<label class="check"><input type="checkbox" id="exportWithSecrets" /> 导出时包含密钥(邮箱密码 / WebHook 加签)</label>
2026-11-24 16:37:13 +08:00
</div>
2026-11-24 17:22:08 +08:00
<div class="row wrap">
<button class="btn primary" id="btnExportConfig">导出配置</button>
<button class="btn ghost" id="btnImportConfig">导入配置</button>
<input type="file" id="importFile" accept="application/json,.json" hidden />
</div>
<p class="hint" id="backupListHint"></p>
2026-11-24 16:37:13 +08:00
</div>
<div class="row sticky-save">
<button class="btn primary" id="btnSaveSettings">保存设置</button>
<span class="test-result" id="saveResult"></span>
</div>
</section>
<!-- ============ 提醒记录 ============ -->
<section class="panel" id="panel-alerts">
<div class="section-head">
<div>
<h2>提醒记录</h2>
<p class="hint">最近 200 条触发记录,同时写入 <code>data/alerts.jsonl</code> 便于追溯。</p>
</div>
<button class="btn ghost" id="btnClearAlerts">清空</button>
</div>
<div class="alert-list" id="alertList"></div>
<p class="empty" id="alertEmpty" hidden>暂时还没有触发过提醒。</p>
</section>
</main>
<!-- ============ 弹窗:添加/编辑品种 ============ -->
<div class="modal" id="modalInstrument" hidden>
<div class="modal-box">
<div class="modal-head">
<h3 id="instrumentModalTitle">添加品种</h3>
<button class="icon-btn" data-close="modalInstrument">✕</button>
</div>
<div class="modal-body">
<label class="field wide">
<span>选择内置品种</span>
<select id="presetSelect"></select>
</label>
<p class="hint" id="presetHint"></p>
<div class="form-grid" id="instrumentCustomFields">
<label class="field wide"><span>名称</span><input type="text" id="instName" placeholder="例如 浙商黄金" /></label>
<label class="field"><span>数据源</span><select id="instSource"></select></label>
<label class="field"><span>刷新频率(秒)</span><input type="number" id="instInterval" min="5" max="86400" step="5" /></label>
<label class="field"><span>价格单位</span><input type="text" id="instUnit" placeholder="元/克" /></label>
<label class="field"><span>小数位</span><input type="number" id="instDigits" min="0" max="4" /></label>
<label class="field wide" id="sinaCodeField"><span>新浪行情代码</span><input type="text" id="instSinaCode" placeholder="SGE_AUTD / hf_XAU / nf_AU0" /></label>
<label class="field wide" id="rijinjiaKeyField"><span>积存金品种 key</span><input type="text" id="instRijinjiaKey" placeholder="czb-jcj" /></label>
<label class="field wide" id="httpUrlField"><span>接口地址</span><input type="text" id="instHttpUrl" placeholder="https://api.example.com/gold" /></label>
<label class="field" id="httpPricePathField"><span>价格字段路径</span><input type="text" id="instHttpPricePath" placeholder="data.price" /></label>
<label class="field" id="httpPrevPathField"><span>昨收字段路径(可选)</span><input type="text" id="instHttpPrevPath" placeholder="data.prevClose" /></label>
</div>
<p class="hint">提示:添加前可以先在「行情」里用「测试抓取」验证数据源是否可用。</p>
</div>
<div class="modal-foot">
<span class="test-result" id="instrumentResult"></span>
<button class="btn ghost" data-close="modalInstrument">取消</button>
<button class="btn ghost" id="btnTestInstrument">测试抓取</button>
<button class="btn primary" id="btnSaveInstrument">保存</button>
</div>
</div>
</div>
<!-- ============ 弹窗:规则 ============ -->
<div class="modal" id="modalRule" hidden>
<div class="modal-box">
<div class="modal-head">
<h3 id="ruleModalTitle">新建规则</h3>
<button class="icon-btn" data-close="modalRule">✕</button>
</div>
<div class="modal-body">
<div class="form-grid">
<!-- 1) 先定类型和标的:类型 → 监控品种(价差再加对比品种) -->
<label class="field"><span>规则类型</span>
<select id="ruleType">
<option value="threshold">价格阈值</option>
<option value="change">涨跌幅</option>
<option value="ladder">阶梯提醒</option>
2026-11-24 16:37:13 +08:00
<option value="spread">价差提醒</option>
<option value="schedule">定时提醒</option>
<option value="failure">请求失败告警</option>
2026-11-24 16:37:13 +08:00
</select>
</label>
<label class="field"><span>监控品种</span><select id="ruleInstrument"></select></label>
<label class="field" id="ruleCompareField" hidden><span>对比品种</span><select id="ruleCompare"></select></label>
<!-- 2) 再定口径和方向:口径决定阈值的单位,放在方向/阈值之前 -->
<label class="field" id="ruleModeField" hidden><span>价差口径</span>
<select id="ruleMode">
<option value="abs">绝对价差(元/克)</option>
<option value="percent">相对价差(%)</option>
</select>
</label>
<!-- 涨跌幅专用:阈值口径(百分比 / 具体价格变动值) -->
<label class="field" id="ruleBasisField" hidden><span>阈值口径</span>
<select id="ruleBasis">
<option value="percent">涨跌幅百分比(%)</option>
<option value="amount">具体变动值(元/克)</option>
</select>
</label>
<label class="field" id="ruleDirectionField"><span>触发方向</span><select id="ruleDirection"></select></label>
<!-- 3) 触发条件:阈值 + 统计区间 -->
<label class="field" id="ruleValueField"><span id="ruleValueLabel">阈值</span>
<input type="number" id="ruleValue" step="0.001" placeholder="800" />
</label>
<!-- 涨跌幅专用:统计区间(日内相对昨收,或近 N 分钟的滚动窗口) -->
<label class="field" id="ruleWindowField" hidden><span>统计区间</span>
<select id="ruleWindow">
<option value="0">日内(相对昨收)</option>
<option value="300">近 5 分钟</option>
<option value="600">近 10 分钟</option>
<option value="900">近 15 分钟</option>
<option value="1800">近 30 分钟</option>
<option value="3600">近 1 小时</option>
<option value="7200">近 2 小时</option>
<option value="14400">近 4 小时</option>
<option value="-1">自定义(分钟)</option>
</select>
</label>
<label class="field" id="ruleWindowCustomField" hidden><span>自定义分钟数(最长 720)</span>
<input type="number" id="ruleWindowCustom" min="1" max="720" step="1" placeholder="20" />
</label>
<!-- 4) 生效与提醒频率 -->
<!-- 生效时段:留空表示全天,支持跨零点(如 22:00 ~ 02:00) -->
<label class="field wide" id="ruleActiveRangeField"><span>生效时段(可选,留空表示全天)</span>
<div class="time-range">
<input type="time" id="ruleActiveFrom" />
<span class="range-sep">~</span>
<input type="time" id="ruleActiveTo" />
</div>
</label>
<label class="field" id="ruleCooldownField"><span>冷却时间(秒)</span><input type="number" id="ruleCooldown" min="30" step="30" value="1800" /></label>
<label class="field" id="ruleRepeatField"><span id="ruleRepeatLabel">持续满足时每 N 秒重复提醒(0 不重复)</span><input type="number" id="ruleRepeat" min="0" step="60" value="0" /></label>
2026-11-24 16:37:13 +08:00
<!-- 定时提醒专用:到点时刻 + 重复方式 -->
<label class="field wide" id="ruleScheduleTimesField" hidden><span>提醒时刻(24 小时制,多个用逗号分隔,最多 12 个)</span>
<input type="text" id="ruleScheduleTimes" placeholder="09:00, 15:30, 21:00" />
</label>
<label class="field" id="ruleScheduleRepeatField" hidden><span>重复方式</span>
<select id="ruleScheduleRepeat">
<option value="daily">每天</option>
<option value="weekday">工作日(周一至周五)</option>
<option value="weekly">每周指定几天</option>
</select>
</label>
<div class="field wide" id="ruleScheduleWeekdaysField" hidden>
<span>每周的哪几天</span>
<div class="row wrap">
<label class="check"><input type="checkbox" class="js-weekday" value="1" /> 周一</label>
<label class="check"><input type="checkbox" class="js-weekday" value="2" /> 周二</label>
<label class="check"><input type="checkbox" class="js-weekday" value="3" /> 周三</label>
<label class="check"><input type="checkbox" class="js-weekday" value="4" /> 周四</label>
<label class="check"><input type="checkbox" class="js-weekday" value="5" /> 周五</label>
<label class="check"><input type="checkbox" class="js-weekday" value="6" /> 周六</label>
<label class="check"><input type="checkbox" class="js-weekday" value="7" /> 周日</label>
</div>
</div>
<!-- 5) 最后填名称:留空则按上面的条件自动生成 -->
<label class="field wide"><span>规则名称(可选,留空自动生成)</span><input type="text" id="ruleName" placeholder="留空则按触发条件自动命名" /></label>
</div>
<div class="row wrap">
<span class="label-text">通知渠道</span>
<label class="check"><input type="checkbox" id="ruleChannelDesktop" /> 桌面通知</label>
<label class="check"><input type="checkbox" id="ruleChannelEmail" /> 邮件</label>
<label class="check"><input type="checkbox" id="ruleChannelWebhook" /> WebHook</label>
<label class="check"><input type="checkbox" id="ruleEnabled" /> 启用该规则</label>
</div>
<p class="hint" id="ruleSummary"></p>
<p class="hint" id="ruleWindowHint">提示:统计区间选「日内」时,涨跌幅相对昨收计算;选「近 N 分钟」时,用本机缓存的行情点回算滚动区间,重启后会接着用已保存的历史。</p>
<p class="hint" id="ruleScheduleHint" hidden>提示:定时提醒会在指定时刻按当时的行情发一条通知,不受价格条件影响;同一时刻每天只响一次,程序当时没运行则不会补发。</p>
<p class="hint" id="ruleLadderHint" hidden>提示:阶梯提醒以「上次提醒时的价格」为基准,价格每偏离一个步长就提醒一次,随后基准更新为当前价。例如步长 2 元/克:782 提醒后基准变 782,涨到 784 再提醒;价格回落不会提醒,也不会重置基准。</p>
<p class="hint" id="ruleFailureHint" hidden>提示:请求失败告警盯的是「数据源还能不能取到价」,与价格高低无关。连续查询失败达到设定次数时提醒一次;一旦某次抓取成功,失败计数清零,下次再连续失败达到次数还会重新提醒。数据源长时间不可用时,可在「持续失败时每 N 秒重复提醒」里填间隔,避免只响一次被忽略。</p>
2026-11-24 16:37:13 +08:00
</div>
<div class="modal-foot">
<span class="test-result" id="ruleResult"></span>
<button class="btn ghost" data-close="modalRule">取消</button>
<button class="btn primary" id="btnSaveRule">保存规则</button>
</div>
</div>
</div>
2026-11-24 17:22:08 +08:00
<!-- ============ 弹窗:确认导入配置 ============ -->
<div class="modal" id="modalImport" hidden>
<div class="modal-box">
<div class="modal-head">
<h3>确认导入配置</h3>
<button class="icon-btn" data-close="modalImport">✕</button>
</div>
<div class="modal-body">
<p class="hint">导入会<b>覆盖</b>当前全部配置(品种、规则、通知渠道、端口等);导入前程序会自动把现有配置备份到 <code>config/backups/</code>,不满意可以用备份回滚。</p>
<div class="import-summary" id="importSummary"></div>
</div>
<div class="modal-foot">
<span class="test-result" id="importResult"></span>
<button class="btn ghost" data-close="modalImport">取消</button>
<button class="btn primary" id="btnConfirmImport">确认导入</button>
</div>
</div>
</div>
2026-11-24 16:37:13 +08:00
<div class="toast-wrap" id="toastWrap"></div>
<script src="/app.js?v=20261124w"></script>
2026-11-24 16:37:13 +08:00
</body>
</html>