From 1845e783576c9c32f05fe885ccc73e1c2af054c9 Mon Sep 17 00:00:00 2001 From: songjie Date: Tue, 27 Jan 2026 13:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=B1=BB=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1-=E7=99=BB=E5=BD=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E5=AF=BC=E5=87=BAPDF=E6=8E=A5=E5=8F=A3=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/platformData.js | 24 ++++++++++++++++ src/views/PlatformData/UserLoginStats.vue | 46 +++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/api/platformData.js b/src/api/platformData.js index 9a354af..a9f8bc1 100644 --- a/src/api/platformData.js +++ b/src/api/platformData.js @@ -182,6 +182,30 @@ export function getUserLoginTrend(params) { }) } +// 导出用户登录数据 PDF +export function exportUserLoginPDF(params) { + const formData = new FormData(); + formData.append('token', localStorage.getItem('token')); + if (params) { + if (params.region) formData.append('region', params.region); + if (params.start_time) formData.append('start_time', params.start_time); + if (params.end_time) formData.append('end_time', params.end_time); + } + + return request({ + url: base_url + '/admin/user/login/export/pdf', + method: 'post', + headers: { + 'token': localStorage.getItem('token'), + 'client': 'ios', + 'version': '1', + 'Content-Type': 'multipart/form-data' + }, + data: formData, + responseType: 'blob' // Important for file download + }) +} + // 获取各地区登录活跃数据 export function getRegionActiveData(params) { const formData = new FormData(); diff --git a/src/views/PlatformData/UserLoginStats.vue b/src/views/PlatformData/UserLoginStats.vue index b67708c..ea15ef4 100644 --- a/src/views/PlatformData/UserLoginStats.vue +++ b/src/views/PlatformData/UserLoginStats.vue @@ -43,7 +43,7 @@ /> 搜索 重置 - 数据导出 + 数据导出 @@ -238,7 +238,7 @@ import { ref, onMounted, nextTick, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import * as echarts from 'echarts'; -import { getUserLoginList, getUserLoginTrend, getRegionActiveData, getRegionActiveDataHistogram, getUserLoginChannel, getUserLoginChannelMember, getUserLoginChannelNoMember, getRegionUserDistribution, exportRegionActiveData, getRegionsList } from '../../api/platformData'; +import { getUserLoginList, getUserLoginTrend, getRegionActiveData, getRegionActiveDataHistogram, getUserLoginChannel, getUserLoginChannelMember, getUserLoginChannelNoMember, getRegionUserDistribution, exportRegionActiveData, getRegionsList, exportUserLoginPDF } from '../../api/platformData'; import { ElMessage } from 'element-plus'; const route = useRoute(); @@ -559,6 +559,48 @@ const fetchAllLoginData = async () => { } }; +const handleExportLogin = async () => { + loading.value = true; + let params = {}; + if (dateRange.value && dateRange.value.length === 2) { + params.start_time = formatDate(dateRange.value[0]); + params.end_time = formatDate(dateRange.value[1]); + } + + if (selectedRegion.value && selectedRegion.value !== 'all') { + params.region = selectedRegion.value; + } + + try { + const res = await exportUserLoginPDF(params); + console.log("导出登录数据PDF响应(Blob):", res); + + // 创建Blob对象,处理二进制流下载 + const blob = new Blob([res], { type: 'application/pdf' }); + const url = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + + // 设置下载文件名,添加时间戳防止重名 + const fileName = `用户登录数据_${formatDate(new Date())}.pdf`; + link.setAttribute('download', fileName); + + document.body.appendChild(link); + link.click(); + + // 清理资源 + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + + ElMessage.success('导出成功'); + } catch (e) { + console.error('导出登录数据失败:', e); + ElMessage.error('导出请求发生错误'); + } finally { + loading.value = false; + } +}; + const handleSearch = () => { // 更新 URL 参数 const query = { ...route.query };