feat: 添加关键词筛选功能并优化日期范围更新

- 在 updateBidsByDateRange 中添加关键词筛选参数
- 优化日期范围更新逻辑,避免重复提示
- 添加 build:watch 脚本用于开发环境
This commit is contained in:
dmy
2026-01-12 20:24:45 +08:00
parent af58d770b6
commit 533d7b60fb
3 changed files with 23 additions and 48 deletions

View File

@@ -6,6 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vue-tsc -b && vite build", "build": "vue-tsc -b && vite build",
"build:watch": "vue-tsc -b && vite build --watch",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {

View File

@@ -145,13 +145,16 @@ const fetchData = async () => {
} }
// 根据日期范围更新投标信息 // 根据日期范围更新投标信息
const updateBidsByDateRange = async (startDate: string, endDate?: string) => { const updateBidsByDateRange = async (startDate: string, endDate?: string, keywords?: string[]) => {
loading.value = true loading.value = true
try { try {
const params: any = { startDate } const params: any = { startDate }
if (endDate) { if (endDate) {
params.endDate = endDate params.endDate = endDate
} }
if (keywords && keywords.length > 0) {
params.keywords = keywords.join(',')
}
const response = await axios.get('/api/bids/by-date-range', { params }) const response = await axios.get('/api/bids/by-date-range', { params })
todayBids.value = response.data todayBids.value = response.data

View File

@@ -111,7 +111,7 @@ const props = defineProps<Props>()
const emit = defineEmits<{ const emit = defineEmits<{
crawl: [] crawl: []
refresh: [] refresh: []
updateBids: [startDate: string, endDate?: string] updateBids: [startDate: string, endDate?: string, keywords?: string[]]
}>() }>()
const selectedKeywords = ref<string[]>([]) const selectedKeywords = ref<string[]>([])
@@ -120,6 +120,7 @@ const crawling = ref(false)
const updating = ref(false) const updating = ref(false)
const highPriorityCollapsed = ref(false) const highPriorityCollapsed = ref(false)
const isInitialized = ref(false) const isInitialized = ref(false)
const isManualClick = ref(false)
// 从 localStorage 加载保存的日期范围 // 从 localStorage 加载保存的日期范围
const loadSavedDateRange = () => { const loadSavedDateRange = () => {
@@ -175,6 +176,12 @@ watch(dateRange, () => {
return return
} }
// 手动点击时不显示提示(避免和按钮点击重复)
if (isManualClick.value) {
isManualClick.value = false
return
}
const totalBids = props.todayBids.length const totalBids = props.todayBids.length
const filteredCount = filteredTodayBids.value.length const filteredCount = filteredTodayBids.value.length
@@ -217,18 +224,9 @@ const filteredTodayBids = computed(() => {
return result return result
}) })
// 监听筛选结果变化并显示提示
watch(filteredTodayBids, (newFilteredBids) => {
const totalBids = props.todayBids.length
const filteredCount = newFilteredBids.length
if (totalBids > 0 && filteredCount < totalBids) {
ElMessage.info(`筛选结果:共 ${filteredCount} 条数据(总共 ${totalBids} 条)`)
}
}, { deep: true })
// 设置日期范围为最近3天 // 设置日期范围为最近3天
const setLast3Days = () => { const setLast3Days = async () => {
isManualClick.value = true
const endDate = new Date() const endDate = new Date()
const startDate = new Date() const startDate = new Date()
startDate.setDate(startDate.getDate() - 2) // 最近3天包括今天 startDate.setDate(startDate.getDate() - 2) // 最近3天包括今天
@@ -244,26 +242,13 @@ const setLast3Days = () => {
console.log('setLast3Days called, todayBids:', props.todayBids.length, 'dateRange:', dateRange.value) console.log('setLast3Days called, todayBids:', props.todayBids.length, 'dateRange:', dateRange.value)
// 直接计算筛选结果并显示提示(只限制开始时间,不限制结束时间) // 调用更新函数
const start = new Date(startDate) await updateBidsByDateRange()
start.setHours(0, 0, 0, 0)
let result = props.todayBids
result = result.filter(bid => {
if (!bid.publishDate) return false
const bidDate = new Date(bid.publishDate)
return bidDate >= start
})
const totalBids = props.todayBids.length
const filteredCount = result.length
console.log('setLast3Days result, totalBids:', totalBids, 'filteredCount:', filteredCount)
// 只在手动点击按钮时显示提示,初始化时不显示
} }
// 设置日期范围为最近7天 // 设置日期范围为最近7天
const setLast7Days = () => { const setLast7Days = async () => {
isManualClick.value = true
const endDate = new Date() const endDate = new Date()
const startDate = new Date() const startDate = new Date()
startDate.setDate(startDate.getDate() - 6) // 最近7天包括今天 startDate.setDate(startDate.getDate() - 6) // 最近7天包括今天
@@ -279,22 +264,8 @@ const setLast7Days = () => {
console.log('setLast7Days called, todayBids:', props.todayBids.length, 'dateRange:', dateRange.value) console.log('setLast7Days called, todayBids:', props.todayBids.length, 'dateRange:', dateRange.value)
// 直接计算筛选结果并显示提示(只限制开始时间,不限制结束时间) // 调用更新函数
const start = new Date(startDate) await updateBidsByDateRange()
start.setHours(0, 0, 0, 0)
let result = props.todayBids
result = result.filter(bid => {
if (!bid.publishDate) return false
const bidDate = new Date(bid.publishDate)
return bidDate >= start
})
const totalBids = props.todayBids.length
const filteredCount = result.length
console.log('setLast7Days result, totalBids:', totalBids, 'filteredCount:', filteredCount)
// 只在手动点击按钮时显示提示,初始化时不显示
} }
// 根据日期范围更新投标信息 // 根据日期范围更新投标信息
@@ -314,9 +285,9 @@ const updateBidsByDateRange = async () => {
// 如果 endDate 是今天,则不传递 endDate 参数(不限制截止时间) // 如果 endDate 是今天,则不传递 endDate 参数(不限制截止时间)
if (endDate === todayStr) { if (endDate === todayStr) {
emit('updateBids', startDate) emit('updateBids', startDate, undefined, selectedKeywords.value)
} else { } else {
emit('updateBids', startDate, endDate) emit('updateBids', startDate, endDate, selectedKeywords.value)
} }
ElMessage.success('更新成功') ElMessage.success('更新成功')