feat(admin): API 文档区添加生成 TOKEN 功能
- 在 API 接口面板顶部增加「生成 TOKEN」按钮 - 一键获取 Token,可复制用于 curl/Skill 上传新章节 - souladmin 域名下自动使用同源 /api 代理 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
29
soul-admin/dist/index.html
vendored
29
soul-admin/dist/index.html
vendored
@@ -31,6 +31,13 @@
|
||||
.si-api pre{background:#0a0e17;border:1px solid #1e293b;border-radius:6px;padding:12px;
|
||||
overflow-x:auto;margin:6px 0 14px;font-size:12px;color:#2dd4a8;white-space:pre-wrap}
|
||||
.si-api h4{color:#e0e6ed;font-size:13px;margin:16px 0 4px;font-family:sans-serif}
|
||||
.si-token-box{background:#0a0e17;border:1px solid #2dd4a8;border-radius:8px;padding:14px;margin-bottom:20px}
|
||||
.si-token-box .si-token-row{display:flex;gap:8px;align-items:center;margin-top:8px}
|
||||
.si-token-box input{flex:1;padding:8px 10px;background:#111827;border:1px solid #1e293b;border-radius:6px;color:#2dd4a8;font-size:12px;font-family:monospace}
|
||||
.si-token-btn{padding:8px 16px;border-radius:6px;font-size:13px;cursor:pointer;border:none;background:#2dd4a8;color:#0a0e17;font-weight:600}
|
||||
.si-token-btn:hover{background:#22b896}
|
||||
.si-token-btn.copy{background:#1e293b;color:#e0e6ed}
|
||||
.si-token-btn.copy:hover{background:#334155}
|
||||
.si-toast{position:fixed;top:16px;right:16px;padding:10px 18px;border-radius:6px;
|
||||
font-size:13px;z-index:99999;animation:siFade .25s}
|
||||
.si-toast.ok{background:#065f46;color:#6ee7b7}
|
||||
@@ -39,7 +46,7 @@
|
||||
`;
|
||||
document.head.appendChild(CSS);
|
||||
|
||||
var API='https://souldev.quwanzhi.com';
|
||||
var API=(window.location.hostname||'').indexOf('souladmin')>=0?'':'https://souldev.quwanzhi.com';
|
||||
var token=localStorage.getItem('admin_token')||'';
|
||||
|
||||
function toast(m,ok){var t=document.createElement('div');t.className='si-toast '+(ok!==false?'ok':'err');
|
||||
@@ -142,6 +149,10 @@
|
||||
apiP.className='si-panel';apiP.id='si-apidoc';apiP.style.display='none';
|
||||
apiP.innerHTML='<div class="si-api">'
|
||||
+'<h3 style="font-family:sans-serif">内容管理 API 接口文档</h3>'
|
||||
+'<div class="si-token-box"><strong style="color:#e0e6ed">生成 TOKEN</strong> — 用于上传新章节、删除等操作<br>'
|
||||
+'<div class="si-token-row"><button class="si-token-btn" id="si-gen-token">生成 TOKEN</button>'
|
||||
+'<input type="text" id="si-token-input" readonly placeholder="点击生成后显示,可复制用于 curl/Skill 上传" style="cursor:pointer">'
|
||||
+'<button class="si-token-btn copy" id="si-copy-token">复制</button></div></div>'
|
||||
+'<p>基础域名: <code>https://soulapi.quwanzhi.com</code> (正式) / <code>https://souldev.quwanzhi.com</code> (开发)</p>'
|
||||
+'<h4>1. 获取所有章节 (无需认证)</h4><pre>GET /api/book/all-chapters\n\ncurl https://soulapi.quwanzhi.com/api/book/all-chapters</pre>'
|
||||
+'<h4>2. 获取单章内容</h4><pre>GET /api/book/chapter/:id\n\ncurl https://soulapi.quwanzhi.com/api/book/chapter/1.1</pre>'
|
||||
@@ -153,6 +164,22 @@
|
||||
+'</div>';
|
||||
insertTarget.parentElement.insertBefore(apiP,insertTarget);
|
||||
|
||||
document.getElementById('si-gen-token').onclick=function(){
|
||||
var inp=document.getElementById('si-token-input');
|
||||
inp.value='获取中...';
|
||||
doLogin().then(function(ok){
|
||||
if(ok&&token){inp.value=token;toast('TOKEN 已生成,可复制使用')}
|
||||
else{inp.value='';toast('获取失败',false)}
|
||||
});
|
||||
};
|
||||
document.getElementById('si-copy-token').onclick=function(){
|
||||
var inp=document.getElementById('si-token-input');
|
||||
if(!inp.value||inp.value==='获取中...'){toast('请先生成 TOKEN',false);return}
|
||||
inp.select();document.execCommand('copy');
|
||||
toast('已复制到剪贴板');
|
||||
};
|
||||
document.getElementById('si-token-input').onclick=function(){this.select()};
|
||||
|
||||
// === 3. 给每个章节添加删除按钮 ===
|
||||
addDelBtns();
|
||||
new MutationObserver(function(){addDelBtns()}).observe(document.getElementById('root'),{childList:true,subtree:true});
|
||||
|
||||
Reference in New Issue
Block a user