Browse Source

用户类登录统计-登录数据的导出PDF接口;

zhaowenkang/feature-20260206140254-后台AI复盘二期
songjie 4 weeks ago
parent
commit
1845e78357
  1. 24
      src/api/platformData.js
  2. 46
      src/views/PlatformData/UserLoginStats.vue

24
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) { export function getRegionActiveData(params) {
const formData = new FormData(); const formData = new FormData();

46
src/views/PlatformData/UserLoginStats.vue

@ -43,7 +43,7 @@
/> />
<el-button type="primary" class="search-btn" @click="handleSearch">搜索</el-button> <el-button type="primary" class="search-btn" @click="handleSearch">搜索</el-button>
<el-button type="primary" class="reset-btn" @click="handleReset">重置</el-button> <el-button type="primary" class="reset-btn" @click="handleReset">重置</el-button>
<el-button type="danger" class="export-btn">数据导出</el-button>
<el-button type="danger" class="export-btn" @click="handleExportLogin">数据导出</el-button>
</div> </div>
<!-- 统计卡片 --> <!-- 统计卡片 -->
@ -238,7 +238,7 @@
import { ref, onMounted, nextTick, watch } from 'vue'; import { ref, onMounted, nextTick, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import * as echarts from 'echarts'; 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'; import { ElMessage } from 'element-plus';
const route = useRoute(); 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 = () => { const handleSearch = () => {
// URL // URL
const query = { ...route.query }; const query = { ...route.query };

Loading…
Cancel
Save