0203a65973
Co-authored-by: Cursor <cursoragent@cursor.com>
474 lines
12 KiB
HTML
474 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>API 密钥管理</title>
|
|
<style>
|
|
:root {
|
|
--bg: #0d0d0f;
|
|
--surface: #16161a;
|
|
--surface-hover: #1c1c22;
|
|
--border: #2a2a32;
|
|
--text: #e4e4e7;
|
|
--text-muted: #71717a;
|
|
--accent: #3b82f6;
|
|
--accent-hover: #2563eb;
|
|
--success: #22c55e;
|
|
--danger: #ef4444;
|
|
--radius: 8px;
|
|
--font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
|
--mono: "Cascadia Code", "Consolas", "SF Mono", monospace;
|
|
}
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body {
|
|
font-family: var(--font);
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
min-height: 100vh;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.wrap {
|
|
max-width: 960px;
|
|
margin: 0 auto;
|
|
padding: 32px 20px 48px;
|
|
}
|
|
|
|
header {
|
|
margin-bottom: 32px;
|
|
padding-bottom: 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
header p {
|
|
margin-top: 6px;
|
|
font-size: 0.875rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.panel {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 20px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.panel h2 {
|
|
font-size: 0.8125rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.06em;
|
|
color: var(--text-muted);
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.form-grid {
|
|
display: grid;
|
|
gap: 12px;
|
|
}
|
|
|
|
@media (min-width: 640px) {
|
|
.form-grid { grid-template-columns: 1fr 1fr 1fr; }
|
|
.form-actions { grid-column: 1 / -1; }
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 10px 12px;
|
|
background: var(--bg);
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
color: var(--text);
|
|
font-family: var(--mono);
|
|
font-size: 0.8125rem;
|
|
}
|
|
|
|
input:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 6px;
|
|
padding: 8px 14px;
|
|
font-size: 0.8125rem;
|
|
font-weight: 500;
|
|
border: none;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
transition: background 0.15s, color 0.15s;
|
|
font-family: var(--font);
|
|
}
|
|
|
|
.btn-primary {
|
|
background: var(--accent);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn-primary:hover { background: var(--accent-hover); }
|
|
|
|
.btn-ghost {
|
|
background: transparent;
|
|
color: var(--text-muted);
|
|
border: 1px solid var(--border);
|
|
}
|
|
|
|
.btn-ghost:hover {
|
|
background: var(--surface-hover);
|
|
color: var(--text);
|
|
}
|
|
|
|
.btn-copy {
|
|
background: var(--bg);
|
|
color: var(--text-muted);
|
|
border: 1px solid var(--border);
|
|
padding: 4px 10px;
|
|
font-size: 0.75rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.btn-copy:hover {
|
|
color: var(--text);
|
|
border-color: var(--accent);
|
|
}
|
|
|
|
.btn-copy.copied {
|
|
color: var(--success);
|
|
border-color: var(--success);
|
|
}
|
|
|
|
.btn-danger {
|
|
background: transparent;
|
|
color: var(--danger);
|
|
border: 1px solid transparent;
|
|
padding: 4px 8px;
|
|
font-size: 0.75rem;
|
|
}
|
|
|
|
.btn-danger:hover {
|
|
background: rgba(239, 68, 68, 0.1);
|
|
border-color: var(--danger);
|
|
}
|
|
|
|
.toolbar {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.toolbar .count {
|
|
font-size: 0.8125rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.toggle-mask {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 0.8125rem;
|
|
color: var(--text-muted);
|
|
cursor: pointer;
|
|
user-select: none;
|
|
}
|
|
|
|
.toggle-mask input { width: auto; accent-color: var(--accent); }
|
|
|
|
.account-list { display: flex; flex-direction: column; gap: 12px; }
|
|
|
|
.account-card {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 16px;
|
|
}
|
|
|
|
.account-card:hover { border-color: #3f3f48; }
|
|
|
|
.account-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 12px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
.account-name {
|
|
font-weight: 600;
|
|
font-size: 0.9375rem;
|
|
}
|
|
|
|
.field {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.field:last-child { margin-bottom: 0; }
|
|
|
|
.field-label {
|
|
width: 88px;
|
|
flex-shrink: 0;
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.field-value {
|
|
flex: 1;
|
|
min-width: 0;
|
|
font-family: var(--mono);
|
|
font-size: 0.8125rem;
|
|
word-break: break-all;
|
|
color: var(--text);
|
|
}
|
|
|
|
.empty {
|
|
text-align: center;
|
|
padding: 48px 20px;
|
|
color: var(--text-muted);
|
|
font-size: 0.875rem;
|
|
border: 1px dashed var(--border);
|
|
border-radius: var(--radius);
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
bottom: 24px;
|
|
right: 24px;
|
|
padding: 10px 16px;
|
|
background: var(--surface);
|
|
border: 1px solid var(--success);
|
|
color: var(--success);
|
|
border-radius: 6px;
|
|
font-size: 0.8125rem;
|
|
opacity: 0;
|
|
transform: translateY(8px);
|
|
transition: opacity 0.2s, transform 0.2s;
|
|
pointer-events: none;
|
|
z-index: 100;
|
|
}
|
|
|
|
.toast.show {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.error-msg {
|
|
color: var(--danger);
|
|
font-size: 0.8125rem;
|
|
margin-top: 8px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<header>
|
|
<h1>API 密钥管理</h1>
|
|
<p>本地多账户存储 · 数据保存在 data.json</p>
|
|
</header>
|
|
|
|
<section class="panel">
|
|
<h2>添加账户</h2>
|
|
<form id="addForm" class="form-grid">
|
|
<div>
|
|
<label for="username">账户名称 (username)</label>
|
|
<input type="text" id="username" name="username" placeholder="例如: main_account" autocomplete="off" required>
|
|
</div>
|
|
<div>
|
|
<label for="api_key">API Key</label>
|
|
<input type="text" id="api_key" name="api_key" placeholder="输入 API Key" autocomplete="off" required>
|
|
</div>
|
|
<div>
|
|
<label for="api_secret">API Secret</label>
|
|
<input type="text" id="api_secret" name="api_secret" placeholder="输入 API Secret" autocomplete="off" required>
|
|
</div>
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">添加账户</button>
|
|
<p id="formError" class="error-msg" hidden></p>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<section>
|
|
<div class="toolbar">
|
|
<span class="count" id="accountCount">共 0 个账户</span>
|
|
<label class="toggle-mask">
|
|
<input type="checkbox" id="maskToggle">
|
|
隐藏敏感字段(复制仍为明文)
|
|
</label>
|
|
</div>
|
|
<div id="accountList" class="account-list"></div>
|
|
</section>
|
|
</div>
|
|
|
|
<div id="toast" class="toast">已复制到剪贴板</div>
|
|
|
|
<script>
|
|
const API = "/api/accounts";
|
|
let accounts = [];
|
|
let masked = false;
|
|
|
|
const listEl = document.getElementById("accountList");
|
|
const countEl = document.getElementById("accountCount");
|
|
const maskToggle = document.getElementById("maskToggle");
|
|
const toast = document.getElementById("toast");
|
|
const form = document.getElementById("addForm");
|
|
const formError = document.getElementById("formError");
|
|
|
|
function maskValue(value) {
|
|
if (!masked || !value) return value;
|
|
return "•".repeat(Math.min(value.length, 24));
|
|
}
|
|
|
|
function showToast(msg) {
|
|
toast.textContent = msg;
|
|
toast.classList.add("show");
|
|
clearTimeout(showToast._t);
|
|
showToast._t = setTimeout(() => toast.classList.remove("show"), 1800);
|
|
}
|
|
|
|
async function copyText(text, btn) {
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
btn.classList.add("copied");
|
|
btn.textContent = "已复制";
|
|
showToast("已复制到剪贴板");
|
|
setTimeout(() => {
|
|
btn.classList.remove("copied");
|
|
btn.textContent = "复制";
|
|
}, 1500);
|
|
} catch {
|
|
const ta = document.createElement("textarea");
|
|
ta.value = text;
|
|
document.body.appendChild(ta);
|
|
ta.select();
|
|
document.execCommand("copy");
|
|
document.body.removeChild(ta);
|
|
showToast("已复制到剪贴板");
|
|
}
|
|
}
|
|
|
|
function renderField(label, value, copyLabel) {
|
|
const row = document.createElement("div");
|
|
row.className = "field";
|
|
row.innerHTML = `
|
|
<span class="field-label">${label}</span>
|
|
<span class="field-value"></span>
|
|
`;
|
|
row.querySelector(".field-value").textContent = maskValue(value);
|
|
|
|
const btn = document.createElement("button");
|
|
btn.type = "button";
|
|
btn.className = "btn btn-copy";
|
|
btn.textContent = "复制";
|
|
btn.title = `复制${copyLabel}`;
|
|
btn.addEventListener("click", () => copyText(value, btn));
|
|
row.appendChild(btn);
|
|
return row;
|
|
}
|
|
|
|
function renderAccount(acc) {
|
|
const card = document.createElement("article");
|
|
card.className = "account-card";
|
|
card.dataset.id = acc.id;
|
|
|
|
const header = document.createElement("div");
|
|
header.className = "account-header";
|
|
header.innerHTML = `<span class="account-name"></span>`;
|
|
header.querySelector(".account-name").textContent = maskValue(acc.username);
|
|
|
|
const delBtn = document.createElement("button");
|
|
delBtn.type = "button";
|
|
delBtn.className = "btn btn-danger";
|
|
delBtn.textContent = "删除";
|
|
delBtn.addEventListener("click", () => deleteAccount(acc.id));
|
|
header.appendChild(delBtn);
|
|
card.appendChild(header);
|
|
|
|
card.appendChild(renderField("账户名称", acc.username, "账户名称"));
|
|
card.appendChild(renderField("API Key", acc.api_key, "API Key"));
|
|
card.appendChild(renderField("API Secret", acc.api_secret, "API Secret"));
|
|
|
|
return card;
|
|
}
|
|
|
|
function renderList() {
|
|
countEl.textContent = `共 ${accounts.length} 个账户`;
|
|
listEl.innerHTML = "";
|
|
if (accounts.length === 0) {
|
|
listEl.innerHTML = '<div class="empty">暂无账户,请在上方添加</div>';
|
|
return;
|
|
}
|
|
accounts.forEach(acc => listEl.appendChild(renderAccount(acc)));
|
|
}
|
|
|
|
async function loadAccounts() {
|
|
const res = await fetch(API);
|
|
accounts = await res.json();
|
|
renderList();
|
|
}
|
|
|
|
async function deleteAccount(id) {
|
|
if (!confirm("确定删除该账户?")) return;
|
|
await fetch(`${API}/${id}`, { method: "DELETE" });
|
|
accounts = accounts.filter(a => a.id !== id);
|
|
renderList();
|
|
}
|
|
|
|
form.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
formError.hidden = true;
|
|
const payload = {
|
|
username: document.getElementById("username").value,
|
|
api_key: document.getElementById("api_key").value,
|
|
api_secret: document.getElementById("api_secret").value,
|
|
};
|
|
const res = await fetch(API, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
const data = await res.json();
|
|
if (!res.ok) {
|
|
formError.textContent = data.error || "添加失败";
|
|
formError.hidden = false;
|
|
return;
|
|
}
|
|
accounts.push(data);
|
|
form.reset();
|
|
renderList();
|
|
showToast("账户已添加");
|
|
});
|
|
|
|
maskToggle.addEventListener("change", () => {
|
|
masked = maskToggle.checked;
|
|
renderList();
|
|
});
|
|
|
|
loadAccounts();
|
|
</script>
|
|
</body>
|
|
</html>
|