feat: 全面升级系统日志和反爬虫功能
- 新增专业日志系统:集成 Winston 日志框架,支持按天轮转和分级存储 - 增强反爬虫能力:集成 puppeteer-extra-plugin-stealth 插件,提升隐蔽性 - 新增独立爬虫脚本:可通过 npm run crawl 命令单独执行爬虫任务 - 优化前端日期筛选:添加日期范围选择器,支持3天/7天快速筛选 - 改进爬虫统计功能:详细记录每个平台的成功/失败情况和执行时间 - 移除默认关键词初始化:避免重复创建预设关键词 - 扩展环境配置:新增 LOG_LEVEL 日志级别配置选项 - 增强.gitignore:添加日志目录、构建产物等忽略规则 - 升级执行时间限制:将最大执行时间从1小时延长至3小时 - 完善错误处理:更好的异常捕获和日志记录机制
This commit is contained in:
@@ -65,22 +65,37 @@
|
||||
<el-divider />
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
||||
<h3 style="margin: 0;">Today's Bids</h3>
|
||||
<el-select
|
||||
v-model="selectedKeywords"
|
||||
multiple
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="Filter by Keywords"
|
||||
clearable
|
||||
style="width: 300px;"
|
||||
>
|
||||
<el-option
|
||||
v-for="keyword in keywords"
|
||||
:key="keyword.id"
|
||||
:label="keyword.word"
|
||||
:value="keyword.word"
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
type="daterange"
|
||||
range-separator="To"
|
||||
start-placeholder="Start Date"
|
||||
end-placeholder="End Date"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
clearable
|
||||
style="width: 240px;"
|
||||
/>
|
||||
</el-select>
|
||||
<el-button type="primary" @click="setLast3Days">3天</el-button>
|
||||
<el-button type="primary" @click="setLast7Days">7天</el-button>
|
||||
<el-select
|
||||
v-model="selectedKeywords"
|
||||
multiple
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="Filter by Keywords"
|
||||
clearable
|
||||
style="width: 300px;"
|
||||
>
|
||||
<el-option
|
||||
v-for="keyword in keywords"
|
||||
:key="keyword.id"
|
||||
:label="keyword.word"
|
||||
:value="keyword.word"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="filteredTodayBids" v-loading="loading" style="width: 100%">
|
||||
<el-table-column prop="title" label="Title">
|
||||
@@ -173,13 +188,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, computed, watch } from 'vue'
|
||||
import { ref, onMounted, reactive, computed, watch, nextTick } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { DataBoard, Document, Setting, Refresh } from '@element-plus/icons-vue'
|
||||
|
||||
const activeIndex = ref('1')
|
||||
const bids = ref<any[]>([])
|
||||
const todayBids = ref<any[]>([])
|
||||
const highPriorityBids = ref<any[]>([])
|
||||
const keywords = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
@@ -192,6 +208,7 @@ const total = ref(0)
|
||||
const sourceOptions = ref<string[]>([])
|
||||
const isCrawling = ref(false)
|
||||
const selectedKeywords = ref<string[]>([])
|
||||
const dateRange = ref<[string, string] | null>(null)
|
||||
|
||||
// 从 localStorage 加载保存的关键字
|
||||
const loadSavedKeywords = () => {
|
||||
@@ -210,6 +227,16 @@ watch(selectedKeywords, (newKeywords) => {
|
||||
localStorage.setItem('selectedKeywords', JSON.stringify(newKeywords))
|
||||
}, { deep: true })
|
||||
|
||||
// 监听日期范围变化并显示提示
|
||||
watch(dateRange, () => {
|
||||
const totalBids = bids.value.length
|
||||
const filteredCount = filteredTodayBids.value.length
|
||||
|
||||
if (totalBids > 0 && filteredCount < totalBids) {
|
||||
ElMessage.info(`筛选结果:共 ${filteredCount} 条数据(总共 ${totalBids} 条)`)
|
||||
}
|
||||
})
|
||||
|
||||
const form = reactive({
|
||||
word: '',
|
||||
weight: 1
|
||||
@@ -241,24 +268,134 @@ const handleSizeChange = (size: number) => {
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 设置日期范围为最近3天
|
||||
const setLast3Days = () => {
|
||||
const endDate = new Date()
|
||||
const startDate = new Date()
|
||||
startDate.setDate(startDate.getDate() - 2) // 最近3天(包括今天)
|
||||
|
||||
const formatDateForPicker = (date: Date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
dateRange.value = [formatDateForPicker(startDate), formatDateForPicker(endDate)]
|
||||
|
||||
console.log('setLast3Days called, todayBids:', todayBids.value.length, 'dateRange:', dateRange.value)
|
||||
|
||||
// 直接计算筛选结果并显示提示
|
||||
const start = new Date(startDate)
|
||||
start.setHours(0, 0, 0, 0)
|
||||
const end = new Date(endDate)
|
||||
end.setHours(23, 59, 59, 999)
|
||||
|
||||
let result = todayBids.value
|
||||
result = result.filter(bid => {
|
||||
if (!bid.publishDate) return false
|
||||
const bidDate = new Date(bid.publishDate)
|
||||
return bidDate >= start && bidDate <= end
|
||||
})
|
||||
|
||||
const totalBids = todayBids.value.length
|
||||
const filteredCount = result.length
|
||||
|
||||
console.log('setLast3Days result, totalBids:', totalBids, 'filteredCount:', filteredCount)
|
||||
if (totalBids > 0) {
|
||||
ElMessage.info(`筛选结果:共 ${filteredCount} 条数据(总共 ${totalBids} 条)`)
|
||||
} else {
|
||||
ElMessage.warning('暂无数据,请先抓取数据')
|
||||
}
|
||||
}
|
||||
|
||||
// 设置日期范围为最近7天
|
||||
const setLast7Days = () => {
|
||||
const endDate = new Date()
|
||||
const startDate = new Date()
|
||||
startDate.setDate(startDate.getDate() - 6) // 最近7天(包括今天)
|
||||
|
||||
const formatDateForPicker = (date: Date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
dateRange.value = [formatDateForPicker(startDate), formatDateForPicker(endDate)]
|
||||
|
||||
console.log('setLast7Days called, todayBids:', todayBids.value.length, 'dateRange:', dateRange.value)
|
||||
|
||||
// 直接计算筛选结果并显示提示
|
||||
const start = new Date(startDate)
|
||||
start.setHours(0, 0, 0, 0)
|
||||
const end = new Date(endDate)
|
||||
end.setHours(23, 59, 59, 999)
|
||||
|
||||
let result = todayBids.value
|
||||
result = result.filter(bid => {
|
||||
if (!bid.publishDate) return false
|
||||
const bidDate = new Date(bid.publishDate)
|
||||
return bidDate >= start && bidDate <= end
|
||||
})
|
||||
|
||||
const totalBids = todayBids.value.length
|
||||
const filteredCount = result.length
|
||||
|
||||
console.log('setLast7Days result, totalBids:', totalBids, 'filteredCount:', filteredCount)
|
||||
if (totalBids > 0) {
|
||||
ElMessage.info(`筛选结果:共 ${filteredCount} 条数据(总共 ${totalBids} 条)`)
|
||||
} else {
|
||||
ElMessage.warning('暂无数据,请先抓取数据')
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
if (!dateString) return '-'
|
||||
return new Date(dateString).toLocaleDateString()
|
||||
}
|
||||
|
||||
// 过滤 Today's Bids,只显示包含所选关键字的项目
|
||||
// 过滤 Today's Bids,只显示包含所选关键字的项目,并且在日期范围内
|
||||
const filteredTodayBids = computed(() => {
|
||||
if (selectedKeywords.value.length === 0) {
|
||||
return bids.value
|
||||
let result = todayBids.value
|
||||
|
||||
// 按关键字筛选
|
||||
if (selectedKeywords.value.length > 0) {
|
||||
result = result.filter(bid => {
|
||||
return selectedKeywords.value.some(keyword =>
|
||||
bid.title.toLowerCase().includes(keyword.toLowerCase())
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return bids.value.filter(bid => {
|
||||
return selectedKeywords.value.some(keyword =>
|
||||
bid.title.toLowerCase().includes(keyword.toLowerCase())
|
||||
)
|
||||
})
|
||||
// 按日期范围筛选
|
||||
if (dateRange.value && dateRange.value.length === 2) {
|
||||
const [startDate, endDate] = dateRange.value
|
||||
result = result.filter(bid => {
|
||||
if (!bid.publishDate) return false
|
||||
const bidDate = new Date(bid.publishDate)
|
||||
const start = new Date(startDate)
|
||||
const end = new Date(endDate)
|
||||
// 设置时间为当天的开始和结束
|
||||
start.setHours(0, 0, 0, 0)
|
||||
end.setHours(23, 59, 59, 999)
|
||||
return bidDate >= start && bidDate <= end
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
// 监听筛选结果变化并显示提示
|
||||
watch(filteredTodayBids, (newFilteredBids) => {
|
||||
const totalBids = todayBids.value.length
|
||||
const filteredCount = newFilteredBids.length
|
||||
|
||||
if (totalBids > 0 && filteredCount < totalBids) {
|
||||
ElMessage.info(`筛选结果:共 ${filteredCount} 条数据(总共 ${totalBids} 条)`)
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -281,6 +418,15 @@ const fetchData = async () => {
|
||||
keywords.value = kwRes.data
|
||||
sourceOptions.value = sourcesRes.data
|
||||
isCrawling.value = statusRes.data.isCrawling
|
||||
|
||||
// 过滤今天的数据用于 Today's Bids
|
||||
const today = new Date()
|
||||
today.setHours(0, 0, 0, 0)
|
||||
todayBids.value = bidsRes.data.items.filter((bid: any) => {
|
||||
if (!bid.publishDate) return false
|
||||
const bidDate = new Date(bid.publishDate)
|
||||
return bidDate >= today
|
||||
})
|
||||
} catch (error) {
|
||||
ElMessage.error('Failed to fetch data')
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user