fix: 隔离历史报告列表请求状态
This commit is contained in:
@@ -101,7 +101,7 @@ const formModel = ref<{
|
||||
report_type: ReportType | ''
|
||||
status: ReportStatus | ''
|
||||
keyword: string
|
||||
timeRange: string[]
|
||||
timeRange?: string[]
|
||||
}>({
|
||||
report_type: '',
|
||||
status: '',
|
||||
@@ -152,6 +152,7 @@ const formItems = computed<FormItem[]>(() => [
|
||||
const loading = ref(false)
|
||||
const downloadingId = ref<number | null>(null)
|
||||
const tableData = ref<ReportRecord[]>([])
|
||||
let latestRequestId = 0
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -214,41 +215,57 @@ const canDownloadPDF = (record: ReportRecord) =>
|
||||
record.status === ReportStatus.SUCCESS && pdfReportTypes.has(record.report_type as ReportType)
|
||||
|
||||
const fetchList = async () => {
|
||||
const requestId = ++latestRequestId
|
||||
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 {
|
||||
const params: ReportListParams = {
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
page,
|
||||
size,
|
||||
}
|
||||
|
||||
if (formModel.value.report_type) {
|
||||
params.report_type = formModel.value.report_type
|
||||
if (reportType) {
|
||||
params.report_type = reportType
|
||||
}
|
||||
if (formModel.value.status) {
|
||||
params.status = formModel.value.status
|
||||
if (status) {
|
||||
params.status = status
|
||||
}
|
||||
const keyword = formModel.value.keyword.trim()
|
||||
if (keyword) {
|
||||
params.keyword = keyword
|
||||
}
|
||||
if (formModel.value.timeRange.length === 2) {
|
||||
params.created_from = formModel.value.timeRange[0]
|
||||
params.created_to = formModel.value.timeRange[1]
|
||||
if (timeRange?.length === 2 && timeRange[0] && timeRange[1]) {
|
||||
params.created_from = timeRange[0]
|
||||
params.created_to = timeRange[1]
|
||||
}
|
||||
|
||||
const res = await fetchReportList(params)
|
||||
if (requestId !== latestRequestId) return
|
||||
|
||||
if (res.code === 0 && res.details) {
|
||||
tableData.value = normalizeReportRows(res.details.data || [])
|
||||
pagination.total = res.details.total || 0
|
||||
} else {
|
||||
tableData.value = []
|
||||
pagination.total = 0
|
||||
Message.error(res.message || '获取报表列表失败')
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (requestId !== latestRequestId) return
|
||||
|
||||
tableData.value = []
|
||||
pagination.total = 0
|
||||
console.error('获取报表列表失败:', error)
|
||||
Message.error(error.message || '获取报表列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (requestId === latestRequestId) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user