fix: 隔离历史报告列表请求状态

This commit is contained in:
zxr
2026-08-03 22:06:35 +08:00
parent 809dc883f5
commit 3abdc187fb

View File

@@ -101,7 +101,7 @@ const formModel = ref<{
report_type: ReportType | '' report_type: ReportType | ''
status: ReportStatus | '' status: ReportStatus | ''
keyword: string keyword: string
timeRange: string[] timeRange?: string[]
}>({ }>({
report_type: '', report_type: '',
status: '', status: '',
@@ -152,6 +152,7 @@ const formItems = computed<FormItem[]>(() => [
const loading = ref(false) const loading = ref(false)
const downloadingId = ref<number | null>(null) const downloadingId = ref<number | null>(null)
const tableData = ref<ReportRecord[]>([]) const tableData = ref<ReportRecord[]>([])
let latestRequestId = 0
const pagination = reactive({ const pagination = reactive({
current: 1, current: 1,
@@ -214,41 +215,57 @@ const canDownloadPDF = (record: ReportRecord) =>
record.status === ReportStatus.SUCCESS && pdfReportTypes.has(record.report_type as ReportType) record.status === ReportStatus.SUCCESS && pdfReportTypes.has(record.report_type as ReportType)
const fetchList = async () => { const fetchList = async () => {
const requestId = ++latestRequestId
loading.value = true loading.value = true
const reportType = formModel.value.report_type
const status = formModel.value.status
const keyword = formModel.value.keyword.trim()
const timeRange = formModel.value.timeRange
const page = pagination.current
const size = pagination.pageSize
try { try {
const params: ReportListParams = { const params: ReportListParams = {
page: pagination.current, page,
size: pagination.pageSize, size,
} }
if (formModel.value.report_type) { if (reportType) {
params.report_type = formModel.value.report_type params.report_type = reportType
} }
if (formModel.value.status) { if (status) {
params.status = formModel.value.status params.status = status
} }
const keyword = formModel.value.keyword.trim()
if (keyword) { if (keyword) {
params.keyword = keyword params.keyword = keyword
} }
if (formModel.value.timeRange.length === 2) { if (timeRange?.length === 2 && timeRange[0] && timeRange[1]) {
params.created_from = formModel.value.timeRange[0] params.created_from = timeRange[0]
params.created_to = formModel.value.timeRange[1] params.created_to = timeRange[1]
} }
const res = await fetchReportList(params) const res = await fetchReportList(params)
if (requestId !== latestRequestId) return
if (res.code === 0 && res.details) { if (res.code === 0 && res.details) {
tableData.value = normalizeReportRows(res.details.data || []) tableData.value = normalizeReportRows(res.details.data || [])
pagination.total = res.details.total || 0 pagination.total = res.details.total || 0
} else { } else {
tableData.value = []
pagination.total = 0
Message.error(res.message || '获取报表列表失败') Message.error(res.message || '获取报表列表失败')
} }
} catch (error: any) { } catch (error: any) {
if (requestId !== latestRequestId) return
tableData.value = []
pagination.total = 0
console.error('获取报表列表失败:', error) console.error('获取报表列表失败:', error)
Message.error(error.message || '获取报表列表失败') Message.error(error.message || '获取报表列表失败')
} finally { } finally {
loading.value = false if (requestId === latestRequestId) {
loading.value = false
}
} }
} }