From 534de6d2c08ce6bf0adb12776953d9f067a6832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Mon, 28 Sep 2026 17:22:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=84=E7=90=86=E4=BA=A4=E6=98=93?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E7=94=9F=E6=88=90=20execl=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=94=B9=E6=88=90=E7=82=B9=E5=87=BB=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=97=B6=E5=80=99=E5=86=8D=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistic/TradeStatisticController.php | 1 + .../statistic/TradeStatisticServices.php | 13 +++++++++---- .../transaction/components/transaction.vue | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/backend/app/adminapi/controller/statistic/TradeStatisticController.php b/backend/app/adminapi/controller/statistic/TradeStatisticController.php index 38da4c8e4..c2d3801dc 100644 --- a/backend/app/adminapi/controller/statistic/TradeStatisticController.php +++ b/backend/app/adminapi/controller/statistic/TradeStatisticController.php @@ -72,6 +72,7 @@ class TradeStatisticController extends AuthController { $day = $this->request->getMore([ ['data', ""], + ['export', 0], ]); $bottom = $this->services->getBottomTrade($day); return app('json')->success($bottom); diff --git a/backend/app/services/statistic/TradeStatisticServices.php b/backend/app/services/statistic/TradeStatisticServices.php index a5db2717f..065a7bbf5 100644 --- a/backend/app/services/statistic/TradeStatisticServices.php +++ b/backend/app/services/statistic/TradeStatisticServices.php @@ -246,8 +246,8 @@ class TradeStatisticServices extends BaseService $where['time'] = ['start_time' => date('Y-m-d 00:00:00', strtotime($time[0])), "end_time" => date('Y-m-d 23:59:59', strtotime($time[1]))]; } unset($where['data']); - /** @var ExportServices $exportService */ - $exportService = app()->make(ExportServices::class); + $isExport = !empty($where['export']); + unset($where['export']); $chainTime = $this->chainTime($where['time']); $isNum = false; if ($chainTime == "other") $isNum = true; @@ -428,8 +428,13 @@ class TradeStatisticServices extends BaseService $data['series'][$k]['rate'] = $v['rate']; $data['series'][$k]['value'] = array_values($v['value']); } - $export = $exportService->tradeData($data, '交易统计', 2); - $data['export'] = $export[0]; + // 仅导出请求时才生成 Excel 文件,普通查询不落盘 + if ($isExport) { + /** @var ExportServices $exportService */ + $exportService = app()->make(ExportServices::class); + $export = $exportService->tradeData($data, '交易统计', 2); + $data['export'] = $export[0]; + } return $data; } diff --git a/frontend/admin/src/pages/statistic/transaction/components/transaction.vue b/frontend/admin/src/pages/statistic/transaction/components/transaction.vue index 6390e2e68..35ee5eb70 100644 --- a/frontend/admin/src/pages/statistic/transaction/components/transaction.vue +++ b/frontend/admin/src/pages/statistic/transaction/components/transaction.vue @@ -109,7 +109,6 @@ const dataTime = ref(''); const list = ref({}); const optionData = ref({}); const style = { height: '400px' }; -const getExcel = ref(''); const spinShow = ref(false); // created @@ -154,7 +153,6 @@ function getStatistics() { cardLists.series[i]['icon'] = incons[i]; } list.value = cardLists.series; - getExcel.value = cardLists.export; get(cardLists); spinShow.value = false; }) @@ -249,8 +247,22 @@ function get(extract) { series: seriesData, }; } +// 导出:携带 export 参数请求后端生成 Excel,拿到地址后触发下载 function excel() { - window.location.href = getExcel.value; + spinShow.value = true; + statisticBottomTradeApi({ data: dataTime.value, export: 1 }) + .then((res) => { + spinShow.value = false; + if (res.data.export) { + window.location.href = res.data.export; + } else { + ElMessage.error('导出文件生成失败'); + } + }) + .catch((res) => { + ElMessage.error(res.msg); + spinShow.value = false; + }); }