fix(QA): 修复构建阻断与静态资源路径——useMessage 误导入 + plans/citations 根绝对路径改 BASE_URL 前缀(代 bot_qa 验收 #164-#176)

This commit is contained in:
2026-08-06 13:14:52 +08:00
parent 787234146b
commit 1b7c2b0177
7 changed files with 51 additions and 1142 deletions
Binary file not shown.
@@ -9,8 +9,6 @@
* 推理服务为 iAOP 独立通道(不要求 FBA JWT),故用原生 fetch 封装,
* 统一超时 / 错误信息 / 结果结构;FBA requestClient 仅用于 /fba/* 接口。
*/
import { useMessage } from '@vben/hooks';
const BASE_URL = '/v1';
const TIMEOUT_MS = 15000;
@@ -8,7 +8,7 @@
*
* 统一:带缓存(会话内重复加载不重发请求)+ 结构校验 + 错误提示。
*/
import { useMessage } from '@vben/hooks';
import { message } from 'antdv-next';
export interface CockpitPlan {
$schema?: string;
@@ -32,6 +32,10 @@ export interface AlarmPanelConfig {
const CACHE = new Map<string, unknown>();
// 静态模板资产在 public/iaop/plans/,随 VITE_BASE 挂载(生产 /fba-admin/),
// 必须用 BASE_URL 前缀,不能用根绝对路径(否则 nginx 子路径下 404)。
const PLANS_BASE = `${import.meta.env.BASE_URL}iaop/plans`;
async function loadJson<T>(name: string, base: string): Promise<T> {
const key = `${base}/${name}`;
if (CACHE.has(key)) {
@@ -46,7 +50,6 @@ async function loadJson<T>(name: string, base: string): Promise<T> {
CACHE.set(key, data);
return data;
} catch (err) {
const message = useMessage();
message.error(`模板 ${name} 加载失败`);
throw err;
}
@@ -54,12 +57,12 @@ async function loadJson<T>(name: string, base: string): Promise<T> {
/** 驾驶舱布局(按行业模板切换:ti-cl4 / resin) */
export function loadCockpitPlan(template: 'ti-cl4' | 'resin'): Promise<CockpitPlan> {
return loadJson<CockpitPlan>(`${template}.json`, '/iaop/plans');
return loadJson<CockpitPlan>(`${template}.json`, PLANS_BASE);
}
/** 告警面板配置 */
export function loadAlarmPanel(): Promise<AlarmPanelConfig> {
return loadJson<AlarmPanelConfig>('alarm_panel.ti.json', '/iaop/plans');
return loadJson<AlarmPanelConfig>('alarm_panel.ti.json', PLANS_BASE);
}
/** 清理模板缓存(发布新版本后调用) */
@@ -6,7 +6,7 @@ const docs = ref<Array<{ title: string; sections: number; indexed: boolean }>>([
onMounted(async () => {
try {
const resp = await fetch('/iaop/citations.json');
const resp = await fetch(`${import.meta.env.BASE_URL}iaop/citations.json`);
const d = await resp.json();
const docsObj = (d as { documents?: Record<string, string[]> }).documents || {};
docs.value = Object.entries(docsObj).map(([title, secs]) => ({ title, sections: secs.length, indexed: true }));
@@ -39,7 +39,7 @@ onMounted(async () => {
offline.value = true;
}
try {
const resp = await fetch('/iaop/citations.json');
const resp = await fetch(`${import.meta.env.BASE_URL}iaop/citations.json`);
const d = await resp.json();
citations.value = (d as { documents?: Record<string, string[]> }).documents || {};
} catch {
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://lefthook.dev/configuration/
#
# pre-push:
# jobs:
# - name: packages audit
# tags:
# - frontend
# - security
# run: yarn audit
#
# - name: gems audit
# tags:
# - backend
# - security
# run: bundle audit
#
# pre-commit:
# parallel: true
# jobs:
# - run: yarn eslint {staged_files}
# glob: "*.{js,ts,jsx,tsx}"
#
# - name: rubocop
# glob: "*.rb"
# exclude:
# - config/application.rb
# - config/routes.rb
# run: bundle exec rubocop --force-exclusion -- {all_files}
#
# - name: govet
# files: git ls-files -m
# glob: "*.go"
# run: go vet -- {files}
#
# - script: "hello.js"
# runner: node
#
# - script: "hello.go"
# runner: go run