diff --git a/controller/QAController.py b/controller/QAController.py index 48fe2dd..d61e52d 100644 --- a/controller/QAController.py +++ b/controller/QAController.py @@ -9,6 +9,8 @@ from robyn import jsonify, Response from app import app from controller.client import client +import uuid + def convert_to_g6_format(data): entities = data["entities"] relations = data["relations"] @@ -25,13 +27,12 @@ def convert_to_g6_format(data): nodes.append({ "id": node_id, "label": name, - "data":{ + "data": { "type": ent["t"] # 可用于 G6 的节点样式区分 } - }) - # 构建边 + # 构建边,并为每条边生成唯一 ID edges = [] for rel in relations: e1 = rel["e1"] @@ -42,11 +43,14 @@ def convert_to_g6_format(data): target_id = name_to_id.get(e2) if source_id and target_id: + edge_id = str(uuid.uuid4()) # 👈 为边生成唯一 ID edges.append({ + "id": edge_id, # ✅ 添加 id 字段 "source": source_id, "target": target_id, + "label": r, # G6 支持直接使用 label(非必须放 data) "data": { - "label": r + "label": r # 保留 data.label 便于扩展 } }) else: diff --git a/controller/client.py b/controller/client.py index 448c4cb..09b4c03 100644 --- a/controller/client.py +++ b/controller/client.py @@ -1,3 +1,5 @@ import httpx -client = httpx.AsyncClient(base_url="http://192.168.50.113:8088") \ No newline at end of file +client = httpx.AsyncClient(base_url="http://192.168.50.113:8088") + +# client = httpx.AsyncClient(base_url="http://192.168.2.20:8088") \ No newline at end of file diff --git a/util/auth_interceptor.py b/util/auth_interceptor.py index ad74ac9..2eeefc3 100644 --- a/util/auth_interceptor.py +++ b/util/auth_interceptor.py @@ -106,7 +106,8 @@ def global_auth_interceptor(request): """全局认证拦截器 - 用于 @app.before_request() 装饰器""" # 获取请求路径 path = str(request.url.path) if hasattr(request.url, 'path') else str(request.url) - + print(path) + print("1111111111111111=============") # 公开路径直接放行 if is_public_path(path): return request diff --git a/vue/src/api/profile.js b/vue/src/api/profile.js index 04e2b1e..1acecbe 100644 --- a/vue/src/api/profile.js +++ b/vue/src/api/profile.js @@ -6,11 +6,10 @@ import request from '@/utils/request'; * 后端接口:GET /api/userInfo * @param {string} token - 用户登录令牌 */ -export function getUserProfile(token) { +export function getUserProfile() { return request({ url: '/api/userInfo', method: 'get', - }); } diff --git a/vue/src/components/Menu.vue b/vue/src/components/Menu.vue index 344967d..e9342a8 100644 --- a/vue/src/components/Menu.vue +++ b/vue/src/components/Menu.vue @@ -80,7 +80,7 @@ const props = defineProps({ // 定义组件事件 const emit = defineEmits(['menu-click']); -const userProfile = ref({ +let userProfile = ref(JSON.parse(localStorage.getItem('userProfile')) || { username: '用户', avatar: '/resource/avatar/用户.png' }); @@ -111,39 +111,36 @@ const handleProfile = () => { const handleLogout = () => { localStorage.removeItem('messages'); localStorage.removeItem('token'); // 退出时通常需要清除token + localStorage.removeItem('userProfile'); // 清除用户信息缓存 router.push('/login'); }; onMounted(async () => { - try { - const token = localStorage.getItem('token'); - console.log('Profile组件挂载,获取到的token:', token); - - if (token) { - const response = await getUserProfile(token); - if (response.success) { - let avatarUrl = response.user.avatar || '/resource/avatar/4.png'; - // 保持你原有的逻辑 - userProfile.value = { - username: response.user.username, - avatar: avatarUrl - }; - } else { - // 如果token失效 - if (response.message && response.message.includes('登录')) { - localStorage.removeItem('token'); - ElMessage.warning('登录已过期,请重新登录'); - } - } - } else { - console.log('用户未登录'); - // 修复点:改用 ElMessage 而不是不存在的 errorMessage.value - ElMessage.info('您当前处于游客模式,请登录后操作'); + // 优先从 localStorage 读取 + const cached = localStorage.getItem('userProfile'); + + if (cached) { + try { + userProfile.value = JSON.parse(cached); + return; // 已有缓存,不再请求 + } catch (e) { + console.warn('userProfile 缓存解析失败,将重新请求'); } - } catch (error) { - console.error('获取用户信息失败:', error); - // 修复点:改用 ElMessage - ElMessage.error('无法连接到服务器,请检查网络'); + } + + // 无有效缓存,发起请求 + const response = await getUserProfile(); + if (response?.success && response.user) { + const avatarUrl = response.user.avatar || '/resource/avatar/4.png'; + userProfile.value = { + username: response.user.username, + avatar: avatarUrl + }; + // 保存到 localStorage + localStorage.setItem('userProfile', JSON.stringify(userProfile.value)); + } else { + // 可选:保留默认值或提示错误 + ElMessage.warning('用户信息加载失败,使用默认头像'); } }); diff --git a/vue/src/system/GraphBuilder.vue b/vue/src/system/GraphBuilder.vue index 7640e46..acef2d9 100644 --- a/vue/src/system/GraphBuilder.vue +++ b/vue/src/system/GraphBuilder.vue @@ -5,6 +5,7 @@ :initial-active="1" />