| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>客户报备管理系统</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- min-height: 100vh;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .container {
- width: 90%;
- max-width: 1200px;
- background: white;
- border-radius: 20px;
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
- padding: 40px;
- }
- .header {
- text-align: center;
- margin-bottom: 40px;
- }
- .header h1 {
- color: #333;
- font-size: 32px;
- margin-bottom: 10px;
- }
- .header p {
- color: #666;
- font-size: 16px;
- }
- .login-form {
- max-width: 400px;
- margin: 0 auto;
- display: none;
- }
- .login-form.active {
- display: block;
- }
- .form-group {
- margin-bottom: 20px;
- }
- .form-group label {
- display: block;
- margin-bottom: 8px;
- color: #333;
- font-weight: 500;
- }
- .form-group input {
- width: 100%;
- padding: 12px 15px;
- border: 2px solid #e0e0e0;
- border-radius: 8px;
- font-size: 14px;
- transition: border-color 0.3s;
- }
- .form-group input:focus {
- outline: none;
- border-color: #667eea;
- }
- .btn {
- width: 100%;
- padding: 14px;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- border: none;
- border-radius: 8px;
- font-size: 16px;
- font-weight: 500;
- cursor: pointer;
- transition: transform 0.2s, box-shadow 0.2s;
- }
- .btn:hover {
- transform: translateY(-2px);
- box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
- }
- .btn:active {
- transform: translateY(0);
- }
- .dashboard {
- display: none;
- }
- .dashboard.active {
- display: block;
- }
- .user-info {
- background: #f5f5f5;
- padding: 20px;
- border-radius: 10px;
- margin-bottom: 30px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .user-info h3 {
- color: #333;
- font-size: 18px;
- }
- .user-info .role {
- display: inline-block;
- padding: 4px 12px;
- background: #667eea;
- color: white;
- border-radius: 20px;
- font-size: 12px;
- margin-left: 10px;
- }
- .btn-logout {
- padding: 8px 20px;
- background: #ff4757;
- color: white;
- border: none;
- border-radius: 6px;
- cursor: pointer;
- font-size: 14px;
- }
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
- gap: 20px;
- margin-bottom: 30px;
- }
- .stat-card {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- padding: 25px;
- border-radius: 10px;
- box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
- }
- .stat-card h4 {
- font-size: 14px;
- margin-bottom: 10px;
- opacity: 0.9;
- }
- .stat-card .value {
- font-size: 32px;
- font-weight: bold;
- }
- .api-docs {
- background: #f9f9f9;
- padding: 30px;
- border-radius: 10px;
- margin-top: 30px;
- }
- .api-docs h3 {
- color: #333;
- margin-bottom: 20px;
- }
- .api-item {
- background: white;
- padding: 15px;
- margin-bottom: 10px;
- border-radius: 8px;
- border-left: 4px solid #667eea;
- }
- .api-item .method {
- display: inline-block;
- padding: 4px 10px;
- background: #667eea;
- color: white;
- border-radius: 4px;
- font-size: 12px;
- font-weight: bold;
- margin-right: 10px;
- }
- .api-item .method.post {
- background: #28a745;
- }
- .api-item .method.put {
- background: #ffc107;
- }
- .api-item .method.delete {
- background: #dc3545;
- }
- .alert {
- padding: 12px 20px;
- border-radius: 8px;
- margin-bottom: 20px;
- display: none;
- }
- .alert.success {
- background: #d4edda;
- color: #155724;
- border: 1px solid #c3e6cb;
- }
- .alert.error {
- background: #f8d7da;
- color: #721c24;
- border: 1px solid #f5c6cb;
- }
- .alert.active {
- display: block;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="header">
- <h1>🎯 客户报备管理系统</h1>
- <p>Customer Registration CRM System</p>
- </div>
- <div id="alert" class="alert"></div>
- <!-- 登录表单 -->
- <div id="loginForm" class="login-form active">
- <form onsubmit="handleLogin(event)">
- <div class="form-group">
- <label for="username">用户名</label>
- <input type="text" id="username" name="username" value="admin" required>
- </div>
- <div class="form-group">
- <label for="password">密码</label>
- <input type="password" id="password" name="password" value="admin123" required>
- </div>
- <button type="submit" class="btn">登录</button>
- </form>
- <div style="margin-top: 20px; text-align: center; color: #666; font-size: 14px;">
- <p>默认账号: admin / admin123</p>
- </div>
- </div>
- <!-- 仪表盘 -->
- <div id="dashboard" class="dashboard">
- <div class="user-info">
- <div>
- <h3>欢迎回来,<span id="userName"></span> <span id="userRole" class="role"></span></h3>
- </div>
- <button class="btn-logout" onclick="handleLogout()">退出登录</button>
- </div>
- <div class="stats-grid" id="statsGrid">
- <div class="stat-card">
- <h4>我的报备</h4>
- <div class="value" id="totalCustomers">-</div>
- </div>
- <div class="stat-card">
- <h4>跟进中</h4>
- <div class="value" id="followingCustomers">-</div>
- </div>
- <div class="stat-card">
- <h4>已成交</h4>
- <div class="value" id="wonCustomers">-</div>
- </div>
- <div class="stat-card">
- <h4>转化率</h4>
- <div class="value" id="conversionRate">-</div>
- </div>
- </div>
- <div class="api-docs">
- <h3>📚 API 接口文档</h3>
-
- <h4 style="margin: 20px 0 10px; color: #555;">认证接口</h4>
- <div class="api-item">
- <span class="method post">POST</span>
- <code>/api/auth/login</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">用户登录</p>
- </div>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/auth/me</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">获取当前用户信息</p>
- </div>
- <h4 style="margin: 20px 0 10px; color: #555;">客户管理</h4>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/customers/check-duplicate?customer_name=xxx</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">客户查重</p>
- </div>
- <div class="api-item">
- <span class="method post">POST</span>
- <code>/api/customers</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">创建客户报备</p>
- </div>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/customers</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">获取客户列表</p>
- </div>
- <h4 style="margin: 20px 0 10px; color: #555;">公海池管理</h4>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/pool/customers</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">获取公海池客户</p>
- </div>
- <div class="api-item">
- <span class="method post">POST</span>
- <code>/api/pool/claim</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">领取公海池客户</p>
- </div>
- <h4 style="margin: 20px 0 10px; color: #555;">统计报表</h4>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/stats/dashboard</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">个人仪表盘</p>
- </div>
- <div class="api-item">
- <span class="method">GET</span>
- <code>/api/stats/team</code>
- <p style="margin-top: 8px; color: #666; font-size: 14px;">团队统计</p>
- </div>
- </div>
- </div>
- </div>
- <script>
- const API_BASE = '/api';
- let token = localStorage.getItem('token');
- // 页面加载时检查登录状态
- if (token) {
- checkAuth();
- }
- function showAlert(message, type = 'success') {
- const alert = document.getElementById('alert');
- alert.textContent = message;
- alert.className = `alert ${type} active`;
- setTimeout(() => {
- alert.className = 'alert';
- }, 3000);
- }
- async function handleLogin(event) {
- event.preventDefault();
- const username = document.getElementById('username').value;
- const password = document.getElementById('password').value;
- try {
- const response = await fetch(`${API_BASE}/auth/login`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ username, password })
- });
- const data = await response.json();
- if (data.success) {
- token = data.data.token;
- localStorage.setItem('token', token);
- showAlert('登录成功!', 'success');
- showDashboard(data.data.user);
- loadDashboardData();
- } else {
- showAlert(data.message || '登录失败', 'error');
- }
- } catch (error) {
- showAlert('网络错误,请稍后重试', 'error');
- console.error(error);
- }
- }
- async function checkAuth() {
- try {
- const response = await fetch(`${API_BASE}/auth/me`, {
- headers: { 'Authorization': `Bearer ${token}` }
- });
- const data = await response.json();
- if (data.success) {
- showDashboard(data.data);
- loadDashboardData();
- } else {
- handleLogout();
- }
- } catch (error) {
- console.error(error);
- handleLogout();
- }
- }
- function showDashboard(user) {
- document.getElementById('loginForm').classList.remove('active');
- document.getElementById('dashboard').classList.add('active');
- document.getElementById('userName').textContent = user.real_name;
- document.getElementById('userRole').textContent = getRoleName(user.role);
- }
- async function loadDashboardData() {
- try {
- const response = await fetch(`${API_BASE}/stats/dashboard`, {
- headers: { 'Authorization': `Bearer ${token}` }
- });
- const data = await response.json();
- if (data.success) {
- const summary = data.data.summary;
- document.getElementById('totalCustomers').textContent = summary.total;
- document.getElementById('followingCustomers').textContent = summary.following;
- document.getElementById('wonCustomers').textContent = summary.won;
- document.getElementById('conversionRate').textContent = summary.conversion_rate;
- }
- } catch (error) {
- console.error('加载仪表盘数据失败:', error);
- }
- }
- function handleLogout() {
- localStorage.removeItem('token');
- token = null;
- document.getElementById('loginForm').classList.add('active');
- document.getElementById('dashboard').classList.remove('active');
- showAlert('已退出登录', 'success');
- }
- function getRoleName(role) {
- const roles = {
- 'sales': '销售',
- 'sales_manager': '销售经理',
- 'sales_director': '销售总监',
- 'admin': '管理员'
- };
- return roles[role] || role;
- }
- </script>
- </body>
- </html>
|