feat: 添加AI推荐功能及自动刷新机制

新增AI推荐模块,包括后端数据获取接口和前端展示组件
实现自动刷新功能,每5分钟自动更新当前标签页数据
添加手动刷新按钮,优化用户交互体验
This commit is contained in:
dmy
2026-01-14 01:06:15 +08:00
parent 8e4429558c
commit 6a9c52fe10
8 changed files with 317 additions and 6 deletions

View File

@@ -1,13 +1,47 @@
<script lang="ts" setup>
import { ref } from 'vue'
import { ref, onMounted, onUnmounted } from 'vue'
import PinnedBids from './components/PinnedBids.vue'
import AiRecommendations from './components/AiRecommendations.vue'
const activeTab = ref('pinned')
const pinnedBidsRef = ref<InstanceType<typeof PinnedBids>>()
const aiRecommendationsRef = ref<InstanceType<typeof AiRecommendations>>()
let refreshTimer: number | null = null
const tabs = [
{ id: 'pinned', label: '置顶项目' },
{ id: 'other', label: '其他' }
{ id: 'ai', label: 'AI 推荐' }
]
const handleRefresh = () => {
if (activeTab.value === 'pinned' && pinnedBidsRef.value) {
pinnedBidsRef.value.loadPinnedBids()
} else if (activeTab.value === 'ai' && aiRecommendationsRef.value) {
aiRecommendationsRef.value.loadRecommendations()
}
}
const startAutoRefresh = () => {
// 每5分钟300000毫秒自动刷新
refreshTimer = window.setInterval(() => {
handleRefresh()
}, 300000)
}
const stopAutoRefresh = () => {
if (refreshTimer !== null) {
clearInterval(refreshTimer)
refreshTimer = null
}
}
onMounted(() => {
startAutoRefresh()
})
onUnmounted(() => {
stopAutoRefresh()
})
</script>
<template>
@@ -21,13 +55,14 @@ const tabs = [
>
{{ tab.label }}
</button>
<button class="refresh-button" @click="handleRefresh">
🔄 刷新
</button>
</div>
<div class="tab-content">
<PinnedBids v-if="activeTab === 'pinned'"/>
<div v-else class="placeholder">
<p>暂无内容</p>
</div>
<PinnedBids v-if="activeTab === 'pinned'" ref="pinnedBidsRef"/>
<AiRecommendations v-else-if="activeTab === 'ai'" ref="aiRecommendationsRef"/>
</div>
</div>
</template>
@@ -82,6 +117,26 @@ body {
padding: 20px;
}
.refresh-button {
margin-left: auto;
padding: 8px 16px;
background: #3498db;
color: #fff;
border: none;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s ease;
}
.refresh-button:hover {
background: #2980b9;
}
.refresh-button:active {
transform: scale(0.98);
}
.placeholder {
display: flex;
align-items: center;