fix(QA): 修复构建阻断与静态资源路径——useMessage 误导入 + plans/citations 根绝对路径改 BASE_URL 前缀(代 bot_qa 验收 #164-#176)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user