feat(api): Key 改为明文保存可随时复制,新增口令列与一键复制接入信息(地址+使用者+口令)
This commit is contained in:
+67
-10
@@ -129,7 +129,7 @@ button { font-family: inherit; cursor: pointer; }
|
||||
}
|
||||
|
||||
.tbl-wrap { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; min-width: 860px; }
|
||||
table { width: 100%; border-collapse: collapse; min-width: 1000px; }
|
||||
th, td { padding: 11px 14px; text-align: left; vertical-align: middle; }
|
||||
th {
|
||||
font-size: 11px; font-weight: 500; color: var(--text-faint);
|
||||
@@ -142,6 +142,18 @@ tbody tr:hover { background: #fafbff; }
|
||||
.sub { margin-top: 2px; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
|
||||
.note { max-width: 200px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
|
||||
.key-cell { white-space: nowrap; }
|
||||
.key-val {
|
||||
display: inline-block; margin-right: 6px; padding: 2px 6px;
|
||||
font-family: var(--mono); font-size: 10.5px; color: #4b5563;
|
||||
background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
|
||||
}
|
||||
.key-old { font-size: 11px; color: var(--text-faint); }
|
||||
.tip {
|
||||
margin: 12px 16px 0; padding: 9px 12px;
|
||||
font-size: 11.5px; line-height: 1.6; color: #92400e;
|
||||
background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
|
||||
}
|
||||
.pill {
|
||||
display: inline-flex; align-items: center; gap: 5px;
|
||||
padding: 2px 8px; font-size: 11px; border-radius: 999px; white-space: nowrap;
|
||||
@@ -244,11 +256,13 @@ tbody tr:hover { background: #fafbff; }
|
||||
<input id="filter" type="search" placeholder="筛选使用者 / 备注">
|
||||
<button class="btn sm" id="btn-refresh">刷新</button>
|
||||
</div>
|
||||
<div class="tip" id="old-tip" hidden>早期生成的 Key 只保存了哈希,无法查看明文。如需复制接入信息,请重新生成一个(旧 Key 可删除)。</div>
|
||||
<div class="tbl-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>使用者</th>
|
||||
<th>口令</th>
|
||||
<th>备注</th>
|
||||
<th>状态</th>
|
||||
<th>限额</th>
|
||||
@@ -307,10 +321,11 @@ tbody tr:hover { background: #fafbff; }
|
||||
<h3>✅ API Key 已生成</h3>
|
||||
<p class="hint" id="key-for"></p>
|
||||
<div class="key-box" id="key-value"></div>
|
||||
<div class="key-warn">明文只显示这一次。关闭后无法再查看,只能重新生成。请立即复制并妥善保存。</div>
|
||||
<div class="key-warn">内部使用:该口令已明文保存在服务器,可随时在本页复制。请勿发到公开群聊或写进前端代码。</div>
|
||||
<div class="modal-foot">
|
||||
<button class="btn" id="btn-copy">复制 Key</button>
|
||||
<button class="btn primary" id="btn-close-key">我已保存</button>
|
||||
<button class="btn" id="btn-copy">仅复制口令</button>
|
||||
<button class="btn primary" id="btn-copy-info">复制接入信息</button>
|
||||
<button class="btn" id="btn-close-key">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -324,6 +339,10 @@ tbody tr:hover { background: #fafbff; }
|
||||
var token = '';
|
||||
var keys = [];
|
||||
var editingId = null;
|
||||
var lastCreated = null;
|
||||
|
||||
// 对外接入地址(复制给调用方用)
|
||||
var API_ENDPOINT = 'https://drawlogo.zhuig.com/api/v1';
|
||||
|
||||
// 本地预览时直连本地 API;线上同源
|
||||
var IS_LOCAL = /^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname);
|
||||
@@ -335,6 +354,18 @@ tbody tr:hover { background: #fafbff; }
|
||||
});
|
||||
}
|
||||
|
||||
/** 口令掩码:前 10 + 后 6 */
|
||||
function maskKey(k) {
|
||||
if (!k) return '';
|
||||
if (k.length <= 20) return k;
|
||||
return k.slice(0, 10) + '…' + k.slice(-6);
|
||||
}
|
||||
|
||||
/** 一键复制用的接入信息(地址 + 使用者 + 口令) */
|
||||
function infoText(rec) {
|
||||
return '画个标素材 API\n地址:' + API_ENDPOINT + '\n使用者:' + rec.name + '\n口令:' + rec.key;
|
||||
}
|
||||
|
||||
function api(path, opts) {
|
||||
opts = opts || {};
|
||||
opts.headers = Object.assign({ 'X-Admin-Token': token }, opts.headers || {});
|
||||
@@ -422,6 +453,7 @@ tbody tr:hover { background: #fafbff; }
|
||||
return (k.name + ' ' + (k.note || '') + ' ' + k.id).toLowerCase().indexOf(q) !== -1;
|
||||
});
|
||||
|
||||
$('#old-tip').hidden = !keys.some(function (k) { return !k.key; });
|
||||
$('#empty').hidden = list.length > 0;
|
||||
$('#rows').innerHTML = list.map(function (k) {
|
||||
var expired = isExpired(k);
|
||||
@@ -430,6 +462,12 @@ tbody tr:hover { background: #fafbff; }
|
||||
: '<span class="pill ok">启用中</span>';
|
||||
return '<tr data-id="' + esc(k.id) + '">' +
|
||||
'<td><div class="name">' + esc(k.name) + '</div><div class="sub">' + esc(k.id) + '</div></td>' +
|
||||
'<td class="key-cell">' +
|
||||
(k.key
|
||||
? '<code class="key-val" title="' + esc(k.key) + '">' + esc(maskKey(k.key)) + '</code>' +
|
||||
'<button class="btn sm" data-act="copy">复制</button>'
|
||||
: '<span class="key-old">不可查看</span>') +
|
||||
'</td>' +
|
||||
'<td class="note" title="' + esc(k.note) + '">' + (k.note ? esc(k.note) : '<span style="color:#c3c9d2">—</span>') + '</td>' +
|
||||
'<td>' + pill + '</td>' +
|
||||
'<td><span class="mono">' + k.ratePerMin + '</span><span style="color:#9ca3af">/分</span><br>' +
|
||||
@@ -499,6 +537,7 @@ tbody tr:hover { background: #fafbff; }
|
||||
req.then(function (d) {
|
||||
closeForm();
|
||||
if (!editingId && d && d.key) {
|
||||
lastCreated = d.record;
|
||||
$('#key-for').textContent = '使用者:' + d.record.name + '(' + d.record.id + ')';
|
||||
$('#key-value').textContent = d.key;
|
||||
$('#key-mask').hidden = false;
|
||||
@@ -545,18 +584,31 @@ tbody tr:hover { background: #fafbff; }
|
||||
$('#btn-save').addEventListener('click', save);
|
||||
|
||||
$('#btn-close-key').addEventListener('click', function () { $('#key-mask').hidden = true; });
|
||||
|
||||
$('#btn-copy').addEventListener('click', function () {
|
||||
var text = $('#key-value').textContent;
|
||||
var done = function () {
|
||||
$('#btn-copy').textContent = '已复制 ✓';
|
||||
setTimeout(function () { $('#btn-copy').textContent = '复制 Key'; }, 1600);
|
||||
};
|
||||
var btn = this;
|
||||
copyText($('#key-value').textContent, function () { flash(btn, '已复制口令'); });
|
||||
});
|
||||
|
||||
$('#btn-copy-info').addEventListener('click', function () {
|
||||
var btn = this;
|
||||
if (!lastCreated || !lastCreated.key) return;
|
||||
copyText(infoText(lastCreated), function () { flash(btn, '已复制接入信息'); });
|
||||
});
|
||||
|
||||
function copyText(text, done) {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(done).catch(function () { fallbackCopy(text, done); });
|
||||
} else {
|
||||
fallbackCopy(text, done);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function flash(btn, text) {
|
||||
var old = btn.textContent;
|
||||
btn.textContent = text || '已复制';
|
||||
setTimeout(function () { btn.textContent = old; }, 1500);
|
||||
}
|
||||
|
||||
function fallbackCopy(text, done) {
|
||||
var ta = document.createElement('textarea');
|
||||
@@ -577,6 +629,11 @@ tbody tr:hover { background: #fafbff; }
|
||||
if (!tr) return;
|
||||
var id = tr.getAttribute('data-id');
|
||||
var act = btn.getAttribute('data-act');
|
||||
if (act === 'copy') {
|
||||
var r = keys.filter(function (k) { return k.id === id; })[0];
|
||||
if (r && r.key) copyText(infoText(r), function () { flash(btn); });
|
||||
return;
|
||||
}
|
||||
if (act === 'toggle') toggle(id);
|
||||
else if (act === 'del') remove(id);
|
||||
else if (act === 'edit') {
|
||||
|
||||
Reference in New Issue
Block a user