From 4173b53b1b086ad56b74f409532dfb93d707938a Mon Sep 17 00:00:00 2001 From: caoxiaozhu Date: Thu, 16 Jul 2026 11:03:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=89=8D=E7=AB=AF=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=8C=89=E9=9C=80=E5=8C=96=E4=B8=8E=20Mock=20?= =?UTF-8?q?=E6=87=92=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除全量 Element Plus 与全局 VChart 注册,改为按需引入样式与组件内局部图表;Mock 适配器改为按 VITE_ENABLE_MOCK 环境变量懒加载,生产默认不拦截请求;ECharts 精简为看板所需图表,各视图与 stores 同步适配。 --- frontend/README.md | 9 ++++ .../regression-training-log-layout.mjs | 3 +- frontend/src/App.vue | 6 ++- frontend/src/api/request.ts | 4 -- frontend/src/env.d.ts | 9 ++++ frontend/src/layouts/MainLayout.vue | 1 + frontend/src/main.ts | 32 ++++++----- frontend/src/plugins/echarts.ts | 10 +--- frontend/src/stores/models.ts | 21 +++++--- frontend/src/stores/system.ts | 13 ++++- .../src/views/dashboard/DashboardView.vue | 6 ++- .../views/eval/create/DimensionFormFields.vue | 11 ++-- .../src/views/fine-tune/FineTuneListView.vue | 20 +++---- frontend/src/views/login/LoginView.vue | 2 +- frontend/src/views/system/HardwareView.vue | 2 + frontend/src/views/system/LogsView.vue | 54 +++++++++---------- frontend/src/views/system/TrainingLogView.vue | 22 ++++---- frontend/vite.config.ts | 4 +- 18 files changed, 137 insertions(+), 92 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 85f9468..883fe95 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -26,6 +26,15 @@ npm run dev 后端 API 默认通过 Vite 代理转发到 `http://localhost:7861`(见 `vite.config.ts`)。 +开发环境默认启用前端 Mock。如需联调真实后端,使用: + +```bash +VITE_ENABLE_MOCK=false npm run dev +``` + +生产构建默认不包含 Mock;仅在演示构建中可显式设置 +`VITE_ENABLE_MOCK=true`。 + ## 构建 ```bash diff --git a/frontend/scripts/regression-training-log-layout.mjs b/frontend/scripts/regression-training-log-layout.mjs index 05245ea..215b245 100644 --- a/frontend/scripts/regression-training-log-layout.mjs +++ b/frontend/scripts/regression-training-log-layout.mjs @@ -117,7 +117,8 @@ assert.match( assert.match(source, /import \{ getSystemInfo \} from '@\/api\/modules\/system'/, '训练概览必须复用系统 GPU 监控数据源') assert.match(source, /Promise\.all\(\[datasetPromise, loadLog\(currentTask\), loadGpuStatus\(\)\]\)/, 'GPU 状态必须和训练日志一起刷新') assert.match(source, /if \(refreshInFlight\) return/, '轮询刷新必须阻止并发重叠') -assert.match(source, /onUnmounted\([\s\S]*?clearInterval\(timer\)/, '组件卸载时必须清理轮询定时器') +assert.match(source, /usePolling/, '训练日志必须使用统一轮询机制') +assert.match(source, /stopPolling\(\)/, '训练结束后必须停止轮询') const overview = findElements( templateAst, diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 856a59f..c9dc7e9 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,7 +1,9 @@ diff --git a/frontend/src/api/request.ts b/frontend/src/api/request.ts index 3ee62a7..4c44b53 100644 --- a/frontend/src/api/request.ts +++ b/frontend/src/api/request.ts @@ -17,10 +17,6 @@ const service: AxiosInstance = axios.create({ timeout: 30000, }) -// 安装 mock adapter(拦截所有 axios 请求返回 mock 数据,方便前端独立开发调试) -import { installMockAdapter } from '@/mock/adapter' -installMockAdapter(service) - // 请求拦截器 service.interceptors.request.use( (config) => config, diff --git a/frontend/src/env.d.ts b/frontend/src/env.d.ts index 323c78a..443a7fa 100644 --- a/frontend/src/env.d.ts +++ b/frontend/src/env.d.ts @@ -1,5 +1,14 @@ /// +interface ImportMetaEnv { + /** 是否启用前端 Mock;开发环境默认开启,生产环境默认关闭。 */ + readonly VITE_ENABLE_MOCK?: 'true' | 'false' +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} + declare module '*.vue' { import type { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any> diff --git a/frontend/src/layouts/MainLayout.vue b/frontend/src/layouts/MainLayout.vue index 0a67cda..6cb75d7 100644 --- a/frontend/src/layouts/MainLayout.vue +++ b/frontend/src/layouts/MainLayout.vue @@ -1,6 +1,7 @@ diff --git a/frontend/src/views/login/LoginView.vue b/frontend/src/views/login/LoginView.vue index aa89d4b..3b5e5e8 100644 --- a/frontend/src/views/login/LoginView.vue +++ b/frontend/src/views/login/LoginView.vue @@ -136,7 +136,7 @@ async function handleLogin() { position: relative; color: #fff; background-color: #121127; - background-image: url('@/assets/login-hero-flow.png'); + background-image: url('@/assets/login-hero-flow.jpg'); background-size: cover; background-position: center; overflow: hidden; diff --git a/frontend/src/views/system/HardwareView.vue b/frontend/src/views/system/HardwareView.vue index 765cfcd..0ea331c 100644 --- a/frontend/src/views/system/HardwareView.vue +++ b/frontend/src/views/system/HardwareView.vue @@ -1,6 +1,8 @@