Browse Source

增加loading,修改超时时间

gcz 3 weeks ago
parent
commit
01cc570490
2 changed files with 13 additions and 7 deletions
  1. 1 1
      src/utils/request.js
  2. 12 6
      src/views/Statistics.vue

+ 1 - 1
src/utils/request.js

@@ -4,7 +4,7 @@ import { ElMessage } from 'element-plus'
 // 创建 axios 实例
 const service = axios.create({
   baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
-  timeout: 10000, // 请求超时时间
+  timeout: 99910000, // 请求超时时间
   headers: {
     'Content-Type': 'application/json'
   }

+ 12 - 6
src/views/Statistics.vue

@@ -297,6 +297,7 @@ import {
 } from 'echarts/components'
 import { CanvasRenderer } from 'echarts/renderers'
 import { ElMessage } from 'element-plus'
+import { ElLoading } from 'element-plus'
 
 import { getStatisticsData } from '@/api/statistics'
 
@@ -390,6 +391,12 @@ const offlineChartType = ref('salesAmount')
 
 // 处理日期变化
 const handleDateChange = async () => {
+  const loading = ElLoading.service({
+    lock: true,
+    text: '数据请求中...',
+    background: 'rgba(255, 255, 255, 0.7)'
+  })
+
   try {
     const formatDateTime = (date, isEndTime = false) => {
       const year = date.getFullYear()
@@ -402,12 +409,9 @@ const handleDateChange = async () => {
       beginTime: formatDateTime(selectedDate.value),
       endTime: formatDateTime(selectedDate.value, true)
     }
-    // console.log('params',params)
 
     const response = await getStatisticsData(params)
 
-    // console.log('response',response)
-
     if (response.code === 200) {
       // 更新线上数据
       onlineData.value = response.data.onlineData.chartData.map(item => ({
@@ -421,10 +425,10 @@ const handleDateChange = async () => {
         salesAmount: item.settlementPrice
       }))
 
-      // console.log('onlineData',onlineData.value)
-
       // 更新线下数据
-      offlineData.value = response.data.offData.offDataList.map(item => ({
+      // 返回的offData可能为null
+      const offData = response.data.offData?.offDataList || [];
+      offlineData.value = offData.map(item => ({
         type: item.productName,
         reservedCount: item.totalNum,
         verifiedCount: item.useNum,
@@ -445,6 +449,8 @@ const handleDateChange = async () => {
   } catch (error) {
     console.error('获取统计数据失败:', error)
     ElMessage.error('获取统计数据失败')
+  } finally {
+    loading.close()
   }
 }