feat(admin): 管理面信封化+分页化,OpenAPI 文档端点旁路(B1-B6)
build / build-push (push) Successful in 1m59s

- pom: 引 yh-platform-dependencies(import) / yh-api-std / springdoc-openapi-ui 1.7.0 + nexus-public 仓库
- RoutingFilter.isGatewayInternal: /v3/api-docs、/swagger-ui/**、/swagger-ui.html 纳入自身路径旁路,避免被 TargetRouter 当 target 裸 404
- InternalAdminController: page/routes/targets/logs 三接口分页化返回 BasePageResult;补 @Operation(operationId=GatewayAdmin.*);错误契约去 @ResponseStatus(400) 改 200+code=2;logs 兼容旧 limit 入参
- RouteRefreshController: 补 @Tag/@Operation(operationId=GatewayAdmin.refresh)
- static/admin.html: 适配 {code,msg,data} 信封与 content/total 分页
- InternalAdminControllerTest: 重写 12 用例,77 项测试全绿
This commit is contained in:
chenxing
2026-09-23 12:17:02 +08:00
parent 6e64acc0c7
commit 2389d2fa9a
6 changed files with 198 additions and 67 deletions
+19 -13
View File
@@ -106,6 +106,7 @@ function toast(msg, isErr) {
setTimeout(function(){ t.className = ''; }, isErr ? 4200 : 2200);
}
/* 管理面响应 = 平台信封 {code,msg,data}(yh-api-std 统一包装);成功时把 data 交给调用方 */
function api(method, url, body) {
var opt = { method: method, headers: {} };
if (body !== undefined) {
@@ -113,9 +114,10 @@ function api(method, url, body) {
opt.body = JSON.stringify(body);
}
return fetch(url, opt).then(function(r) {
return r.json().catch(function(){ return {}; }).then(function(j) {
if (!r.ok) { throw new Error(j.msg || ('HTTP ' + r.status)); }
return j;
if (!r.ok) { throw new Error('HTTP ' + r.status); }
return r.json().then(function(j) {
if (j.code !== 0) { throw new Error(j.msg || ('业务错误 code=' + j.code)); }
return j.data;
});
});
}
@@ -128,7 +130,8 @@ function esc(s) {
/* ---------- 路由表 ---------- */
function loadRoutes() {
return api('GET', 'routes').then(function(rows) {
return api('GET', 'routes?pageIndex=1&pageSize=200').then(function(pg) {
var rows = (pg && pg.content) || [];
var tb = $('routeT').tBodies[0];
tb.innerHTML = rows.map(function(r) { return routeRow(r); }).join('');
});
@@ -167,13 +170,14 @@ function saveRoute(btn) {
else { body[k] = el.value; }
});
api('PUT', 'routes/' + tr.dataset.id, body)
.then(function(j) { toast('已保存,注册表加载 ' + j.loaded + ' 条路由'); })
.then(function(d) { toast('已保存,注册表加载 ' + d.loaded + ' 条路由'); })
.catch(function(e) { toast('保存失败:' + e.message, true); });
}
/* ---------- 目标表 ---------- */
function loadTargets() {
return api('GET', 'targets').then(function(rows) {
return api('GET', 'targets?pageIndex=1&pageSize=200').then(function(pg) {
var rows = (pg && pg.content) || [];
var tb = $('tgtT').tBodies[0];
tb.innerHTML = rows.map(function(t) {
return '<tr data-id="' + t.id + '">'
@@ -195,23 +199,25 @@ function saveTarget(btn) {
body[k] = el.type === 'checkbox' ? el.checked : el.value;
});
api('PUT', 'targets/' + tr.dataset.id, body)
.then(function(j) { toast('已保存,目标表加载 ' + j.targets + ' 条'); })
.then(function(d) { toast('已保存,目标表加载 ' + d.targets + ' 条'); })
.catch(function(e) { toast('保存失败:' + e.message, true); });
}
/* ---------- 台账 ---------- */
function loadLogs() {
var q = 'logs?limit=' + (parseInt($('qLimit').value || '50', 10) || 50);
var size = parseInt($('qLimit').value || '50', 10) || 50;
var q = 'logs?pageIndex=1&pageSize=' + size;
if ($('qTarget').value.trim()) q += '&targetCode=' + encodeURIComponent($('qTarget').value.trim());
if ($('qCaller').value.trim()) q += '&callerAppKey=' + encodeURIComponent($('qCaller').value.trim());
return api('GET', q).then(function(j) {
$('logTotal').textContent = '共 ' + j.total + ' 条';
return api('GET', q).then(function(pg) {
$('logTotal').textContent = '共 ' + pg.total + ' 条';
var rows = (pg && pg.content) || [];
var tb = $('logT').tBodies[0];
if (!j.rows || !j.rows.length) {
if (!rows.length) {
tb.innerHTML = '<tr><td colspan="9" class="idle">无匹配记录</td></tr>';
return;
}
tb.innerHTML = j.rows.map(function(l) {
tb.innerHTML = rows.map(function(l) {
var st = l.status;
var cls = st >= 500 ? 'st5xx' : (st >= 400 ? 'st4xx' : 'st2');
return '<tr>'
@@ -230,7 +236,7 @@ function loadLogs() {
/* ---------- 顶部 ---------- */
function reloadRegistry() {
api('POST', '../routes/refresh')
.then(function(j) { toast('注册表已重载:路由 ' + j.loaded + ' 条 / 目标 ' + j.targets + ' 条'); })
.then(function(d) { toast('注册表已重载:路由 ' + d.loaded + ' 条 / 目标 ' + d.targets + ' 条'); })
.catch(function(e) { toast('重载失败:' + e.message, true); });
}