Files
dialect-chat/admin/templates/users.html
hubian 3aab712ff0 新增后台管理系统
功能模块:
- 仪表盘: 用户统计、对话统计、方言使用分布
- 用户管理: 查看、搜索、删除用户
- 对话管理: 查看、删除对话、消息内容预览
- 数据导出: 导出用户数据

技术栈:
- Flask + Tailwind CSS
- RESTful API
- 数据可视化
2026-04-08 12:16:21 +08:00

179 lines
8.7 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户管理 - 方言AI后台</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-translate-2 text-2xl text-purple-400"></i>
方言AI后台
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/users" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-user-line"></i><span>用户管理</span>
</a>
<a href="/chats" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-chat-3-line"></i><span>对话管理</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold text-gray-800">用户管理</h1>
<button onclick="exportUsers()" class="px-4 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 flex items-center gap-2">
<i class="ri-download-line"></i> 导出
</button>
</div>
<!-- 用户列表 -->
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-100">
<tr>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">用户名</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">手机号</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">邮箱</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">对话数</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">注册时间</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">操作</th>
</tr>
</thead>
<tbody id="userTable">
<tr><td colspan="6" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
</tbody>
</table>
</div>
<!-- 详情弹窗 -->
<div id="detailModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-white rounded-xl w-3/4 max-w-2xl max-h-[80vh] overflow-hidden flex flex-col">
<div class="p-6 border-b border-gray-100 flex justify-between items-center">
<h2 class="text-xl font-bold text-gray-800">用户详情</h2>
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600">
<i class="ri-close-line text-2xl"></i>
</button>
</div>
<div class="p-6 overflow-auto flex-1" id="modalContent"></div>
</div>
</div>
</main>
</div>
<script>
async function loadUsers() {
const response = await fetch('/api/users');
const users = await response.json();
const tbody = document.getElementById('userTable');
if (users.length === 0) {
tbody.innerHTML = '<tr><td colspan="6" class="px-6 py-8 text-center text-gray-500">暂无用户</td></tr>';
return;
}
tbody.innerHTML = users.map(u => `
<tr class="border-b border-gray-50 hover:bg-gray-50">
<td class="px-6 py-4 font-medium text-gray-800">${u.username}</td>
<td class="px-6 py-4 text-gray-600">${u.phone || '-'}</td>
<td class="px-6 py-4 text-gray-600">${u.email || '-'}</td>
<td class="px-6 py-4">
<span class="px-2 py-1 bg-purple-100 text-purple-700 rounded text-xs">${u.chats_count}</span>
</td>
<td class="px-6 py-4 text-sm text-gray-500">
${u.created_at ? new Date(u.created_at).toLocaleString() : '-'}
</td>
<td class="px-6 py-4">
<button onclick="viewDetail('${u.id}')" class="text-blue-500 hover:text-blue-700 mr-3">
<i class="ri-eye-line"></i> 查看
</button>
<button onclick="deleteUser('${u.id}')" class="text-red-500 hover:text-red-700">
<i class="ri-delete-bin-line"></i>
</button>
</td>
</tr>
`).join('');
}
async function viewDetail(userId) {
const response = await fetch(`/api/users/${userId}`);
const data = await response.json();
const content = document.getElementById('modalContent');
content.innerHTML = `
<div class="space-y-4">
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-sm text-gray-500">用户名</p>
<p class="font-medium">${data.user.username}</p>
</div>
<div>
<p class="text-sm text-gray-500">手机号</p>
<p class="font-medium">${data.user.phone || '-'}</p>
</div>
<div>
<p class="text-sm text-gray-500">邮箱</p>
<p class="font-medium">${data.user.email || '-'}</p>
</div>
<div>
<p class="text-sm text-gray-500">注册时间</p>
<p class="font-medium">${data.user.created_at ? new Date(data.user.created_at).toLocaleString() : '-'}</p>
</div>
</div>
<div class="pt-4 border-t">
<h3 class="font-medium text-gray-800 mb-3">对话列表 (${data.chats.length})</h3>
<div class="space-y-2 max-h-60 overflow-auto">
${data.chats.map(c => `
<div class="p-3 bg-gray-50 rounded-lg flex justify-between items-center">
<div>
<p class="font-medium text-gray-800">${c.title}</p>
<p class="text-xs text-gray-500">${c.dialect} · ${c.messages_count} 条消息</p>
</div>
</div>
`).join('') || '<p class="text-gray-500">暂无对话</p>'}
</div>
</div>
</div>
`;
document.getElementById('detailModal').classList.remove('hidden');
document.getElementById('detailModal').classList.add('flex');
}
function closeModal() {
document.getElementById('detailModal').classList.add('hidden');
document.getElementById('detailModal').classList.remove('flex');
}
async function deleteUser(userId) {
if (!confirm('确定要删除这个用户吗?这将同时删除该用户的所有对话!')) return;
const response = await fetch(`/api/users/${userId}`, { method: 'DELETE' });
const data = await response.json();
if (data.success) {
loadUsers();
} else {
alert('删除失败');
}
}
async function exportUsers() {
window.location.href = '/api/export/users';
}
loadUsers();
</script>
</body>
</html>