功能模块: - 仪表盘: 用户统计、对话统计、方言使用分布 - 用户管理: 查看、搜索、删除用户 - 对话管理: 查看、删除对话、消息内容预览 - 数据导出: 导出用户数据 技术栈: - Flask + Tailwind CSS - RESTful API - 数据可视化
184 lines
8.7 KiB
HTML
184 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 text-slate-300 hover:bg-slate-700 hover:text-white">
|
|
<i class="ri-user-line"></i><span>用户管理</span>
|
|
</a>
|
|
<a href="/chats" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
|
|
<i class="ri-chat-3-line"></i><span>对话管理</span>
|
|
</a>
|
|
</nav>
|
|
</aside>
|
|
|
|
<main class="ml-64 flex-1 p-8">
|
|
<h1 class="text-2xl font-bold text-gray-800 mb-6">对话管理</h1>
|
|
|
|
<!-- 对话列表 -->
|
|
<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="chatTable">
|
|
<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-3xl 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" id="modalTitle">对话详情</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>
|
|
const DIALECT_NAMES = {
|
|
'mandarin': '普通话',
|
|
'sichuan': '四川话',
|
|
'cantonese': '粤语',
|
|
'shanghai': '上海话',
|
|
'hakka': '客家话',
|
|
'minnan': '闽南话',
|
|
'northeast': '东北话',
|
|
'henan': '河南话'
|
|
};
|
|
|
|
async function loadChats() {
|
|
const response = await fetch('/api/chats');
|
|
const chats = await response.json();
|
|
|
|
const tbody = document.getElementById('chatTable');
|
|
|
|
if (chats.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="6" class="px-6 py-8 text-center text-gray-500">暂无对话</td></tr>';
|
|
return;
|
|
}
|
|
|
|
tbody.innerHTML = chats.map(c => `
|
|
<tr class="border-b border-gray-50 hover:bg-gray-50">
|
|
<td class="px-6 py-4 font-medium text-gray-800">${c.title}</td>
|
|
<td class="px-6 py-4 text-gray-600">${c.user_name}</td>
|
|
<td class="px-6 py-4">
|
|
<span class="px-2 py-1 bg-purple-100 text-purple-700 rounded text-xs">
|
|
${DIALECT_NAMES[c.dialect] || c.dialect}
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4 text-gray-600">${c.messages_count}</td>
|
|
<td class="px-6 py-4 text-sm text-gray-500">
|
|
${c.updated_at ? new Date(c.updated_at).toLocaleString() : '-'}
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<button onclick="viewDetail('${c.id}')" class="text-blue-500 hover:text-blue-700 mr-3">
|
|
<i class="ri-eye-line"></i> 查看
|
|
</button>
|
|
<button onclick="deleteChat('${c.id}')" class="text-red-500 hover:text-red-700">
|
|
<i class="ri-delete-bin-line"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
|
|
async function viewDetail(chatId) {
|
|
const response = await fetch(`/api/chats/${chatId}`);
|
|
const data = await response.json();
|
|
|
|
document.getElementById('modalTitle').textContent = data.title;
|
|
|
|
const content = document.getElementById('modalContent');
|
|
content.innerHTML = `
|
|
<div class="space-y-4">
|
|
<div class="grid grid-cols-3 gap-4 p-4 bg-gray-50 rounded-lg">
|
|
<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">${DIALECT_NAMES[data.dialect] || data.dialect}</p>
|
|
</div>
|
|
<div>
|
|
<p class="text-sm text-gray-500">消息数</p>
|
|
<p class="font-medium">${data.messages.length}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="border-t pt-4">
|
|
<h3 class="font-medium text-gray-800 mb-3">对话内容</h3>
|
|
<div class="space-y-3 max-h-96 overflow-auto">
|
|
${data.messages.map(m => `
|
|
<div class="flex ${m.role === 'user' ? 'justify-end' : 'justify-start'}">
|
|
<div class="max-w-[80%] p-3 rounded-lg ${m.role === 'user' ? 'bg-purple-500 text-white' : 'bg-gray-100 text-gray-800'}">
|
|
<p class="text-sm whitespace-pre-wrap">${m.content}</p>
|
|
<p class="text-xs ${m.role === 'user' ? 'text-purple-200' : 'text-gray-400'} mt-1">
|
|
${m.time ? new Date(m.time).toLocaleString() : ''}
|
|
</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 deleteChat(chatId) {
|
|
if (!confirm('确定要删除这个对话吗?')) return;
|
|
|
|
const response = await fetch(`/api/chats/${chatId}`, { method: 'DELETE' });
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
loadChats();
|
|
} else {
|
|
alert('删除失败');
|
|
}
|
|
}
|
|
|
|
loadChats();
|
|
</script>
|
|
</body>
|
|
</html> |