连接GET:search

Change-Id: I99c843e128508e37d6c93358e857410d78c6f5c0
diff --git a/src/views/torrent/TorrentsView.vue b/src/views/torrent/TorrentsView.vue
index 28b73f1..736c92d 100644
--- a/src/views/torrent/TorrentsView.vue
+++ b/src/views/torrent/TorrentsView.vue
@@ -27,10 +27,9 @@
       
       <div class="filters">
         <el-select v-model="selectedCategory" placeholder="分类" @change="handleFilter">
-          <el-option label="全部" value="" />
           <el-option
-            v-for="category in categories"
-            :key="category.id"
+            v-for="category in categoryOptions"
+            :key="category.slug"
             :label="category.name"
             :value="category.slug"
           />
@@ -155,7 +154,7 @@
 </template>
 
 <script>
-import { ref, onMounted, watch } from 'vue'
+import { ref, onMounted, watch, computed } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 import { ElMessage } from 'element-plus'
 import {
@@ -206,39 +205,33 @@
     const fetchTorrents = async () => {
       loading.value = true
       try {
-        const searchParams = {
-          keyword: searchQuery.value || '', // 搜索关键词
-          //category: selectedCategory.value || '',
-          page: currentPage.value - 1,      // 后端页码从0开始
-          entriesPerPage: pageSize.value    // 每页显示数量
-        }
+        if (selectedCategory.value) {
+          // 使用 GET 请求
+          const response = await fetch(`/api/torrent/search?category=${selectedCategory.value}`)
+        .then(res => res.json())
 
-        console.log('🔍 发送搜索请求,参数:', searchParams)
-        
-        const response = await searchTorrents(searchParams)
-
-        console.log('✅ 接收到响应:', response)
-        
-        if (response) {  // response直接就是数据
           torrents.value = response.torrents || []
           totalCount.value = response.totalElements || 0
           totalPages.value = response.totalPages || 1
-          
-          console.log('📊 处理后的数据:', {
-            torrentsCount: torrents.value.length,
-            totalCount: totalCount.value,
-            firstTorrent: torrents.value[0]
-          })
+
+        } else {
+          // 使用 POST 请求(搜索)
+          const searchParams = {
+            keyword: searchQuery.value || '',
+            page: currentPage.value - 1,
+            entriesPerPage: pageSize.value
+          }
+
+          const response = await searchTorrents(searchParams)
+
+          torrents.value = response.torrents || []
+          totalCount.value = response.totalElements || 0
+          totalPages.value = response.totalPages || 1
         }
+
       } catch (error) {
         console.error('获取种子列表失败:', error)
-        console.error('📝 错误详情:', {
-          message: error.message,
-          status: error.response?.status,
-          data: error.response?.data
-        })
-        ElMessage.error(`获取种子列表失败: ${error.response?.data?.message || error.message}`)
-        // 如果请求失败,清空数据
+        ElMessage.error('获取种子列表失败')
         torrents.value = []
         totalCount.value = 0
       } finally {
@@ -249,10 +242,14 @@
     const fetchCategories = async () => {
       try {
         const response = await getCategories()
+        console.log('分类列表响应:', response)
+        
         if (response && Array.isArray(response)) {
           categories.value = response
+          console.log('分类列表加载成功:', categories.value)
         } else {
           console.error('获取分类列表失败: 响应格式错误', response)
+          ElMessage.warning('分类列表格式不正确')
         }
       } catch (error) {
         console.error('获取分类列表失败:', error)
@@ -345,6 +342,13 @@
       return types[category.slug] || ''
     }
     
+    const categoryOptions = computed(() => {
+      return [
+        { id: '', name: '全部' },
+        ...categories.value
+      ]
+    })
+    
     return {
       loading,
       searchQuery,
@@ -356,6 +360,7 @@
       totalCount,
       torrents,
       categories,
+      categoryOptions,
       handleSearch,
       handleFilter,
       handleRowClick,