Files
audit-platform/综合管理平台/settings.html
T
guwangtu b91954df4a
CI / check (push) Failing after 15m48s
chore: initial open-source baseline v1.0.0
Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
2026-12-05 15:44:53 +00:00

427 lines
22 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统设置 · 综合管理平台</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
:root {
--bg-deep:#0f2027; --card:rgba(255,255,255,.06); --border:rgba(120,220,255,.22);
--text:#e8f4ff; --text-dim:#8fb0c2; --accent:#22d3ee; --accent2:#0ea5e9;
--danger:#f87171; --green:#4ade80;
}
body {
min-height:100vh; color:var(--text);
font-family:'Noto Sans SC','Microsoft YaHei',sans-serif;
background:linear-gradient(135deg,#0f2027 0%,#203a43 45%,#2c5364 100%);
background-attachment:fixed;
}
.topbar {
display:flex; align-items:center; justify-content:space-between;
padding:16px 32px; background:rgba(10,25,32,.55);
border-bottom:1px solid rgba(120,220,255,.14); backdrop-filter:blur(12px);
}
.topbar-left { display:flex; align-items:center; gap:14px; }
.logo-mark {
width:40px; height:40px; border-radius:10px; display:flex; align-items:center; justify-content:center;
background:rgba(79,209,255,.08); border:1px solid rgba(120,220,255,.35);
color:#9fe8ff; font-weight:900; font-size:18px; font-family:'Orbitron',sans-serif;
}
.title { font-size:18px; font-weight:700; color:#9fe8ff; letter-spacing:1px; }
.sub { font-size:11px; color:var(--text-dim); letter-spacing:1px; margin-top:2px; }
.topbar-right a {
display:inline-flex; align-items:center; gap:6px; padding:7px 14px; border-radius:20px;
background:rgba(10,30,45,.6); border:1px solid rgba(80,200,255,.35);
color:#9fe8ff; font-size:13px; text-decoration:none;
}
.topbar-right a:hover { background:rgba(34,211,238,.14); }
.wrap { max-width:960px; margin:0 auto; padding:28px 20px 60px; }
.page-desc { color:var(--text-dim); font-size:13px; margin-bottom:22px; }
.card {
background:var(--card); border:1px solid var(--border); border-radius:14px;
padding:24px 26px; margin-bottom:20px; backdrop-filter:blur(10px);
box-shadow:0 12px 40px rgba(0,0,0,.25);
}
.card h3 { font-size:16px; color:#9fe8ff; margin-bottom:6px; display:flex; align-items:center; gap:8px; }
.card .hint { font-size:12px; color:var(--text-dim); margin-bottom:18px; line-height:1.6; }
label { display:block; font-size:13px; color:#a9c4d4; margin:14px 0 6px; }
input[type=text], input[type=password], select {
width:100%; padding:11px 13px; border-radius:9px; outline:none;
border:1px solid rgba(140,220,255,.28); background:rgba(0,0,0,.25);
color:#eaf7ff; font-size:14px; font-family:inherit;
}
input:focus, select:focus { border-color:#4fd1ff; box-shadow:0 0 0 3px rgba(79,209,255,.12); }
input::placeholder { color:#6f8b9d; }
.row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.btn {
display:inline-flex; align-items:center; gap:8px; padding:10px 22px; border:0; border-radius:9px;
background:linear-gradient(90deg,#0ea5e9,#22d3ee); color:#03202c; font-weight:700;
font-size:14px; cursor:pointer; font-family:inherit; margin-top:18px;
}
.btn:hover { filter:brightness(1.08); }
.btn.ghost { background:rgba(255,255,255,.06); color:#b9d3e2; border:1px solid rgba(120,220,255,.25); }
.pwd-wrap{position:relative}
.pwd-wrap input{padding-right:46px}
.pwd-eye{position:absolute;right:8px;top:50%;transform:translateY(-50%);width:34px;height:34px;border:0;background:transparent;color:#9fb8c8;font-size:16px;cursor:pointer;border-radius:8px;line-height:1}
.pwd-eye:hover{color:#4fd1ff;background:rgba(79,209,255,.08)}
.msg { margin-top:12px; font-size:13px; min-height:18px; }
.msg.ok { color:var(--green); }
.msg.err { color:var(--danger); }
.toggles { display:grid; grid-template-columns:repeat(2,1fr); gap:12px; margin-top:6px; }
.toggle-item {
display:flex; align-items:center; justify-content:space-between; gap:10px;
padding:12px 14px; border-radius:9px; border:1px solid rgba(140,220,255,.18);
background:rgba(0,0,0,.18); font-size:14px;
}
.toggle-item input { width:18px; height:18px; accent-color:#22d3ee; }
.info-row {
display:flex; justify-content:space-between; gap:16px; padding:10px 0;
border-bottom:1px dashed rgba(120,220,255,.12); font-size:13px;
}
.info-row:last-child { border-bottom:none; }
.info-row .k { color:var(--text-dim); }
.info-row .v { color:var(--text); font-weight:600; }
.info-row .v.on { color:var(--green); }
.info-row .v.off { color:var(--danger); }
.foot-note { font-size:12px; color:#7d97a8; margin-top:8px; line-height:1.7; }
</style>
</head>
<body>
<div class="topbar">
<div class="topbar-left">
<div class="logo-mark">S</div>
<div>
<div class="title">系统设置</div>
<div class="sub">SETTINGS · 综合管理平台</div>
</div>
</div>
<div class="topbar-right">
<a href="/">← 返回门户</a>
</div>
</div>
<div class="wrap">
<div class="page-desc">在这里配置大模型、模块权限和登录密码。修改会立即保存到服务器。</div>
<!-- 大模型配置 -->
<div class="card">
<h3>🤖 大模型配置</h3>
<div class="hint">用于风险分析等 AI 功能。兼容 OpenAI 接口的服务都可以填,例如阿里云百炼(DashScope)兼容模式。</div>
<label>接口地址 Base URL</label>
<input type="text" id="llmBaseUrl" placeholder="https://dashscope.aliyuncs.com/compatible-mode/v1">
<label>模型名称</label>
<input type="text" id="llmModel" placeholder="qwen-plus">
<label>API Key</label>
<input type="text" id="llmApiKey" placeholder="留空表示不修改(当前:未设置)" autocomplete="off">
<div class="foot-note">出于安全考虑,这里不会显示完整 Key;留空保存则保持原 Key 不变。</div>
<button class="btn" onclick="saveLLM()">保存大模型配置</button>
<div class="msg" id="llmMsg"></div>
</div>
<!-- 模块权限 -->
<div class="card">
<h3>🔐 模块权限</h3>
<div class="hint">关闭的模块不会显示在门户首页,也不能进入。仅影响门户入口展示,数据不会被删除。</div>
<div class="toggles">
<label class="toggle-item">审计管理 <input type="checkbox" id="modAudit" checked></label>
<label class="toggle-item">风险管理 <input type="checkbox" id="modRisk" checked></label>
<label class="toggle-item">知识库管理 <input type="checkbox" id="modKnowledge" checked></label>
<label class="toggle-item">合同审核 <input type="checkbox" id="modContract" checked></label>
</div>
<button class="btn" onclick="saveModules()">保存模块权限</button>
<div class="msg" id="modMsg"></div>
</div>
<!-- 登录账号 -->
<div class="card">
<h3>👤 登录账号与密码</h3>
<div class="hint">当前登录账号:<b id="accountName">-</b>。修改密码后,下次登录使用新密码;已登录的会话不受影响。</div>
<label>当前密码</label>
<div class="pwd-wrap"><input type="password" id="curPassword" autocomplete="current-password"><button type="button" class="pwd-eye" onclick="togglePwd('curPassword', this)" aria-label="显示密码"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg></button></div>
<div class="row">
<div>
<label>新密码(至少 6 位)</label>
<div class="pwd-wrap"><input type="password" id="newPassword" autocomplete="new-password"><button type="button" class="pwd-eye" onclick="togglePwd('newPassword', this)" aria-label="显示密码"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg></button></div>
</div>
<div>
<label>确认新密码</label>
<div class="pwd-wrap"><input type="password" id="newPassword2" autocomplete="new-password"><button type="button" class="pwd-eye" onclick="togglePwd('newPassword2', this)" aria-label="显示密码"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg></button></div>
</div>
</div>
<button class="btn" onclick="savePassword()">修改密码</button>
<div class="msg" id="pwdMsg"></div>
</div>
<!-- 用户与角色权限 -->
<div class="card" id="userCard">
<h3>👥 用户与角色权限</h3>
<div class="hint">仅系统管理员可管理。每个用户绑定一个角色,角色决定可访问的模块;关闭/删除用户后其无法登录。</div>
<div id="roleSummary" class="foot-note">角色加载中…</div>
<div id="userList" style="margin-top:10px"></div>
<div id="userForm" style="display:none;margin-top:12px;border-top:1px dashed rgba(120,220,255,.12);padding-top:12px">
<input type="hidden" id="ufId">
<div class="row">
<div><label>用户名</label><input type="text" id="ufUsername" placeholder="登录账号" autocomplete="off"></div>
<div><label>显示名称</label><input type="text" id="ufDisplay" placeholder="如:张敏"></div>
</div>
<div class="row">
<div><label>角色</label><select id="ufRole" style="width:100%;padding:10px 12px;border-radius:10px;border:1px solid rgba(120,200,255,.2);background:rgba(8,20,32,.72);color:#e8f4ff"></select></div>
<div><label>状态</label><select id="ufStatus" style="width:100%;padding:10px 12px;border-radius:10px;border:1px solid rgba(120,200,255,.2);background:rgba(8,20,32,.72);color:#e8f4ff"><option>启用</option><option>停用</option></select></div>
</div>
<label>密码</label>
<input type="password" id="ufPassword" placeholder="新建必填;编辑时留空表示不修改" autocomplete="new-password">
<div style="display:flex;gap:10px;margin-top:12px">
<button class="btn" onclick="saveUser()">保存用户</button>
<button class="btn" onclick="cancelUserForm()" style="background:rgba(255,255,255,.06)">取消</button>
</div>
</div>
<div style="display:flex;gap:10px;margin-top:12px">
<button class="btn" id="addUserBtn" onclick="openUserForm()">+ 新增用户</button>
</div>
<div class="msg" id="userMsg"></div>
</div>
<!-- 系统信息 -->
<div class="card">
<h3>📊 系统信息</h3>
<div class="info-row"><span class="k">门户端口</span><span class="v">8080</span></div>
<div class="info-row"><span class="k">审计系统</span><span class="v">8000</span></div>
<div class="info-row"><span class="k">风险系统</span><span class="v">8001</span></div>
<div class="info-row"><span class="k">合同审核</span><span class="v">8090</span></div>
<div class="info-row"><span class="k">审计数据库</span><span class="v" id="auditDb">-</span></div>
<div class="info-row"><span class="k">风险数据库</span><span class="v" id="riskDb">-</span></div>
<div class="info-row"><span class="k">知识库数据库</span><span class="v">与审计共库</span></div>
</div>
</div>
<script>
function showMsg(id, text, ok) {
const el = document.getElementById(id);
el.textContent = text;
el.className = 'msg ' + (ok ? 'ok' : 'err');
}
async function loadSettings() {
try {
const r = await fetch('/api/settings');
if (!r.ok) throw new Error('HTTP ' + r.status);
const s = await r.json();
document.getElementById('llmBaseUrl').value = s.llm.base_url || '';
document.getElementById('llmModel').value = s.llm.model || '';
document.getElementById('llmApiKey').placeholder = s.llm.api_key_set
? '留空表示不修改(当前:' + s.llm.api_key_masked + ')'
: '留空表示不修改(当前:未设置,使用默认 Key)';
document.getElementById('modAudit').checked = !!s.modules.audit;
document.getElementById('modRisk').checked = !!s.modules.risk;
document.getElementById('modKnowledge').checked = !!s.modules.knowledge;
document.getElementById('modContract').checked = !!s.modules.contract;
document.getElementById('accountName').textContent = s.account.username || '-';
document.getElementById('auditDb').textContent = (s.system.audit_db_mb || 0) + ' MB';
document.getElementById('riskDb').textContent = (s.system.risk_db_mb || 0) + ' MB';
} catch (e) {
showMsg('llmMsg', '读取配置失败:' + e.message, false);
}
}
async function saveLLM() {
const fd = new FormData();
fd.append('base_url', document.getElementById('llmBaseUrl').value.trim());
fd.append('model', document.getElementById('llmModel').value.trim());
fd.append('api_key', document.getElementById('llmApiKey').value.trim());
try {
const r = await fetch('/api/settings/llm', { method: 'POST', body: fd });
const d = await r.json();
if (!r.ok) throw new Error(d.detail || '保存失败');
showMsg('llmMsg', d.message, true);
document.getElementById('llmApiKey').value = '';
loadSettings();
} catch (e) {
showMsg('llmMsg', e.message, false);
}
}
async function saveModules() {
const fd = new FormData();
fd.append('audit', document.getElementById('modAudit').checked ? 'on' : 'off');
fd.append('risk', document.getElementById('modRisk').checked ? 'on' : 'off');
fd.append('knowledge', document.getElementById('modKnowledge').checked ? 'on' : 'off');
fd.append('contract', document.getElementById('modContract').checked ? 'on' : 'off');
try {
const r = await fetch('/api/settings/modules', { method: 'POST', body: fd });
const d = await r.json();
if (!r.ok) throw new Error(d.detail || '保存失败');
showMsg('modMsg', d.message, true);
} catch (e) {
showMsg('modMsg', e.message, false);
}
}
async function savePassword() {
const cur = document.getElementById('curPassword').value;
const n1 = document.getElementById('newPassword').value;
const n2 = document.getElementById('newPassword2').value;
if (!cur) return showMsg('pwdMsg', '请输入当前密码', false);
if (n1.length < 6) return showMsg('pwdMsg', '新密码至少 6 位', false);
if (n1 !== n2) return showMsg('pwdMsg', '两次输入的新密码不一致', false);
const fd = new FormData();
fd.append('current_password', cur);
fd.append('new_password', n1);
try {
const r = await fetch('/api/settings/password', { method: 'POST', body: fd });
const d = await r.json();
if (!r.ok) throw new Error(d.detail || '修改失败');
showMsg('pwdMsg', d.message, true);
document.getElementById('curPassword').value = '';
document.getElementById('newPassword').value = '';
document.getElementById('newPassword2').value = '';
} catch (e) {
showMsg('pwdMsg', e.message, false);
}
}
function togglePwd(id, btn) {
const el = document.getElementById(id);
if (!el) return;
const show = el.type === 'password';
el.type = show ? 'text' : 'password';
btn.innerHTML = show ? '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/><path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/><path d="M14.12 14.12a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>' : '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';
btn.setAttribute('aria-label', show ? '隐藏密码' : '显示密码');
}
loadSettings();
</script>
<script>
// ==================== 用户与角色权限 ====================
let ROLES = [];
async function loadUsers() {
try {
const r = await fetch('/api/users');
if (r.status === 403) {
document.getElementById('userCard').innerHTML = '<h3>👥 用户与角色权限</h3><div class="hint">仅系统管理员可管理用户与权限。</div>';
return;
}
const users = await r.json();
window._users = users;
ROLES = await fetch('/api/roles').then(x => x.json());
document.getElementById('roleSummary').textContent = '角色:' + ROLES.map(x => x.name + '(' + (x.permissions || []).join('/') + ')').join(';');
renderUsers(users);
} catch (e) {
document.getElementById('userMsg').textContent = '读取用户失败:' + e.message;
}
}
function renderUsers(users) {
window._users = users;
const el = document.getElementById('userList');
if (!users.length) { el.innerHTML = '<div class="foot-note">暂无用户</div>'; return; }
el.innerHTML = users.map(u => `
<div class="info-row" style="align-items:center">
<span class="k">${esc(u.username)}${u.display_name ? '(' + esc(u.display_name) + ')' : ''}</span>
<span class="v">${esc(u.role_name || u.role_code || '-')} · ${esc(u.status)}</span>
<span style="display:flex;gap:6px">
<button class="btn" style="padding:4px 10px;font-size:12px" onclick="openUserForm(${u.id})">编辑</button>
<button class="btn" style="padding:4px 10px;font-size:12px" onclick="resetUserPwd(${u.id})">重置密码</button>
<button class="btn" style="padding:4px 10px;font-size:12px;background:rgba(255,80,80,.12)" onclick="deleteUser(${u.id})">删除</button>
</span>
</div>`).join('');
}
function esc(s){return String(s==null?'':s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));}
function openUserForm(id) {
const sel = document.getElementById('ufRole');
sel.innerHTML = ROLES.map(r => `<option value="${r.id}">${esc(r.name)}</option>`).join('');
const users = window._users || [];
const u = id ? users.find(x => x.id === id) : null;
document.getElementById('ufId').value = u ? u.id : '';
document.getElementById('ufUsername').value = u ? u.username : '';
document.getElementById('ufUsername').disabled = !!u;
document.getElementById('ufDisplay').value = u ? (u.display_name || '') : '';
document.getElementById('ufStatus').value = u ? u.status : '启用';
if (u && u.role_id) sel.value = u.role_id;
document.getElementById('ufPassword').value = '';
document.getElementById('userForm').style.display = 'block';
}
function cancelUserForm(){ document.getElementById('userForm').style.display='none'; }
async function saveUser() {
const data = {
id: document.getElementById('ufId').value ? Number(document.getElementById('ufId').value) : null,
username: document.getElementById('ufUsername').value.trim(),
display_name: document.getElementById('ufDisplay').value.trim(),
role_id: Number(document.getElementById('ufRole').value),
status: document.getElementById('ufStatus').value,
password: document.getElementById('ufPassword').value
};
if (!data.id && !data.password) { showMsg('userMsg','新建用户必须设置密码',false); return; }
const r = await fetch('/api/users', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});
const d = await r.json().catch(()=>({}));
if (!r.ok) { showMsg('userMsg','保存失败:'+(d.detail||r.status),false); return; }
showMsg('userMsg','用户已保存',true);
document.getElementById('userForm').style.display='none';
loadUsers();
}
async function resetUserPwd(id) {
const pwd = prompt('请输入新密码(至少 6 位):');
if (!pwd) return;
const r = await fetch(`/api/users/${id}/reset-password`, {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:pwd})});
showMsg('userMsg', r.ok ? '密码已重置' : '重置失败', r.ok);
}
async function deleteUser(id) {
if (!confirm('确认删除该用户?删除后该账号无法登录。')) return;
const r = await fetch(`/api/users/${id}`, {method:'DELETE'});
const d = await r.json().catch(()=>({}));
if (!r.ok) { showMsg('userMsg','删除失败:'+(d.detail||r.status),false); return; }
showMsg('userMsg','用户已删除',true); loadUsers();
}
loadUsers();
</script>
<style id="platform-embed-style">
/* shared/embed_theme.css — 统一平台外壳嵌入主题(唯一来源)
* 由 deploy/同步统一主题.py 注入到各业务页面的 <style id="platform-embed-style">。
* 规则:只隐藏子系统顶栏,保留业务侧栏(项目树/风险菜单/合同功能/知识库分类)。
*/
body.embedded .app-header,
body.embedded .topbar { display:none !important; }
body.embedded { background:#0a1622 !important; }
body.embedded #portalBackBtn,
body.embedded #portalTopBack { display:none !important; }
body.embedded .main-content,
body.embedded .main-area,
body.embedded .main { background:transparent !important; }
body.embedded iframe { border:0; }
body.embedded .sidebar { height:100vh !important; top:0 !important; }
body.embedded .main-content,
body.embedded .main-area { height:100vh !important; }
body.embedded .app-body { min-height:100vh !important; }
body.embedded .layout { min-height:100vh !important; }
/* ===== 统一组件细节(颜色跟随各页面主题,不改变原有配色) ===== */
body.embedded button,
body.embedded .btn { border-radius:8px; transition:background .15s ease, border-color .15s ease, transform .1s ease; }
body.embedded button:active,
body.embedded .btn:active { transform:translateY(1px); }
body.embedded button:focus-visible,
body.embedded .btn:focus-visible,
body.embedded a:focus-visible { outline:2px solid currentColor; outline-offset:2px; }
body.embedded input:focus,
body.embedded select:focus,
body.embedded textarea:focus { outline:2px solid rgba(79,209,255,.5); outline-offset:1px; }
body.embedded table tbody tr { transition:background .12s ease; }
body.embedded .empty { padding:26px 12px; text-align:center; border-radius:10px; }
</style>
<script id="platform-embed-script">
(function(){
try {
var embedded = location.search.indexOf('embed=1') >= 0 || window.self !== window.top;
if (embedded) {
document.addEventListener('DOMContentLoaded', function(){ document.body.classList.add('embedded'); });
if (document.body) document.body.classList.add('embedded');
}
} catch(e) {}
})();
</script>
</body>
</html>