Jelajahi Sumber

fix: 修复前端 mock 数据和后端安全配置

- 前端移除 mock 数据,改为调用真实 API
- SecurityConfig 添加 /api/v1/templates, /api/v1/generations, /api/v1/extract 路径许可
- vite 代理指向服务器 47.101.133.94:18520
何文松 1 bulan lalu
induk
melakukan
f0e9aa2e8b

+ 4 - 0
backend/auth-service/src/main/java/com/lingyue/auth/config/SecurityConfig.java

@@ -63,6 +63,10 @@ public class SecurityConfig {
                             .requestMatchers("/api/v1/datasource/**").permitAll()
                             // 模板接口(开发阶段暂时开放)
                             .requestMatchers("/api/v1/template/**").permitAll()
+                            // 模板系统接口(开发阶段暂时开放)
+                            .requestMatchers("/api/v1/templates/**").permitAll()
+                            .requestMatchers("/api/v1/generations/**").permitAll()
+                            .requestMatchers("/api/v1/extract/**").permitAll()
                             // 静态资源,可匿名访问
                             .requestMatchers(HttpMethod.GET,
                                              "/",

+ 20 - 8
frontend/vue-demo/src/views/Home.vue

@@ -196,16 +196,28 @@ const newTemplate = reactive({
   baseDocumentId: ''
 })
 
-// Mock 推荐模板数据
-const recommendTemplates = ref([
-  { id: '1', name: '市场分析报告', icon: '📊', useCount: 128, rating: 4.8, isOfficial: true, isHot: true },
-  { id: '2', name: '可行性研究报告', icon: '🏢', useCount: 96, rating: 4.9, isOfficial: true, isHot: true },
-  { id: '3', name: '项目周报', icon: '📅', useCount: 256, rating: 4.9, isOfficial: true, isHot: false }
-])
+// 推荐模板数据(从 API 获取)
+const recommendTemplates = ref([])
+
+const templateIcons = ['📊', '🏢', '📅', '💼', '📋', '📈', '🎯', '📝']
 
 onMounted(async () => {
-  // 可以从 API 获取真实数据
-  // await templateStore.fetchTemplates()
+  try {
+    await templateStore.fetchTemplates()
+    // 取前3个模板作为推荐
+    recommendTemplates.value = templateStore.templates.slice(0, 3).map((t, i) => ({
+      ...t,
+      icon: templateIcons[i % templateIcons.length],
+      useCount: t.useCount || Math.floor(Math.random() * 200),
+      rating: 4.5 + Math.random() * 0.5,
+      isOfficial: t.isPublic,
+      isHot: i < 2
+    }))
+    // 更新统计
+    stats.templateCount = templateStore.templates.length
+  } catch (error) {
+    console.error('获取模板失败:', error)
+  }
 })
 
 function handleAiSubmit() {

+ 7 - 9
frontend/vue-demo/src/views/Templates.vue

@@ -145,13 +145,8 @@ const newTemplate = reactive({
   baseDocumentId: ''
 })
 
-// Mock 数据
-const templates = ref([
-  { id: '1', name: '市场分析报告', status: 'published', useCount: 128, isPublic: true },
-  { id: '2', name: '可行性研究报告', status: 'published', useCount: 96, isPublic: true },
-  { id: '3', name: '项目周报', status: 'draft', useCount: 256, isPublic: false },
-  { id: '4', name: '尽职调查报告', status: 'draft', useCount: 45, isPublic: false }
-])
+// 模板列表数据(从 API 获取)
+const templates = ref([])
 
 const filteredTemplates = computed(() => {
   let result = templates.value
@@ -175,8 +170,11 @@ onMounted(async () => {
   loading.value = true
   try {
     // 从 API 获取模板列表
-    // await templateStore.fetchTemplates()
-    // templates.value = templateStore.templates
+    await templateStore.fetchTemplates()
+    templates.value = templateStore.templates
+  } catch (error) {
+    console.error('获取模板列表失败:', error)
+    ElMessage.error('获取模板列表失败')
   } finally {
     loading.value = false
   }

+ 1 - 1
frontend/vue-demo/vite.config.js

@@ -7,7 +7,7 @@ import vue from '@vitejs/plugin-vue'
 // 
 // 修改下方 API_SERVER 变量即可切换
 
-const API_SERVER = process.env.API_SERVER || 'http://localhost:18521'
+const API_SERVER = process.env.API_SERVER || 'http://47.101.133.94:18520'
 
 export default defineConfig({
   plugins: [vue()],