Browse Source

fix(admin): LangGraph 管理页面使用独立 axios 实例避免 CORS 和响应格式问题

iwt 1 month ago
parent
commit
02cafd93db
2 changed files with 18 additions and 98 deletions
  1. 1 1
      cfc-web/.last_build_commit
  2. 17 97
      cfc-web/src/api/langgraph.js

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-439404af129637c7b87a4f55dff7d66f5d86d7d3
+722e447bc0dd10d24e64f11ee7403463d62da7f4

+ 17 - 97
cfc-web/src/api/langgraph.js

@@ -1,10 +1,15 @@
-import request from '@/utils/request'
-
-// LangGraph 管理 API
-// 注意:LangGraph 服务在独立域名 ai.etotem.com.cn,不走后端代理
+import axios from 'axios'
 
+// LangGraph 服务地址
 const LANGGRAPH_BASE = 'https://ai.etotem.com.cn'
 
+// 直接创建 axios 实例,不走通用拦截器(LangGraph 返回原始 JSON,不是 {code, data} 格式)
+const lgAxios = axios.create({
+  baseURL: LANGGRAPH_BASE,
+  timeout: 10000,
+  withCredentials: true
+})
+
 /**
  * 获取 LangGraph 健康状态
  */
@@ -21,139 +26,54 @@ export function getLangGraphHealth() {
  * 获取 LangGraph OpenAPI 规范
  */
 export function getLangGraphSpec() {
-  return request({
-    url: LANGGRAPH_BASE + '/openapi.json',
-    method: 'get',
-    timeout: 10000
-  })
+  return lgAxios.get('/openapi.json')
 }
 
 /**
  * 获取详细健康检查
  */
 export function getLangGraphDetailedHealth() {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/health',
-    method: 'get',
-    timeout: 10000
-  })
+  return lgAxios.get('/api/v1/health')
 }
 
 /**
  * 获取 Prometheus metrics
  */
 export function getLangGraphMetrics() {
-  return request({
-    url: LANGGRAPH_BASE + '/metrics',
-    method: 'get',
-    timeout: 10000
-  })
+  return lgAxios.get('/metrics')
 }
 
 /**
  * 测试食材识别
  */
 export function testFoodRecognize(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/food/recognize',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
+  return lgAxios.post('/api/v1/food/recognize', data, { timeout: 60000 })
 }
 
 /**
  * 测试菜单生成
  */
 export function testMenuGenerate(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/menu/generate',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
+  return lgAxios.post('/api/v1/menu/generate', data, { timeout: 60000 })
 }
 
 /**
  * 测试对话
  */
 export function testChat(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/chat',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
+  return lgAxios.post('/api/v1/chat', data, { timeout: 60000 })
 }
 
 /**
  * 测试营养推荐
  */
 export function testRecommend(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/recommend',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
-}
-
-/**
- * 测试舌诊
- */
-export function testTongueDiagnose(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/tongue/diagnose',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
-}
-
-/**
- * 测试报告解析
- */
-export function testReportParse(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/report-parse/parse',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
-}
-
-/**
- * 测试健康教练
- */
-export function testHealthCoach(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/health/coach',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
-}
-
-/**
- * 测试健康管家
- */
-export function testHealthButler(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/health/butler',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
+  return lgAxios.post('/api/v1/recommend', data, { timeout: 60000 })
 }
 
 /**
  * 测试问卷生成
  */
 export function testQuestionnaireGenerate(data) {
-  return request({
-    url: LANGGRAPH_BASE + '/api/v1/questionnaire/generate',
-    method: 'post',
-    data,
-    timeout: 60000
-  })
+  return lgAxios.post('/api/v1/questionnaire/generate', data, { timeout: 60000 })
 }