Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
252 lines
10 KiB
HTML
252 lines
10 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>测试新的导出功能</title>
|
||
<script src="https://unpkg.com/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
|
||
<style>
|
||
body {
|
||
font-family: Arial, sans-serif;
|
||
padding: 20px;
|
||
max-width: 1000px;
|
||
margin: 0 auto;
|
||
}
|
||
h1 {
|
||
color: #333;
|
||
}
|
||
.section {
|
||
margin: 20px 0;
|
||
padding: 20px;
|
||
border: 1px solid #ddd;
|
||
border-radius: 8px;
|
||
background: #f9f9f9;
|
||
}
|
||
button {
|
||
padding: 10px 20px;
|
||
margin: 5px;
|
||
background: #007bff;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
}
|
||
button:hover {
|
||
background: #0056b3;
|
||
}
|
||
.success {
|
||
color: green;
|
||
margin: 10px 0;
|
||
}
|
||
.error {
|
||
color: red;
|
||
margin: 10px 0;
|
||
}
|
||
.log {
|
||
background: #f0f0f0;
|
||
padding: 10px;
|
||
margin: 10px 0;
|
||
border-radius: 4px;
|
||
font-family: monospace;
|
||
white-space: pre-wrap;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<h1>TG账号导出功能测试</h1>
|
||
|
||
<div class="section">
|
||
<h2>1. 直接测试导出功能</h2>
|
||
<button onclick="testDirectExport()">测试Excel导出</button>
|
||
<button onclick="testDirectCSV()">测试CSV导出</button>
|
||
<button onclick="testAPIAndExport()">获取数据并导出</button>
|
||
<div id="result1"></div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<h2>2. 模拟实际使用场景</h2>
|
||
<button onclick="simulateExportAll()">模拟导出全部</button>
|
||
<button onclick="simulateExportNotBanned()">模拟导出未封号</button>
|
||
<button onclick="simulateExportCurrentPage()">模拟导出当前页</button>
|
||
<div id="result2"></div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<h2>3. 测试日志</h2>
|
||
<div id="log" class="log"></div>
|
||
</div>
|
||
|
||
<script>
|
||
// 日志函数
|
||
function log(message, type = 'info') {
|
||
const logDiv = document.getElementById('log');
|
||
const time = new Date().toLocaleTimeString();
|
||
const color = type === 'error' ? 'red' : type === 'success' ? 'green' : 'black';
|
||
logDiv.innerHTML += `<span style="color: ${color}">[${time}] ${message}</span>\n`;
|
||
console.log(`[${time}] ${message}`);
|
||
}
|
||
|
||
// 导出到Excel
|
||
function exportToExcel(data, filename) {
|
||
try {
|
||
log(`开始导出Excel,数据量: ${data.length}`);
|
||
|
||
const exportData = data.map(item => ({
|
||
'手机号': item.phone || '',
|
||
'密码': item.password || '',
|
||
'姓': item.firstname || '',
|
||
'名': item.lastname || '',
|
||
'用途ID': item.usageId || '',
|
||
'Session': item.session ? item.session.substring(0, 50) + '...' : ''
|
||
}));
|
||
|
||
const ws = XLSX.utils.json_to_sheet(exportData);
|
||
const wb = XLSX.utils.book_new();
|
||
XLSX.utils.book_append_sheet(wb, ws, "账号列表");
|
||
|
||
XLSX.writeFile(wb, filename);
|
||
log(`Excel导出成功: ${filename}`, 'success');
|
||
return true;
|
||
} catch (error) {
|
||
log(`Excel导出失败: ${error.message}`, 'error');
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 导出到CSV
|
||
function exportToCSV(data, filename) {
|
||
try {
|
||
log(`开始导出CSV,数据量: ${data.length}`);
|
||
|
||
const headers = ['手机号', '密码', '姓', '名', '用途ID', 'Session'];
|
||
const rows = data.map(item => [
|
||
item.phone || '',
|
||
item.password || '',
|
||
item.firstname || '',
|
||
item.lastname || '',
|
||
item.usageId || '',
|
||
item.session ? item.session.substring(0, 50) + '...' : ''
|
||
]);
|
||
|
||
const csvContent = [
|
||
headers.join(','),
|
||
...rows.map(row => row.map(cell => {
|
||
const cellStr = String(cell);
|
||
if (cellStr.includes(',') || cellStr.includes('"')) {
|
||
return '"' + cellStr.replace(/"/g, '""') + '"';
|
||
}
|
||
return cellStr;
|
||
}).join(','))
|
||
].join('\n');
|
||
|
||
const blob = new Blob(['\ufeff' + csvContent], { type: 'text/csv;charset=utf-8;' });
|
||
const link = document.createElement('a');
|
||
link.href = URL.createObjectURL(blob);
|
||
link.download = filename;
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
document.body.removeChild(link);
|
||
|
||
log(`CSV导出成功: ${filename}`, 'success');
|
||
return true;
|
||
} catch (error) {
|
||
log(`CSV导出失败: ${error.message}`, 'error');
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 测试数据
|
||
const testData = [
|
||
{ phone: '12345678901', password: 'test123', firstname: '张', lastname: '三', usageId: '1', session: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' },
|
||
{ phone: '12345678902', password: 'test456', firstname: '李', lastname: '四', usageId: '2', session: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' },
|
||
{ phone: '12345678903', password: 'test789', firstname: '王', lastname: '五', usageId: '1', session: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' }
|
||
];
|
||
|
||
// 测试直接导出Excel
|
||
function testDirectExport() {
|
||
log('=== 测试直接Excel导出 ===');
|
||
const success = exportToExcel(testData, 'test-excel.xlsx');
|
||
document.getElementById('result1').innerHTML = success ?
|
||
'<div class="success">✅ Excel导出成功!请检查下载的文件。</div>' :
|
||
'<div class="error">❌ Excel导出失败!请查看控制台错误。</div>';
|
||
}
|
||
|
||
// 测试直接导出CSV
|
||
function testDirectCSV() {
|
||
log('=== 测试直接CSV导出 ===');
|
||
const success = exportToCSV(testData, 'test-csv.csv');
|
||
document.getElementById('result1').innerHTML = success ?
|
||
'<div class="success">✅ CSV导出成功!请检查下载的文件。</div>' :
|
||
'<div class="error">❌ CSV导出失败!请查看控制台错误。</div>';
|
||
}
|
||
|
||
// 测试API并导出
|
||
async function testAPIAndExport() {
|
||
log('=== 测试API获取数据并导出 ===');
|
||
try {
|
||
const response = await fetch('http://localhost:3000/tgAccount/test-all', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/x-www-form-urlencoded'
|
||
}
|
||
});
|
||
const data = await response.json();
|
||
|
||
if (data.success && data.data) {
|
||
log(`API获取成功,数据量: ${data.data.length}`, 'success');
|
||
const exportData = data.data.slice(0, 10); // 只导出前10条
|
||
const success = exportToExcel(exportData, 'api-data.xlsx');
|
||
document.getElementById('result1').innerHTML = success ?
|
||
'<div class="success">✅ API数据导出成功!</div>' :
|
||
'<div class="error">❌ API数据导出失败!</div>';
|
||
} else {
|
||
throw new Error('API返回失败');
|
||
}
|
||
} catch (error) {
|
||
log(`API测试失败: ${error.message}`, 'error');
|
||
document.getElementById('result1').innerHTML =
|
||
'<div class="error">❌ API测试失败!' + error.message + '</div>';
|
||
}
|
||
}
|
||
|
||
// 模拟导出全部
|
||
function simulateExportAll() {
|
||
log('=== 模拟导出全部账号 ===');
|
||
const date = new Date();
|
||
const filename = `TG账号_全部_${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`;
|
||
const success = exportToExcel(testData, filename);
|
||
document.getElementById('result2').innerHTML = success ?
|
||
'<div class="success">✅ 导出全部成功!</div>' :
|
||
'<div class="error">❌ 导出全部失败!</div>';
|
||
}
|
||
|
||
// 模拟导出未封号
|
||
function simulateExportNotBanned() {
|
||
log('=== 模拟导出未封号账号 ===');
|
||
const notBannedData = testData.filter((_, index) => index < 2); // 模拟前两条为未封号
|
||
const date = new Date();
|
||
const filename = `TG账号_未封号_${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`;
|
||
const success = exportToExcel(notBannedData, filename);
|
||
document.getElementById('result2').innerHTML = success ?
|
||
'<div class="success">✅ 导出未封号成功!</div>' :
|
||
'<div class="error">❌ 导出未封号失败!</div>';
|
||
}
|
||
|
||
// 模拟导出当前页
|
||
function simulateExportCurrentPage() {
|
||
log('=== 模拟导出当前页 ===');
|
||
const currentPageData = testData.slice(0, 2); // 模拟当前页只有2条
|
||
const date = new Date();
|
||
const filename = `TG账号_当前页_${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`;
|
||
const success = exportToExcel(currentPageData, filename);
|
||
document.getElementById('result2').innerHTML = success ?
|
||
'<div class="success">✅ 导出当前页成功!</div>' :
|
||
'<div class="error">❌ 导出当前页失败!</div>';
|
||
}
|
||
|
||
// 页面加载完成后的初始化
|
||
window.onload = function() {
|
||
log('页面加载完成,XLSX库状态: ' + (typeof XLSX !== 'undefined' ? '已加载' : '未加载'));
|
||
};
|
||
</script>
|
||
</body>
|
||
</html> |