From feb18c01bb5ff04e4d908d949f4f87de27037480 Mon Sep 17 00:00:00 2001 From: dmy Date: Tue, 13 Jan 2026 21:03:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E6=8F=90=E5=8F=96=E4=B8=BA?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Dashboard-AI.vue | 104 +------------------ frontend/src/components/Dashboard.vue | 2 + frontend/src/components/PinnedProject.vue | 121 ++++++++++++++++++++++ 3 files changed, 126 insertions(+), 101 deletions(-) create mode 100644 frontend/src/components/PinnedProject.vue diff --git a/frontend/src/components/Dashboard-AI.vue b/frontend/src/components/Dashboard-AI.vue index 71cfccc..d7f6e1a 100644 --- a/frontend/src/components/Dashboard-AI.vue +++ b/frontend/src/components/Dashboard-AI.vue @@ -7,55 +7,7 @@ 获取 AI 推荐 - - - - -
- -

加载中...

-
-
- -

暂无置顶项目

-
-
- - - - - - - - - - - - -
-
-
-
+ @@ -178,6 +130,7 @@ import { ref, watch } from 'vue' import axios from 'axios' import { ElMessage } from 'element-plus' import { MagicStick, Loading, InfoFilled, List, ArrowDown, Paperclip } from '@element-plus/icons-vue' +import PinnedProject from './PinnedProject.vue' interface AIRecommendation { @@ -201,8 +154,6 @@ const dateRange = ref<[string, string] | null>(null) const showAllBids = ref(false) const bidsLoading = ref(false) const bidsByDateRange = ref([]) -const pinnedBids = ref([]) -const pinnedLoading = ref(false) // 从 localStorage 加载保存的日期范围 const loadSavedDateRange = () => { @@ -241,23 +192,9 @@ const loadLatestRecommendations = async () => { } } -// 加载置顶项目 -const loadPinnedBids = async () => { - pinnedLoading.value = true - try { - const response = await axios.get('/api/bids/pinned') - pinnedBids.value = response.data - } catch (error) { - console.error('Failed to load pinned bids:', error) - } finally { - pinnedLoading.value = false - } -} - -// 初始化时加载保存的日期范围、最新的 AI 推荐和置顶项目 +// 初始化时加载保存的日期范围和最新的 AI 推荐 loadSavedDateRange() loadLatestRecommendations() -loadPinnedBids() // 设置日期范围为最近3天 const setLast3Days = () => { @@ -397,46 +334,11 @@ const togglePin = async (item: AIRecommendation) => { const newPinStatus = !item.pin await axios.patch(`/api/bids/${encodeURIComponent(item.title)}/pin`, { pin: newPinStatus }) item.pin = newPinStatus - if (newPinStatus) { - // 添加到置顶列表 - pinnedBids.value.unshift({ - title: item.title, - url: item.url, - source: item.source, - publishDate: item.publishDate, - pin: true - }) - } else { - // 从置顶列表移除 - const index = pinnedBids.value.findIndex(b => b.title === item.title) - if (index !== -1) { - pinnedBids.value.splice(index, 1) - } - } ElMessage.success(newPinStatus ? '已置顶' : '已取消置顶') } catch (error) { ElMessage.error('操作失败') } } - -// 切换置顶列表的 Pin 状态 -const togglePinnedPin = async (item: any) => { - try { - await axios.patch(`/api/bids/${encodeURIComponent(item.title)}/pin`, { pin: false }) - const index = pinnedBids.value.findIndex(b => b.title === item.title) - if (index !== -1) { - pinnedBids.value.splice(index, 1) - } - // 同时更新 AI 推荐列表中的状态 - const aiItem = aiRecommendations.value.find(r => r.title === item.title) - if (aiItem) { - aiItem.pin = false - } - ElMessage.success('已取消置顶') - } catch (error) { - ElMessage.error('操作失败') - } -}