feat(admin-portal): 完整实现 admin-portal 管理端微前端

包含 src 全部实现、Dockerfile、配置文件等
This commit is contained in:
SpecialX
2026-07-10 19:09:12 +08:00
parent 02d09c47fa
commit b3511910d1
69 changed files with 11955 additions and 693 deletions

View File

@@ -0,0 +1,43 @@
/**
* Web Vitals 采集A11y + 性能)
*
* 仲裁:所有前端应用必须采集 Web Vitals
* 端点NEXT_PUBLIC_WEB_VITALS_ENDPOINT默认 /api/admin/web-vitals
*/
import { onLCP, onCLS, onFCP, onINP, onTTFB } from "web-vitals";
type Metric = { name: string; value: number; rating: string; id: string };
const ENDPOINT =
process.env.NEXT_PUBLIC_WEB_VITALS_ENDPOINT ?? "/api/admin/web-vitals";
function sendMetric(metric: Metric): void {
if (typeof navigator === "undefined") return;
const body = JSON.stringify({
name: metric.name,
value: metric.value,
rating: metric.rating,
id: metric.id,
page: window.location.pathname,
ts: Date.now(),
});
// 使用 sendBeacon 避免阻塞卸载
if (navigator.sendBeacon) {
navigator.sendBeacon(ENDPOINT, body);
} else {
void fetch(ENDPOINT, { method: "POST", body, keepalive: true }).catch(
() => {
// 忽略上报失败
},
);
}
}
export function initWebVitals(): void {
if (typeof window === "undefined") return;
onLCP((m) => sendMetric(m as unknown as Metric));
onCLS((m) => sendMetric(m as unknown as Metric));
onFCP((m) => sendMetric(m as unknown as Metric));
onINP((m) => sendMetric(m as unknown as Metric));
onTTFB((m) => sendMetric(m as unknown as Metric));
}