index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>客户报备管理系统</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. display: flex;
  18. align-items: center;
  19. justify-content: center;
  20. }
  21. .container {
  22. width: 90%;
  23. max-width: 1200px;
  24. background: white;
  25. border-radius: 20px;
  26. box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  27. padding: 40px;
  28. }
  29. .header {
  30. text-align: center;
  31. margin-bottom: 40px;
  32. }
  33. .header h1 {
  34. color: #333;
  35. font-size: 32px;
  36. margin-bottom: 10px;
  37. }
  38. .header p {
  39. color: #666;
  40. font-size: 16px;
  41. }
  42. .login-form {
  43. max-width: 400px;
  44. margin: 0 auto;
  45. display: none;
  46. }
  47. .login-form.active {
  48. display: block;
  49. }
  50. .form-group {
  51. margin-bottom: 20px;
  52. }
  53. .form-group label {
  54. display: block;
  55. margin-bottom: 8px;
  56. color: #333;
  57. font-weight: 500;
  58. }
  59. .form-group input {
  60. width: 100%;
  61. padding: 12px 15px;
  62. border: 2px solid #e0e0e0;
  63. border-radius: 8px;
  64. font-size: 14px;
  65. transition: border-color 0.3s;
  66. }
  67. .form-group input:focus {
  68. outline: none;
  69. border-color: #667eea;
  70. }
  71. .btn {
  72. width: 100%;
  73. padding: 14px;
  74. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  75. color: white;
  76. border: none;
  77. border-radius: 8px;
  78. font-size: 16px;
  79. font-weight: 500;
  80. cursor: pointer;
  81. transition: transform 0.2s, box-shadow 0.2s;
  82. }
  83. .btn:hover {
  84. transform: translateY(-2px);
  85. box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
  86. }
  87. .btn:active {
  88. transform: translateY(0);
  89. }
  90. .dashboard {
  91. display: none;
  92. }
  93. .dashboard.active {
  94. display: block;
  95. }
  96. .user-info {
  97. background: #f5f5f5;
  98. padding: 20px;
  99. border-radius: 10px;
  100. margin-bottom: 30px;
  101. display: flex;
  102. justify-content: space-between;
  103. align-items: center;
  104. }
  105. .user-info h3 {
  106. color: #333;
  107. font-size: 18px;
  108. }
  109. .user-info .role {
  110. display: inline-block;
  111. padding: 4px 12px;
  112. background: #667eea;
  113. color: white;
  114. border-radius: 20px;
  115. font-size: 12px;
  116. margin-left: 10px;
  117. }
  118. .btn-logout {
  119. padding: 8px 20px;
  120. background: #ff4757;
  121. color: white;
  122. border: none;
  123. border-radius: 6px;
  124. cursor: pointer;
  125. font-size: 14px;
  126. }
  127. .stats-grid {
  128. display: grid;
  129. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  130. gap: 20px;
  131. margin-bottom: 30px;
  132. }
  133. .stat-card {
  134. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  135. color: white;
  136. padding: 25px;
  137. border-radius: 10px;
  138. box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
  139. }
  140. .stat-card h4 {
  141. font-size: 14px;
  142. margin-bottom: 10px;
  143. opacity: 0.9;
  144. }
  145. .stat-card .value {
  146. font-size: 32px;
  147. font-weight: bold;
  148. }
  149. .api-docs {
  150. background: #f9f9f9;
  151. padding: 30px;
  152. border-radius: 10px;
  153. margin-top: 30px;
  154. }
  155. .api-docs h3 {
  156. color: #333;
  157. margin-bottom: 20px;
  158. }
  159. .api-item {
  160. background: white;
  161. padding: 15px;
  162. margin-bottom: 10px;
  163. border-radius: 8px;
  164. border-left: 4px solid #667eea;
  165. }
  166. .api-item .method {
  167. display: inline-block;
  168. padding: 4px 10px;
  169. background: #667eea;
  170. color: white;
  171. border-radius: 4px;
  172. font-size: 12px;
  173. font-weight: bold;
  174. margin-right: 10px;
  175. }
  176. .api-item .method.post {
  177. background: #28a745;
  178. }
  179. .api-item .method.put {
  180. background: #ffc107;
  181. }
  182. .api-item .method.delete {
  183. background: #dc3545;
  184. }
  185. .alert {
  186. padding: 12px 20px;
  187. border-radius: 8px;
  188. margin-bottom: 20px;
  189. display: none;
  190. }
  191. .alert.success {
  192. background: #d4edda;
  193. color: #155724;
  194. border: 1px solid #c3e6cb;
  195. }
  196. .alert.error {
  197. background: #f8d7da;
  198. color: #721c24;
  199. border: 1px solid #f5c6cb;
  200. }
  201. .alert.active {
  202. display: block;
  203. }
  204. </style>
  205. </head>
  206. <body>
  207. <div class="container">
  208. <div class="header">
  209. <h1>🎯 客户报备管理系统</h1>
  210. <p>Customer Registration CRM System</p>
  211. </div>
  212. <div id="alert" class="alert"></div>
  213. <!-- 登录表单 -->
  214. <div id="loginForm" class="login-form active">
  215. <form onsubmit="handleLogin(event)">
  216. <div class="form-group">
  217. <label for="username">用户名</label>
  218. <input type="text" id="username" name="username" value="admin" required>
  219. </div>
  220. <div class="form-group">
  221. <label for="password">密码</label>
  222. <input type="password" id="password" name="password" value="admin123" required>
  223. </div>
  224. <button type="submit" class="btn">登录</button>
  225. </form>
  226. <div style="margin-top: 20px; text-align: center; color: #666; font-size: 14px;">
  227. <p>默认账号: admin / admin123</p>
  228. </div>
  229. </div>
  230. <!-- 仪表盘 -->
  231. <div id="dashboard" class="dashboard">
  232. <div class="user-info">
  233. <div>
  234. <h3>欢迎回来,<span id="userName"></span> <span id="userRole" class="role"></span></h3>
  235. </div>
  236. <button class="btn-logout" onclick="handleLogout()">退出登录</button>
  237. </div>
  238. <div class="stats-grid" id="statsGrid">
  239. <div class="stat-card">
  240. <h4>我的报备</h4>
  241. <div class="value" id="totalCustomers">-</div>
  242. </div>
  243. <div class="stat-card">
  244. <h4>跟进中</h4>
  245. <div class="value" id="followingCustomers">-</div>
  246. </div>
  247. <div class="stat-card">
  248. <h4>已成交</h4>
  249. <div class="value" id="wonCustomers">-</div>
  250. </div>
  251. <div class="stat-card">
  252. <h4>转化率</h4>
  253. <div class="value" id="conversionRate">-</div>
  254. </div>
  255. </div>
  256. <div class="api-docs">
  257. <h3>📚 API 接口文档</h3>
  258. <h4 style="margin: 20px 0 10px; color: #555;">认证接口</h4>
  259. <div class="api-item">
  260. <span class="method post">POST</span>
  261. <code>/api/auth/login</code>
  262. <p style="margin-top: 8px; color: #666; font-size: 14px;">用户登录</p>
  263. </div>
  264. <div class="api-item">
  265. <span class="method">GET</span>
  266. <code>/api/auth/me</code>
  267. <p style="margin-top: 8px; color: #666; font-size: 14px;">获取当前用户信息</p>
  268. </div>
  269. <h4 style="margin: 20px 0 10px; color: #555;">客户管理</h4>
  270. <div class="api-item">
  271. <span class="method">GET</span>
  272. <code>/api/customers/check-duplicate?customer_name=xxx</code>
  273. <p style="margin-top: 8px; color: #666; font-size: 14px;">客户查重</p>
  274. </div>
  275. <div class="api-item">
  276. <span class="method post">POST</span>
  277. <code>/api/customers</code>
  278. <p style="margin-top: 8px; color: #666; font-size: 14px;">创建客户报备</p>
  279. </div>
  280. <div class="api-item">
  281. <span class="method">GET</span>
  282. <code>/api/customers</code>
  283. <p style="margin-top: 8px; color: #666; font-size: 14px;">获取客户列表</p>
  284. </div>
  285. <h4 style="margin: 20px 0 10px; color: #555;">公海池管理</h4>
  286. <div class="api-item">
  287. <span class="method">GET</span>
  288. <code>/api/pool/customers</code>
  289. <p style="margin-top: 8px; color: #666; font-size: 14px;">获取公海池客户</p>
  290. </div>
  291. <div class="api-item">
  292. <span class="method post">POST</span>
  293. <code>/api/pool/claim</code>
  294. <p style="margin-top: 8px; color: #666; font-size: 14px;">领取公海池客户</p>
  295. </div>
  296. <h4 style="margin: 20px 0 10px; color: #555;">统计报表</h4>
  297. <div class="api-item">
  298. <span class="method">GET</span>
  299. <code>/api/stats/dashboard</code>
  300. <p style="margin-top: 8px; color: #666; font-size: 14px;">个人仪表盘</p>
  301. </div>
  302. <div class="api-item">
  303. <span class="method">GET</span>
  304. <code>/api/stats/team</code>
  305. <p style="margin-top: 8px; color: #666; font-size: 14px;">团队统计</p>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <script>
  311. const API_BASE = '/api';
  312. let token = localStorage.getItem('token');
  313. // 页面加载时检查登录状态
  314. if (token) {
  315. checkAuth();
  316. }
  317. function showAlert(message, type = 'success') {
  318. const alert = document.getElementById('alert');
  319. alert.textContent = message;
  320. alert.className = `alert ${type} active`;
  321. setTimeout(() => {
  322. alert.className = 'alert';
  323. }, 3000);
  324. }
  325. async function handleLogin(event) {
  326. event.preventDefault();
  327. const username = document.getElementById('username').value;
  328. const password = document.getElementById('password').value;
  329. try {
  330. const response = await fetch(`${API_BASE}/auth/login`, {
  331. method: 'POST',
  332. headers: { 'Content-Type': 'application/json' },
  333. body: JSON.stringify({ username, password })
  334. });
  335. const data = await response.json();
  336. if (data.success) {
  337. token = data.data.token;
  338. localStorage.setItem('token', token);
  339. showAlert('登录成功!', 'success');
  340. showDashboard(data.data.user);
  341. loadDashboardData();
  342. } else {
  343. showAlert(data.message || '登录失败', 'error');
  344. }
  345. } catch (error) {
  346. showAlert('网络错误,请稍后重试', 'error');
  347. console.error(error);
  348. }
  349. }
  350. async function checkAuth() {
  351. try {
  352. const response = await fetch(`${API_BASE}/auth/me`, {
  353. headers: { 'Authorization': `Bearer ${token}` }
  354. });
  355. const data = await response.json();
  356. if (data.success) {
  357. showDashboard(data.data);
  358. loadDashboardData();
  359. } else {
  360. handleLogout();
  361. }
  362. } catch (error) {
  363. console.error(error);
  364. handleLogout();
  365. }
  366. }
  367. function showDashboard(user) {
  368. document.getElementById('loginForm').classList.remove('active');
  369. document.getElementById('dashboard').classList.add('active');
  370. document.getElementById('userName').textContent = user.real_name;
  371. document.getElementById('userRole').textContent = getRoleName(user.role);
  372. }
  373. async function loadDashboardData() {
  374. try {
  375. const response = await fetch(`${API_BASE}/stats/dashboard`, {
  376. headers: { 'Authorization': `Bearer ${token}` }
  377. });
  378. const data = await response.json();
  379. if (data.success) {
  380. const summary = data.data.summary;
  381. document.getElementById('totalCustomers').textContent = summary.total;
  382. document.getElementById('followingCustomers').textContent = summary.following;
  383. document.getElementById('wonCustomers').textContent = summary.won;
  384. document.getElementById('conversionRate').textContent = summary.conversion_rate;
  385. }
  386. } catch (error) {
  387. console.error('加载仪表盘数据失败:', error);
  388. }
  389. }
  390. function handleLogout() {
  391. localStorage.removeItem('token');
  392. token = null;
  393. document.getElementById('loginForm').classList.add('active');
  394. document.getElementById('dashboard').classList.remove('active');
  395. showAlert('已退出登录', 'success');
  396. }
  397. function getRoleName(role) {
  398. const roles = {
  399. 'sales': '销售',
  400. 'sales_manager': '销售经理',
  401. 'sales_director': '销售总监',
  402. 'admin': '管理员'
  403. };
  404. return roles[role] || role;
  405. }
  406. </script>
  407. </body>
  408. </html>