Initial commit: Telegram Management System
Some checks failed
Deploy / deploy (push) Has been cancelled
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>
This commit is contained in:
132
temp-api-server.js
Normal file
132
temp-api-server.js
Normal file
@@ -0,0 +1,132 @@
|
||||
|
||||
// 临时修复方案:为前端创建模拟数据接口
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// 数据库连接配置
|
||||
const dbConfig = {
|
||||
host: '127.0.0.1',
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'tg_manage'
|
||||
};
|
||||
|
||||
// TG账号列表接口
|
||||
app.post('/api/tgAccount/list', async (req, res) => {
|
||||
try {
|
||||
const connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
const page = req.body.page || 1;
|
||||
const size = req.body.size || 10;
|
||||
const offset = (page - 1) * size;
|
||||
|
||||
// 查询总数
|
||||
const [countResult] = await connection.execute(
|
||||
'SELECT COUNT(*) as total FROM accounts'
|
||||
);
|
||||
const total = countResult[0].total;
|
||||
|
||||
// 查询数据 - 根据实际表结构修正字段
|
||||
const [rows] = await connection.execute(
|
||||
`SELECT
|
||||
id, phone, firstname, lastname, status, usageId,
|
||||
createdAt, updatedAt, lastOnline, isBan
|
||||
FROM accounts
|
||||
ORDER BY id DESC
|
||||
LIMIT ?, ?`,
|
||||
[offset, size]
|
||||
);
|
||||
|
||||
// 统计数据
|
||||
const [stats] = await connection.execute(
|
||||
`SELECT
|
||||
COUNT(*) as total,
|
||||
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as active,
|
||||
SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) as inactive,
|
||||
SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as banned
|
||||
FROM accounts`
|
||||
);
|
||||
|
||||
await connection.end();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
code: 200,
|
||||
data: {
|
||||
list: rows,
|
||||
total: total,
|
||||
page: page,
|
||||
size: size,
|
||||
totalPages: Math.ceil(total / size),
|
||||
stats: stats[0]
|
||||
},
|
||||
msg: '查询成功'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('API错误:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
code: 500,
|
||||
data: null,
|
||||
msg: '服务器错误: ' + error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 账号用途列表接口
|
||||
app.post('/api/tgAccount/usageList', async (req, res) => {
|
||||
try {
|
||||
const connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
const [rows] = await connection.execute(
|
||||
`SELECT usageId, COUNT(*) as count,
|
||||
CASE usageId
|
||||
WHEN 1 THEN '营销推广'
|
||||
WHEN 2 THEN '客服咨询'
|
||||
WHEN 3 THEN '群组管理'
|
||||
WHEN 4 THEN '自动回复'
|
||||
WHEN 5 THEN '数据采集'
|
||||
ELSE '未分类'
|
||||
END as usageName
|
||||
FROM accounts
|
||||
GROUP BY usageId
|
||||
ORDER BY count DESC`
|
||||
);
|
||||
|
||||
await connection.end();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
code: 200,
|
||||
data: {
|
||||
list: rows,
|
||||
total: rows.length
|
||||
},
|
||||
msg: '查询成功'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('API错误:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
code: 500,
|
||||
data: null,
|
||||
msg: '服务器错误: ' + error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 启动服务
|
||||
const PORT = 3002;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 临时API服务启动成功,端口: ${PORT}`);
|
||||
console.log(`📡 TG账号列表: POST http://localhost:${PORT}/api/tgAccount/list`);
|
||||
console.log(`📊 账号用途统计: POST http://localhost:${PORT}/api/tgAccount/usageList`);
|
||||
});
|
||||
Reference in New Issue
Block a user