fix: 处理错误信息字段的空值和空字符串

更新多个文件以确保错误信息字段在处理时将空字符串和未定义值转换为null,增强数据一致性和展示逻辑。包括前端组件和后端服务的相应调整。
This commit is contained in:
dmy
2026-01-14 21:33:35 +08:00
parent 740c11527f
commit 10565af001
4 changed files with 9 additions and 7 deletions

View File

@@ -26,14 +26,14 @@
</el-table-column> </el-table-column>
<el-table-column label="状态" width="100"> <el-table-column label="状态" width="100">
<template #default="{ row }"> <template #default="{ row }">
<el-tag :type="row.error ? 'danger' : (row.count > 0 ? 'success' : 'info')"> <el-tag :type="row.error && row.error.trim() ? 'danger' : (row.count > 0 ? 'success' : 'info')">
{{ row.error ? '出错' : (row.count > 0 ? '正常' : '无数据') }} {{ row.error && row.error.trim() ? '出错' : (row.count > 0 ? '正常' : '无数据') }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="错误信息" min-width="200"> <el-table-column label="错误信息" min-width="200">
<template #default="{ row }"> <template #default="{ row }">
<span v-if="row.error" style="color: #f56c6c">{{ row.error }}</span> <span v-if="row.error && row.error.trim()" style="color: #f56c6c">{{ row.error }}</span>
<span v-else>-</span> <span v-else>-</span>
</template> </template>
</el-table-column> </el-table-column>
@@ -100,7 +100,7 @@ const activeSources = computed(() => {
}) })
const errorSources = computed(() => { const errorSources = computed(() => {
return crawlStats.value.filter(item => item.error).length return crawlStats.value.filter(item => item.error && item.error.trim()).length
}) })
const formatDate = (dateStr: string | null) => { const formatDate = (dateStr: string | null) => {

View File

@@ -143,7 +143,8 @@ export class BidsService {
count: item.count, count: item.count,
latestUpdate: item.latestUpdate, latestUpdate: item.latestUpdate,
latestPublishDate: item.latestPublishDate, latestPublishDate: item.latestPublishDate,
error: item.error, // 确保 error 字段正确处理null 或空字符串都转换为 null非空字符串保留
error: item.error && item.error.trim() !== '' ? item.error : null,
})); }));
} }
} }

View File

@@ -15,7 +15,7 @@ export class CrawlInfoAdd {
latestPublishDate: Date | null; latestPublishDate: Date | null;
@Column({ type: 'text', nullable: true }) @Column({ type: 'text', nullable: true })
error: string; error: string | null;
@CreateDateColumn() @CreateDateColumn()
createdAt: Date; createdAt: Date;

View File

@@ -318,7 +318,8 @@ export class BidCrawlerService {
source, source,
count, count,
latestPublishDate, latestPublishDate,
error, // 确保 error 字段正确处理undefined 或空字符串都转换为 null
error: error && error.trim() !== '' ? error : null,
}); });
await this.crawlInfoRepository.save(crawlInfo); await this.crawlInfoRepository.save(crawlInfo);
this.logger.log(`Saved crawl info for ${source}: ${count} items`); this.logger.log(`Saved crawl info for ${source}: ${count} items`);