125续15l-5: 后台玩家签署情况板块 + 玩家端查看协议原文

- admin.php: 侧边栏加'📜 用户协议'(data-p=rules), go('rules')→loadRules
  后台视角=玩家签署情况: 已签总数/当前版本已签/旧版本待重签 + 签署记录倒序表
  (玩家名/签署时间/版本状态徽章), 调 api/sync.php?action=rules_content
  rules目录无.md 时后台提示未配置
- player.php: 侧边栏加'📜 用户协议', switchPage('rules')→renderRules
  玩家端视角=查看协议原文: 轻量markdown渲染(标题/列表/加粗/引用/代码/链接), 无外部依赖
  展示版本指纹+行数; rules目录无.md 时提示未配置
This commit is contained in:
ypsdf1
2026-11-19 23:23:48 +08:00
parent 20220f7a96
commit c118bb2303
2 changed files with 168 additions and 0 deletions
+74
View File
@@ -209,6 +209,7 @@ if (is_file($ossTxt)) {
<div class="si" data-p="cashier_manage" onclick="go('cashier_manage')">🧾 收银员管理</div>
<div class="si" data-p="recharge_orders" onclick="go('recharge_orders')">💳 充值对账</div>
<div class="si" data-p="shop_config" onclick="go('shop_config')">🛒 充值商店配置</div>
<div class="si" data-p="rules" onclick="go('rules')">📜 用户协议</div>
<div class="si" onclick="location.href='admin_2fa_setup.php'">🛡️ 安全配置(2FA / IP白名单 / 入口令牌)</div>
</div>
<div class="content" id="C"></div>
@@ -288,6 +289,7 @@ function go(p) {
else if (p==='cashier_manage') loadCashierManage(c);
else if (p==='recharge_orders') loadRechargeOrders(c);
else if (p==='shop_config') loadShopConfig(c);
else if (p==='rules') loadRules(c);
}
// 检查登录状态
@@ -4480,6 +4482,78 @@ async function loadShopConfig(el) {
loadShopConfigData();
}
async function loadRules(el) {
el.innerHTML = '<div style="text-align:center;padding:40px;color:var(--dim)">加载中...</div>';
try {
const res = await fetch('api/sync.php?action=rules_content', {
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' }
});
const data = await res.json();
if (!data.success || !data.data) {
el.innerHTML = '<div class="card" style="padding:24px">❌ 加载失败:' + esc(data.message || '未知错误') + '</div>';
return;
}
const d = data.data;
// 服务器未配置用户协议
if (d.skipped || !d.has_agreement) {
el.innerHTML = `<div class="card" style="padding:24px">
<h2 style="margin:0 0 12px;color:var(--fg)">📜 用户协议 · 玩家签署情况</h2>
<p style="color:var(--dim)">服务器未配置用户协议(Web 目录 rules/ 下没有 .md 文件)。</p>
<p style="color:var(--dim);margin-top:8px">此时登录页不显示勾选门控,也不要求玩家签章。</p>
</div>`;
return;
}
const list = d.signed_list || [];
const totalSigned = d.total_signed || 0;
const curVersion = list.filter(r => r.current_version).length;
let html = `<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;flex-wrap:wrap;gap:8px">`;
html += `<h2 style="margin:0;color:var(--fg)">📜 用户协议 · 玩家签署情况</h2>`;
html += `<div style="display:flex;gap:8px">`;
html += `<button onclick="loadRules(document.getElementById('C'))" style="padding:6px 12px;background:var(--card);color:var(--dim);border:1px solid var(--border);border-radius:4px;cursor:pointer;font-size:12px">🔄 刷新</button>`;
html += `</div></div>`;
html += '<div class="dash-stats">';
html += `<div class="dash-stat"><div class="v blue">${totalSigned}</div><div class="l">已签署玩家</div></div>`;
html += `<div class="dash-stat"><div class="v green">${curVersion}</div><div class="l">当前版本已签</div></div>`;
html += `<div class="dash-stat"><div class="v yellow">${totalSigned - curVersion}</div><div class="l">旧版本待重签</div></div>`;
html += `</div>`;
// 协议元信息
html += '<div class="card" style="margin-bottom:16px"><h3 style="margin:0 0 10px;font-size:14px">当前协议</h3>';
html += `<p style="color:var(--text);font-size:13px">协议标题:${esc(d.title || '(无)')}<br>`;
html += `<span style="color:var(--dim);font-size:12px">版本指纹:${esc(d.fingerprint || '')} | 共 ${d.line_count || 0} 行</span></p>`;
html += `<p style="color:var(--dim);font-size:12px;margin-top:8px">玩家端可通过登录页「查看协议原文」或 /rules 阅读正文;后台此处仅监控签署进度。</p>`;
html += '</div>';
// 签署清单表
html += '<div class="card"><h3 style="margin:0 0 12px;font-size:14px">签署记录(按签署时间倒序,最多显示 200 条)</h3>';
if (list.length === 0) {
html += '<p style="color:var(--dim);font-size:13px;padding:12px">暂无玩家签署记录。玩家登录 Web 端并勾选「已阅用户协议」后,此处将生成签章回执并在此登记。</p>';
} else {
html += '<table style="width:100%;border-collapse:collapse;font-size:13px">';
html += '<thead><tr style="color:var(--dim);text-align:left"><th style="padding:8px;border-bottom:1px solid var(--border)">玩家</th><th style="padding:8px;border-bottom:1px solid var(--border)">签署时间</th><th style="padding:8px;border-bottom:1px solid var(--border)">版本状态</th></tr></thead><tbody>';
for (const r of list) {
const when = r.signed_at > 0 ? new Date(r.signed_at * 1000).toLocaleString('zh-CN') : '未知';
const verBadge = r.current_version
? '<span style="color:var(--green)">✔ 当前版本</span>'
: '<span style="color:var(--yellow)">⚠ 旧版本(协议已更新,需重签)</span>';
html += `<tr><td style="padding:8px;border-bottom:1px solid var(--border);color:var(--text);font-weight:600">${esc(r.player)}</td>`
+ `<td style="padding:8px;border-bottom:1px solid var(--border);color:var(--dim)">${when}</td>`
+ `<td style="padding:8px;border-bottom:1px solid var(--border)">${verBadge}</td></tr>`;
}
html += '</tbody></table>';
}
html += '</div>';
el.innerHTML = html;
} catch (e) {
el.innerHTML = '<div class="card" style="padding:24px;color:var(--red)">加载失败:' + esc(e.message) + '</div>';
}
}
async function loadShopConfigData() {
const el = document.getElementById('shopConfigList');
if (!el) return;
+94
View File
@@ -381,6 +381,7 @@ if ($currentVersion !== $BUILD_VERSION) {
<div class="sidebar-item" data-page="sn" onclick="switchPage('sn')">🔢 SN设备管理</div>
<div class="sidebar-item" data-page="account" onclick="switchPage('account')">🛡️ 账号安全</div>
<div class="sidebar-item" data-page="credit" onclick="switchPage('credit')">⭐ 信誉积分</div>
<div class="sidebar-item" data-page="rules" onclick="switchPage('rules')">📜 用户协议</div>
</div>
<div class="content" id="content">
@@ -1273,6 +1274,99 @@ if ($currentVersion !== $BUILD_VERSION) {
else if (page === 'credit') renderCredit(c);
else if (page === 'recharge') renderRecharge(c);
else if (page === 'orders') renderMyOrders(c);
else if (page === 'rules') renderRules(c);
}
// ==================== 用户协议(玩家端查看协议原文) ====================
// 数据源:api/sync.php?action=rules_content(读 Web 目录 rules/*.md)
// rules 目录无 .md → 提示"服务器未配置用户协议"
async function renderRules(el) {
el.innerHTML = `<div class="card" style="text-align:center;padding:40px;color:var(--dim)">正在加载用户协议...</div>`;
let d = null;
try {
const res = await fetch('api/sync.php?action=rules_content', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin'
});
const json = await res.json();
if (json.success && json.data) d = json.data;
} catch (e) {
el.innerHTML = `<div class="card" style="padding:24px;color:var(--red)">协议加载失败:${e.message}</div>`;
return;
}
if (!d || d.skipped || !d.has_agreement) {
el.innerHTML = `<div class="card" style="padding:24px">
<h2 style="margin:0 0 10px">📜 用户协议</h2>
<p style="color:var(--dim)">服务器当前未配置用户协议(rules 目录无协议文件)。</p>
</div>`;
return;
}
// 渲染:用 <pre-wrap> 原文 + 简单 markdown 转 html(标题/列表/加粗),不引入外部依赖
el.innerHTML = `<div class="card" style="max-width:760px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;flex-wrap:wrap;gap:8px">
<h2 style="margin:0">📜 ${esc(d.title || '服务器用户协议')}</h2>
<button class="btn btn-dim" onclick="renderRules(document.getElementById('content'))" style="font-size:12px;padding:6px 12px">🔄 刷新</button>
</div>
<div class="rules-body" style="line-height:1.85;font-size:14px;white-space:pre-wrap;word-break:break-word;color:var(--text)">
${renderMarkdownLite(d.content)}
</div>
<p style="color:var(--dim);font-size:12px;margin-top:16px">协议版本指纹:${esc(d.fingerprint || '')} | 共 ${d.line_count || 0} 行</p>
</div>`;
}
// 轻量 markdown → HTML(仅处理标题/无序列表/加粗/表格分隔线/引用/代码/链接,足够展示协议)
function renderMarkdownLite(md) {
if (!md) return '';
const lines = String(md).split('\n');
let html = '';
let inList = false;
const closeList = () => { if (inList) { html += '</ul>'; inList = false; } };
for (let raw of lines) {
let s = raw;
// 表格分隔线丢弃
if (s.trim().match(/^\|?[\s:|-]+\|?$/) && s.trim().length > 1 && s.includes('-')) { closeList(); continue; }
// 代码围栏 ``` 整行丢弃(json 动作配置已在后端剥离,双保险)
if (s.trim().startsWith('```')) { closeList(); continue; }
// 标题
if (s.match(/^#{1,6}\s/)) {
closeList();
const lvl = s.match(/^#+/)[0].length;
const txt = s.replace(/^#+\s*/, '');
const sz = Math.max(15, 22 - lvl);
html += `<div style="font-size:${sz}px;font-weight:700;color:var(--accent);margin:14px 0 8px">${esc(txt)}</div>`;
continue;
}
// 无序列表
if (s.match(/^\s*[-*+]\s+/)) {
if (!inList) { html += '<ul style="margin:6px 0 6px 20px;padding:0">'; inList = true; }
const item = s.replace(/^\s*[-*+]\s+/, '');
html += `<li style="margin:3px 0">${inlineMd(item)}</li>`;
continue;
}
closeList();
// 引用
if (s.match(/^\s*>/)) {
html += `<div style="border-left:3px solid var(--yellow);padding:6px 12px;margin:8px 0;background:rgba(210,153,34,0.08);border-radius:4px">${inlineMd(s.replace(/^\s*>\s?/, ''))}</div>`;
continue;
}
// 空行
if (s.trim() === '') { html += '<div style="height:8px"></div>'; continue; }
// 普通段落
html += `<div style="margin:4px 0">${inlineMd(s)}</div>`;
}
closeList();
return html;
}
// 行内 markdown:加粗/斜体/代码/链接
function inlineMd(s) {
let t = esc(s);
t = t.replace(/`([^`]*)`/g, '<code style="background:rgba(136,136,136,0.2);padding:1px 5px;border-radius:3px;font-size:0.9em">$1</code>');
t = t.replace(/(\*\*|__)(.+?)\1/g, '<b>$2</b>');
t = t.replace(/(^|[^*])(\*)([^*]+)\*(?!\*)/g, '$1<i>$3</i>');
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener" style="color:var(--accent);text-decoration:underline">$1</a>');
return t;
}
// ==================== 债券在线充值(动态加载商品) ====================