feat: 添加投标信息按日期范围更新功能及AI推荐持久化

添加按日期范围更新投标信息的功能,支持日期范围选择和数据更新
实现AI推荐结果的持久化存储和加载功能
优化日期范围选择器的本地存储功能
This commit is contained in:
dmy
2026-01-12 19:50:51 +08:00
parent 2b21ddb990
commit af58d770b6
8 changed files with 227 additions and 13 deletions

View File

@@ -43,6 +43,7 @@
:loading="loading"
:is-crawling="isCrawling"
@refresh="fetchData"
@update-bids="updateBidsByDateRange"
/>
<DashboardAI
@@ -73,6 +74,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { DataBoard, Document, Setting, MagicStick } from '@element-plus/icons-vue'
import Dashboard from './components/Dashboard.vue'
import DashboardAI from './components/Dashboard-AI.vue'
@@ -142,6 +144,26 @@ const fetchData = async () => {
}
}
// 根据日期范围更新投标信息
const updateBidsByDateRange = async (startDate: string, endDate?: string) => {
loading.value = true
try {
const params: any = { startDate }
if (endDate) {
params.endDate = endDate
}
const response = await axios.get('/api/bids/by-date-range', { params })
todayBids.value = response.data
ElMessage.success(`更新成功,共 ${response.data.length} 条数据`)
} catch (error) {
console.error('Failed to update bids by date range:', error)
ElMessage.error('更新失败')
} finally {
loading.value = false
}
}
onMounted(() => {
fetchData()
})

View File

@@ -106,7 +106,7 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, watch } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { MagicStick, Loading, InfoFilled, List } from '@element-plus/icons-vue'
@@ -132,6 +132,37 @@ const showAllBids = ref(false)
const bidsLoading = ref(false)
const bidsByDateRange = ref<any[]>([])
// 从 localStorage 加载保存的日期范围
const loadSavedDateRange = () => {
const saved = localStorage.getItem('dashboardAI_dateRange')
if (saved) {
try {
dateRange.value = JSON.parse(saved)
} catch (e) {
console.error('Failed to parse saved date range:', e)
}
}
}
// 监听日期范围变化并保存到 localStorage
watch(dateRange, (newDateRange) => {
localStorage.setItem('dashboardAI_dateRange', JSON.stringify(newDateRange))
}, { deep: true })
// 从数据库加载最新的 AI 推荐
const loadLatestRecommendations = async () => {
try {
const response = await axios.get('/api/ai/latest-recommendations')
aiRecommendations.value = response.data
} catch (error) {
console.error('Failed to load latest recommendations:', error)
}
}
// 初始化时加载保存的日期范围和最新的 AI 推荐
loadSavedDateRange()
loadLatestRecommendations()
// 设置日期范围为最近3天
const setLast3Days = () => {
const endDate = new Date()
@@ -181,7 +212,7 @@ const fetchAIRecommendations = async () => {
})
// 根据 title 从 bidsByDateRange 中更新 url 和 source
aiRecommendations.value = response.data.map((rec: any) => {
const recommendations = response.data.map((rec: any) => {
const bid = bidsByDateRange.value.find(b => b.title === rec.title)
return {
title: rec.title,
@@ -191,6 +222,13 @@ const fetchAIRecommendations = async () => {
}
})
aiRecommendations.value = recommendations
// 保存推荐结果到数据库
await axios.post('/api/ai/save-recommendations', {
recommendations
})
ElMessage.success('AI 推荐获取成功')
} catch (error: any) {
ElMessage.error('获取 AI 推荐失败')
@@ -247,9 +285,6 @@ const getConfidenceType = (confidence: number) => {
if (confidence >= 70) return 'warning'
return 'info'
}
// 初始化时设置默认日期范围为最近3天
setLast3Days()
</script>
<style scoped>

View File

@@ -56,6 +56,10 @@
/>
<el-button type="primary" @click="setLast3Days">3天</el-button>
<el-button type="primary" @click="setLast7Days">7天</el-button>
<el-button type="success" :loading="updating" @click="updateBidsByDateRange">
<el-icon style="margin-right: 5px"><Refresh /></el-icon>
更新
</el-button>
<el-select
v-model="selectedKeywords"
multiple
@@ -107,14 +111,33 @@ const props = defineProps<Props>()
const emit = defineEmits<{
crawl: []
refresh: []
updateBids: [startDate: string, endDate?: string]
}>()
const selectedKeywords = ref<string[]>([])
const dateRange = ref<[string, string] | null>(null)
const crawling = ref(false)
const updating = ref(false)
const highPriorityCollapsed = ref(false)
const isInitialized = ref(false)
// 从 localStorage 加载保存的日期范围
const loadSavedDateRange = () => {
const saved = localStorage.getItem('dashboard_dateRange')
if (saved) {
try {
dateRange.value = JSON.parse(saved)
} catch (e) {
console.error('Failed to parse saved date range:', e)
}
}
}
// 监听日期范围变化并保存到 localStorage
watch(dateRange, (newDateRange) => {
localStorage.setItem('dashboard_dateRange', JSON.stringify(newDateRange))
}, { deep: true })
// 切换 High Priority Bids 的折叠状态
const toggleHighPriority = () => {
highPriorityCollapsed.value = !highPriorityCollapsed.value
@@ -274,6 +297,36 @@ const setLast7Days = () => {
// 只在手动点击按钮时显示提示,初始化时不显示
}
// 根据日期范围更新投标信息
const updateBidsByDateRange = async () => {
if (!dateRange.value || dateRange.value.length !== 2) {
ElMessage.warning('请先选择日期范围')
return
}
updating.value = true
try {
const [startDate, endDate] = dateRange.value
// 检查 endDate 是否是今天
const today = new Date()
const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
// 如果 endDate 是今天,则不传递 endDate 参数(不限制截止时间)
if (endDate === todayStr) {
emit('updateBids', startDate)
} else {
emit('updateBids', startDate, endDate)
}
ElMessage.success('更新成功')
} catch (error) {
ElMessage.error('更新失败')
} finally {
updating.value = false
}
}
const handleCrawl = async () => {
if (props.isCrawling) {
ElMessage.warning('Crawl is already running')
@@ -291,11 +344,14 @@ const handleCrawl = async () => {
}
}
// 初始化时加载保存的关键字
// 初始化时加载保存的关键字和日期范围
loadSavedKeywords()
loadSavedDateRange()
// 初始化时设置默认日期范围为最近3天
setLast3Days()
// 如果没有保存的日期范围,则设置默认为最近3天
if (!dateRange.value) {
setLast3Days()
}
</script>
<style scoped>