From 7f6f6fa41e66a7e3dec48f386bbd5617d8eafbee Mon Sep 17 00:00:00 2001 From: mac Date: Wed, 22 Jul 2026 14:57:11 +0800 Subject: [PATCH 1/4] feat(container): show business line workloads from Wayne --- frontend/src/api/containerService.ts | 99 +++++ frontend/src/views/dashboard/Index.vue | 116 +++++- frontend/src/views/service/Management.vue | 88 +++- server/internal/handler/container_service.go | 109 +++++ server/internal/router/router.go | 3 + server/internal/service/container_service.go | 411 +++++++++++++++++++ 6 files changed, 824 insertions(+), 2 deletions(-) create mode 100644 frontend/src/api/containerService.ts create mode 100644 server/internal/handler/container_service.go create mode 100644 server/internal/service/container_service.go diff --git a/frontend/src/api/containerService.ts b/frontend/src/api/containerService.ts new file mode 100644 index 0000000..0dd6808 --- /dev/null +++ b/frontend/src/api/containerService.ts @@ -0,0 +1,99 @@ +import { getToken } from '@/utils/auth' + +export interface ContainerServiceSummary { + businessLineId: number + businessLineName: string + namespaces: number + clusters: number + nodes: number + readyNodes: number + schedulableNodes: number + workloads: number + pods: number + readyPods: number + cpuUsed: number + cpuTotal: number + cpuPercent: number + memoryUsed: number + memoryTotal: number + memoryPercent: number + errors?: string[] +} + +export interface ContainerWorkload { + name: string + cluster: string + namespace: string + workload: string + ready: string + readyPods: number + pods: number + image: string + biz: string + status: string + statusClass: string +} + +export const emptyContainerServiceSummary: ContainerServiceSummary = { + businessLineId: 0, + businessLineName: '', + namespaces: 0, + clusters: 0, + nodes: 0, + readyNodes: 0, + schedulableNodes: 0, + workloads: 0, + pods: 0, + readyPods: 0, + cpuUsed: 0, + cpuTotal: 0, + cpuPercent: 0, + memoryUsed: 0, + memoryTotal: 0, + memoryPercent: 0, +} + +export const containerServiceApi = { + async getSummary(businessLineId: number): Promise { + return authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/summary`) + }, + + async listWorkloads(businessLineId: number): Promise<{ items: ContainerWorkload[]; summary: ContainerServiceSummary }> { + const data = await authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/workloads`) + return { + items: Array.isArray(data.items) ? data.items : [], + summary: data.summary || emptyContainerServiceSummary, + } + }, +} + +async function authRequest(path: string, init: RequestInit = {}) { + const token = getToken() + const response = await fetch(path, { + ...init, + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + ...init.headers, + }, + }) + const text = await response.text() + const data = parseResponseBody(text) + if (!response.ok) { + const message = data?.error || data?.message || text || `HTTP ${response.status}` + throw new Error(message) + } + return data || {} +} + +function parseResponseBody(text: string) { + if (!text.trim()) { + return {} + } + try { + return JSON.parse(text) + } catch { + return { error: text } + } +} diff --git a/frontend/src/views/dashboard/Index.vue b/frontend/src/views/dashboard/Index.vue index 36e1c21..5a14ed9 100644 --- a/frontend/src/views/dashboard/Index.vue +++ b/frontend/src/views/dashboard/Index.vue @@ -36,6 +36,40 @@ +
+
+

容器化服务 · 资源概览

+ {{ containerLoading ? '同步中...' : containerMetaText }} +
+
+
+ 命名空间 + {{ containerSummary.namespaces }} + {{ currentName }} 业务线绑定 +
+
+ 工作负载 + {{ containerSummary.workloads }} + Deployment +
+
+ Pod 实例 + {{ containerSummary.pods }} + {{ containerSummary.readyPods }} ready +
+
+ CPU 已用 + {{ formatMetric(containerSummary.cpuUsed) }}C + {{ containerSummary.cpuPercent }}% of allocatable +
+
+ Memory 已用 + {{ formatMetric(containerSummary.memoryUsed) }}G + {{ containerSummary.memoryPercent }}% of allocatable +
+
+
+
@@ -121,13 +155,57 @@ diff --git a/frontend/src/views/service/Management.vue b/frontend/src/views/service/Management.vue index c4c319d..5a796f1 100644 --- a/frontend/src/views/service/Management.vue +++ b/frontend/src/views/service/Management.vue @@ -107,14 +107,58 @@
+ +
+
+

容器化服务台账 · 按集群 / Namespace 同步

+ {{ containerLoading ? '同步中...' : containerMetaText }} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
服务名集群Namespace工作负载Pod Ready镜像业务标签状态
当前业务线暂无容器化服务
{{ service.name }}{{ service.cluster }}{{ service.namespace }}{{ service.workload }}{{ service.ready }}{{ service.image || '-' }}{{ service.biz }}● {{ service.status }}
+ +
+