From dcad2364ba93893a5a4f0cc1e0858c54bfa1fe7d Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Wed, 3 Jun 2026 07:31:47 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BA=86UI=E6=A0=B7=E5=BC=8F=E5=B9=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=9A=97=E9=BB=91=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + docs/frontend-ui.md | 82 ++ oneapi-gateway/Dockerfile | 2 + oneapi-gateway/admin-ui/src/main.tsx | 6 +- oneapi-gateway/admin-ui/src/ui/App.tsx | 491 ++++++------ oneapi-gateway/admin-ui/tsconfig.json | 5 + oneapi-gateway/admin-ui/vite.config.ts | 15 + oneapi-gateway/chat-ui/src/main.tsx | 6 +- oneapi-gateway/chat-ui/src/ui/App.tsx | 678 +++++----------- oneapi-gateway/chat-ui/tsconfig.json | 5 + oneapi-gateway/chat-ui/vite.config.ts | 15 + oneapi-gateway/shared-ui/package-lock.json | 77 ++ oneapi-gateway/shared-ui/package.json | 14 + oneapi-gateway/shared-ui/src/components.tsx | 277 +++++++ oneapi-gateway/shared-ui/src/index.ts | 23 + oneapi-gateway/shared-ui/src/styles.css | 813 ++++++++++++++++++++ oneapi-gateway/shared-ui/src/theme.tsx | 104 +++ oneapi-gateway/src/dashboard.ts | 356 +-------- oneapi-gateway/src/openapi.ts | 107 +-- oneapi-gateway/src/ui-shell.ts | 374 +++++++++ 20 files changed, 2302 insertions(+), 1149 deletions(-) create mode 100644 docs/frontend-ui.md create mode 100644 oneapi-gateway/shared-ui/package-lock.json create mode 100644 oneapi-gateway/shared-ui/package.json create mode 100644 oneapi-gateway/shared-ui/src/components.tsx create mode 100644 oneapi-gateway/shared-ui/src/index.ts create mode 100644 oneapi-gateway/shared-ui/src/styles.css create mode 100644 oneapi-gateway/shared-ui/src/theme.tsx create mode 100644 oneapi-gateway/src/ui-shell.ts diff --git a/README.md b/README.md index 0152d13..e887e92 100644 --- a/README.md +++ b/README.md @@ -57,5 +57,6 @@ BASE_URL=http://localhost:3003 CONFIG_FILE=config/easyai.production.local.yaml . - [部署指南](docs/deployment.md) - [运行手册](docs/operations.md) - [开发与测试](docs/development.md) +- [前端 UI 约定](docs/frontend-ui.md) - [架构说明](docs/architecture.md) - [YAML 密钥管理](docs/yaml-secret-management.md) diff --git a/docs/frontend-ui.md b/docs/frontend-ui.md new file mode 100644 index 0000000..a15e865 --- /dev/null +++ b/docs/frontend-ui.md @@ -0,0 +1,82 @@ +# 前端 UI 约定 + +这份约定适用于 `oneapi-gateway/chat-ui` 和 `oneapi-gateway/admin-ui`。新增页面时,优先复用 `oneapi-gateway/shared-ui` 中的组件和样式,不再在页面内单独定义一套视觉规则。 + +## 1. 统一原则 + +- 所有页面使用同一套主题变量:亮色 / 暗黑由 `ThemeProvider` 和 `ThemeToggle` 控制。 +- 所有表单、按钮、卡片、表格和布局块优先使用共享组件。 +- 页面级 `style` 只允许用于局部尺寸、间距或临时覆盖,不允许承载整页布局。 +- 新增页面必须先检查是否能复用 `Page / Section / Field / ActionBar / Grid / Stack / Inline`。 + +## 2. 共享组件 + +### 基础交互 + +- `Button`:统一按钮外观与状态 +- `Input`:统一输入框 +- `Select`:统一下拉选择 +- `TextArea`:统一多行输入 +- `ThemeToggle`:统一主题切换 + +### 内容容器 + +- `Card`:信息卡、设置卡、结果卡 +- `Table`:列表、统计表、管理表 +- `Section`:页面块、表单区、状态区、结果区 + +### 字段与布局 + +- `Field`:标签 + 控件 + 提示信息 +- `ActionBar`:操作按钮条、筛选条、分页条 +- `Page`:页面根容器 +- `Center`:居中登录页 / 空状态 +- `Stack`:垂直堆叠 +- `Inline`:水平排列 +- `Grid`:响应式网格 + +## 3. 页面写法 + +### 推荐结构 + +```tsx + +
+ + + + + + + ... +
+
+``` + +### 常见约定 + +- 表单字段一律使用 `Field`,不要手写 `label + input` 的散装结构。 +- 多按钮区域一律使用 `ActionBar`,不要在页面里自己拼一套按钮间距。 +- 列表、统计卡、结果区优先用 `Grid + Card` 或 `Table`,不要用自定义多层 `div`。 +- 空状态、登录页优先用 `Center` + `Section`。 + +## 4. 主题与样式 + +- 颜色、边框、阴影、字号、圆角、控件高度统一来自 `shared-ui/src/styles.css`。 +- 新颜色优先加到 CSS 变量,不要在页面里硬编码一组新色值。 +- 响应式优先依赖共享断点和共享布局类,不要为单个页面重新定义断点。 + +## 5. 新增页面检查清单 + +- 是否复用了共享组件,而不是新增本地样式组件 +- 是否把页面级布局收敛到 `Page / Section / Grid / ActionBar` +- 是否避免了新的硬编码颜色、字体、边距体系 +- 是否支持亮色 / 暗黑模式 +- 是否在窄屏下仍然可用 + +## 6. 默认选择 + +- 聊天页优先使用:`Section`、`Field`、`ActionBar`、`Stack` +- 管理页优先使用:`Section`、`Card`、`Table`、`Grid`、`Field` + +如果必须例外,先把例外写进 `shared-ui`,再在页面里使用,不要在业务页分叉出独立规范。 diff --git a/oneapi-gateway/Dockerfile b/oneapi-gateway/Dockerfile index 0803b53..dd89ef8 100644 --- a/oneapi-gateway/Dockerfile +++ b/oneapi-gateway/Dockerfile @@ -11,6 +11,7 @@ FROM node:22-alpine AS build-admin-ui WORKDIR /app/admin-ui COPY admin-ui/package.json admin-ui/package-lock.json admin-ui/tsconfig.json admin-ui/vite.config.ts admin-ui/index.html /app/admin-ui/ COPY admin-ui/src /app/admin-ui/src +COPY shared-ui /app/shared-ui RUN npm ci --no-audit --no-fund RUN npm run build @@ -19,6 +20,7 @@ FROM node:22-alpine AS build-chat-ui WORKDIR /app/chat-ui COPY chat-ui/package.json chat-ui/package-lock.json chat-ui/tsconfig.json chat-ui/vite.config.ts chat-ui/index.html /app/chat-ui/ COPY chat-ui/src /app/chat-ui/src +COPY shared-ui /app/shared-ui RUN npm ci --no-audit --no-fund RUN npm run build diff --git a/oneapi-gateway/admin-ui/src/main.tsx b/oneapi-gateway/admin-ui/src/main.tsx index 479c4e4..2708c9c 100644 --- a/oneapi-gateway/admin-ui/src/main.tsx +++ b/oneapi-gateway/admin-ui/src/main.tsx @@ -1,9 +1,13 @@ import React from "react"; import { createRoot } from "react-dom/client"; import { App } from "./ui/App"; +import { ThemeProvider } from "@easyai/ui"; +import "@easyai/ui/styles.css"; createRoot(document.getElementById("root")!).render( - + + + , ); diff --git a/oneapi-gateway/admin-ui/src/ui/App.tsx b/oneapi-gateway/admin-ui/src/ui/App.tsx index a5dde16..5db1a38 100644 --- a/oneapi-gateway/admin-ui/src/ui/App.tsx +++ b/oneapi-gateway/admin-ui/src/ui/App.tsx @@ -1,5 +1,6 @@ import { useEffect, useMemo, useRef, useState } from "react"; import type { CSSProperties } from "react"; +import { ActionBar, Button, Card, Field, Grid, Input, Inline, Page, Section, Stack, Table } from "@easyai/ui"; type Tab = "usage" | "keys" | "tenants"; @@ -120,32 +121,8 @@ function getDeploymentLabel(appEnv?: string | null): { text: string; tone: strin function DeploymentBadge(props: { appEnv?: string }) { const { text, tone } = getDeploymentLabel(props.appEnv); return ( -
- +
+ {text}
); @@ -278,29 +255,26 @@ function DateTimeInput(props: DateTimeInputProps) { return (
- + {open && !disabled ? (
-
- - -
- - + -
-
+ + +
) : null}
@@ -434,18 +404,14 @@ function ScopeMultiSelect(props: ScopeMultiSelectProps) { return (
- + {open && !disabled ? (
{SCOPE_OPTIONS.map((opt) => ( ))}
@@ -543,8 +506,8 @@ function TenantPicker(props: TenantPickerProps) { return (
-
- + - {value ? {bound} 个密钥 : null} + {value ? {bound} 个密钥 : null}
{open && !disabled ? (
未绑定
@@ -656,11 +615,11 @@ function TenantPicker(props: TenantPickerProps) { cursor: "pointer", display: "flex", justifyContent: "space-between", - background: items[active] === t ? "#f6f7f8" : "#fff", + background: items[active] === t ? "color-mix(in srgb, var(--ui-primary) 8%, transparent)" : "transparent", }} > {t} - {boundCountByTenant.get(t) ?? 0} 个密钥 + {boundCountByTenant.get(t) ?? 0} 个密钥
))}
@@ -1163,75 +1122,64 @@ export function App() { }, [filteredKeys, keyPageClamped]); return ( -
-
+ +

OneAPI 管理台

-
-
-
-
网关状态
- {health?.ok ? "Gateway online" : "Unknown"} -
-
-
认证模式
- {health?.authModes?.join(", ") || "-"} -
-
-
缓存
- {health ? (health.cacheEnabled ? "enabled" : "disabled") : "-"} -
-
-
上游
- {health?.upstreams?.join(", ") || "-"} -
-
-
- - + - + - {status} + + {status}

{title}

{tab === "usage" ? ( -
-
- - -
+ + + - +
{["主体", "鉴权方式", "租户", "API 密钥", "请求数", "错误数", "缓存命中", "P95 延迟(毫秒)", "总 Tokens"].map((h) => ( - ))} @@ -1240,43 +1188,46 @@ export function App() { {usageRows.map((r) => ( - - - - - - - - + + + - + ))} -
+ {h}
+ {r.principal} + {r.auth_mode} - {r.tenant_id ? {r.tenant_id} : -} + + {r.tenant_id ? {r.tenant_id} : -} + {r.api_key_id ? ( #{r.api_key_id} {r.api_key_prefix ? ` (${r.api_key_prefix})` : ""} ) : ( - - + - )} {r.requests}{r.errors}{r.cached} + {r.requests}{r.errors}{r.cached} {r.p95_latency_ms ? Math.round(r.p95_latency_ms) : ""} {r.total_tokens ?? ""}{r.total_tokens ?? ""}
-
+ + ) : null} {tab === "keys" ? ( -
-
- + +
- +
setNewKeyExpiresAt(value ?? "")} style={{ ...dateInputStyle, flex: "1 1 190px" }} /> - - + 创建密钥 + + - -
+ + -
- - + + 第 {keyPageClamped} / {keyTotalPages} 页(共 {filteredKeys.length} 个密钥) - -
+ + {createdKey ? ( -
-
新建 API 密钥(仅展示一次):
- {createdKey} -
- -
-
+ +
+ {createdKey} + + + +
+
) : null} -
+ {keyPageRows.map((k) => ( -
-
+ +
-
-
#{k.id}
+
#{k.id}
{k.status}
-
+ -
- + - + -
- 租户 + updateKeyTenant(k.id, tenantId)} /> -
-
+ + -
- - -
- -
-
-
创建时间
-
{formatTime(k.created_at)}
-
-
-
最后使用
-
{k.last_used_at ? `${formatTime(k.last_used_at)} ${k.last_used_ip ?? ""}` : "尚无调用"}
-
-
-
撤销策略
-
- {k.revoked_at + + + + + +
+
+
-
-
+ : "-" + } + /> + -
- - + - + - - -
-
+ + + ))} -
-
+ + ) : null} {tab === "tenants" ? ( -
-
- + + setNewTenantId(e.target.value)} /> - - + - -
+ + -
- - + + 第 {tenantPageClamped} / {tenantTotalPages} 页(共 {filteredTenants.length} 个租户) - -
+ + - +
{["租户", "创建时间", "已绑定密钥", "RPM 限制", "TPM 限制", "禁用", "操作"].map((h) => ( - ))} @@ -1527,22 +1482,22 @@ export function App() { {tenantPageRows.map((t) => ( - - - - + + - - - ))} -
+ {h}
+ {t.tenant_id} {formatTime(t.created_at)}{boundKeyCountByTenant.get(t.tenant_id) ?? 0} - + {formatTime(t.created_at)}{boundKeyCountByTenant.get(t.tenant_id) ?? 0} + - + + - + + - - - +
-
+ + ) : null} -
+ ); } diff --git a/oneapi-gateway/admin-ui/tsconfig.json b/oneapi-gateway/admin-ui/tsconfig.json index cb12523..8acb0ae 100644 --- a/oneapi-gateway/admin-ui/tsconfig.json +++ b/oneapi-gateway/admin-ui/tsconfig.json @@ -8,6 +8,11 @@ "strict": true, "skipLibCheck": true, "noEmit": true, + "baseUrl": ".", + "paths": { + "@easyai/ui": ["../shared-ui/src/index"], + "@easyai/ui/*": ["../shared-ui/src/*"] + }, "types": ["vite/client"] }, "include": ["src"] diff --git a/oneapi-gateway/admin-ui/vite.config.ts b/oneapi-gateway/admin-ui/vite.config.ts index 8b8a300..e6c0204 100644 --- a/oneapi-gateway/admin-ui/vite.config.ts +++ b/oneapi-gateway/admin-ui/vite.config.ts @@ -1,9 +1,24 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const repoRoot = fileURLToPath(new URL("../", import.meta.url)); export default defineConfig({ plugins: [react()], base: "/dashboard/", + resolve: { + alias: { + "@easyai/ui": path.resolve(repoRoot, "shared-ui/src"), + }, + dedupe: ["react", "react-dom"], + }, + server: { + fs: { + allow: [repoRoot], + }, + }, build: { outDir: "dist", emptyOutDir: true, diff --git a/oneapi-gateway/chat-ui/src/main.tsx b/oneapi-gateway/chat-ui/src/main.tsx index 479c4e4..2708c9c 100644 --- a/oneapi-gateway/chat-ui/src/main.tsx +++ b/oneapi-gateway/chat-ui/src/main.tsx @@ -1,9 +1,13 @@ import React from "react"; import { createRoot } from "react-dom/client"; import { App } from "./ui/App"; +import { ThemeProvider } from "@easyai/ui"; +import "@easyai/ui/styles.css"; createRoot(document.getElementById("root")!).render( - + + + , ); diff --git a/oneapi-gateway/chat-ui/src/ui/App.tsx b/oneapi-gateway/chat-ui/src/ui/App.tsx index 7bacdab..0168503 100644 --- a/oneapi-gateway/chat-ui/src/ui/App.tsx +++ b/oneapi-gateway/chat-ui/src/ui/App.tsx @@ -1,4 +1,5 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { ActionBar, Button, Center, Field, Grid, Input, Inline, Select, Section, Stack, TextArea } from "@easyai/ui"; import { createClientId } from "./id"; import { shouldApplyLoadedMessages } from "./messageLoad"; import { parseSseDataEvents } from "./stream"; @@ -92,6 +93,10 @@ function truncate(s: string, n: number): string { return s.slice(0, n - 1) + "…"; } +function cx(...parts: Array) { + return parts.filter(Boolean).join(" "); +} + function formatTime(s: string): string { const d = new Date(s); if (Number.isNaN(d.getTime())) return s; @@ -167,32 +172,8 @@ function getDeploymentLabel(appEnv?: string | null): { text: string; tone: strin function DeploymentBadge(props: { appEnv?: string }) { const { text, tone } = getDeploymentLabel(props.appEnv); return ( -
- +
+ {text}
); @@ -814,70 +795,35 @@ export function App() { if (!apiKey) { return ( -
-
-
-

EasyAI Chat

+
+
+ -
-

- 请输入 API Key 开始使用。若聊天返回 model not found,请先在服务端拉取配置中的 Ollama 模型。 -

- setKeyInput(e.target.value)} - onKeyDown={(e) => e.key === "Enter" && handleLogin()} - placeholder="sk-..." - style={{ - width: "100%", - padding: "12px 16px", - borderRadius: 8, - border: "1px solid #ddd", - fontSize: 14, - boxSizing: "border-box", - marginBottom: 16, - }} - /> - + {loginError && (
{loginError}
)} -
-
+ + ); } @@ -885,73 +831,50 @@ export function App() { const modelList = models; return ( -
+
{/* Sidebar */} -
-
-
+
+
+

EasyAI Chat

-
- -
+ + -
+
{convLoading && conversations.length === 0 ? ( -
加载中...
+
加载中...
) : conversations.length === 0 ? ( -
暂无对话
+
暂无对话
) : ( conversations.map((conv) => (
handleSelectConversation(conv.id)} + className={cx( + "ui-chat-conversation-item", + conv.id === currentId && "ui-chat-conversation-active", + )} style={{ - padding: "10px 12px", - borderRadius: 8, - marginBottom: 4, cursor: isStreaming ? "default" : "pointer", - background: conv.id === currentId ? "#e8f0fe" : "transparent", - display: "flex", - gap: 8, - alignItems: "flex-start", opacity: isStreaming ? 0.6 : 1, }} >
{renamingId === conv.id ? ( - setRenameInput(e.target.value)} onKeyDown={(e) => { @@ -973,16 +896,8 @@ export function App() { }} onClick={(e) => e.stopPropagation()} autoFocus - style={{ - width: "100%", - padding: "2px 6px", - borderRadius: 4, - border: "1px solid #1a73e8", - fontSize: 14, - fontFamily: "inherit", - outline: "none", - boxSizing: "border-box", - }} + className="ui-input" + style={{ width: "100%", padding: "2px 6px", fontSize: 14 }} /> ) : (
)} -
+
{conv.message_count} 条消息 · {formatTime(conv.updated_at)}
- +
)) )}
-
+
{truncate(apiKey, 24)} - +
{/* Main area */} -
+
{/* Top bar */} -
- - - setSelectedModel(e.target.value)} disabled={isStreaming || modelList.length === 0} style={{ - padding: "6px 12px", - borderRadius: 6, - border: "1px solid #ddd", fontSize: 13, minWidth: 200, }} @@ -1121,211 +990,135 @@ export function App() { {modelList.map((m) => ( ))} - + - + {isStreaming && ( - + )} {viewMode === "test" && testLoading && ( - + )} - {status && ( - {status} - )} + {status && {status}} {currentConv && ( - + )} {currentConv && ( - + > + 删除会话 + )} -
+ {viewMode === "chat" ? ( <> {/* Settings panel */} {showSettings && ( -
- - -
+ + )} {/* Messages */} -
+
{!currentConv && ( -
-
💬
+
+
💬
选择或创建一个对话开始聊天
-
+ )} {messages.map((msg) => (
-
+
{msg.content}
))} {isStreaming && ( -
-
+
+
{streamContent} - +
)} @@ -1334,17 +1127,9 @@ export function App() {
{/* Input area */} -
-
-