feat: 添加投标信息按日期范围更新功能及AI推荐持久化
添加按日期范围更新投标信息的功能,支持日期范围选择和数据更新 实现AI推荐结果的持久化存储和加载功能 优化日期范围选择器的本地存储功能
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user