fix:处理交易统计页面打开的时候生成 execl 文件,改成点击导出的时候再生成

This commit is contained in:
吴昊天 2026-09-28 17:22:04 +08:00
parent 39c657b4b6
commit 534de6d2c0
3 changed files with 25 additions and 7 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
});
}
</script>