市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

671 lines
18 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
2 months ago
  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" />
  6. <title>管理后台</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. padding: 24px;
  11. background: #f7f8fb;
  12. color: #222;
  13. }
  14. .card {
  15. background: #fff;
  16. padding: 16px;
  17. border-radius: 8px;
  18. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  19. margin: auto;
  20. }
  21. table {
  22. width: 100%;
  23. border-collapse: collapse;
  24. margin-top: 12px;
  25. }
  26. th,
  27. td {
  28. padding: 10px 12px;
  29. border-bottom: 1px solid #eee;
  30. text-align: left;
  31. font-size: 14px;
  32. }
  33. th {
  34. background: #fafafa;
  35. font-weight: 600;
  36. }
  37. .controls {
  38. display: flex;
  39. gap: 12px;
  40. align-items: center;
  41. flex-wrap: wrap;
  42. }
  43. .pagination {
  44. display: flex;
  45. gap: 6px;
  46. align-items: center;
  47. margin-left: auto;
  48. flex-wrap: wrap;
  49. }
  50. .btn {
  51. padding: 6px 10px;
  52. border-radius: 6px;
  53. border: 1px solid #ddd;
  54. background: #fff;
  55. cursor: pointer;
  56. user-select: none;
  57. }
  58. .btn:disabled {
  59. opacity: 0.5;
  60. cursor: default;
  61. }
  62. .btn.primary {
  63. background: #007bff;
  64. color: #fff;
  65. border-color: #007bff;
  66. }
  67. .btn.whatsapp {
  68. background: #25D366;
  69. color: #fff;
  70. border-color: #25D366;
  71. }
  72. .status-btn {
  73. padding: 4px 8px;
  74. border-radius: 6px;
  75. border: 1px solid #ccc;
  76. cursor: pointer;
  77. }
  78. .status-0 {
  79. background: red;
  80. color: #fff;
  81. }
  82. .status-1 {
  83. background: #2f9e44;
  84. color: #fff;
  85. border-color: #2f9e44;
  86. }
  87. .btn.active {
  88. background: #007bff;
  89. color: #fff;
  90. border-color: #007bff;
  91. }
  92. select,
  93. input[type="number"] {
  94. padding: 6px;
  95. border-radius: 6px;
  96. border: 1px solid #ddd;
  97. }
  98. .small {
  99. font-size: 13px;
  100. color: #666;
  101. }
  102. @media (max-width: 640px) {
  103. .controls {
  104. flex-direction: column;
  105. align-items: flex-start;
  106. }
  107. .pagination {
  108. margin-left: 0;
  109. }
  110. }
  111. #noteModal {
  112. display: none;
  113. position: fixed;
  114. inset: 0;
  115. background: rgba(0, 0, 0, 0.45);
  116. align-items: center;
  117. justify-content: center;
  118. z-index: 9999;
  119. }
  120. #noteModal .dialog {
  121. background: #fff;
  122. padding: 16px;
  123. border-radius: 8px;
  124. width: 90%;
  125. max-width: 520px;
  126. box-sizing: border-box;
  127. }
  128. #noteModal textarea {
  129. width: 100%;
  130. min-width: 60%;
  131. max-width: 100%;
  132. min-height: 150px;
  133. box-sizing: border-box;
  134. padding: 8px;
  135. border-radius: 6px;
  136. border: 1px solid #ddd;
  137. font-size: 14px;
  138. }
  139. .toast {
  140. position: fixed;
  141. top: -20px;
  142. left: 50%;
  143. transform: translateX(-50%);
  144. background: #4caf50;
  145. color: #fff;
  146. padding: 10px 16px;
  147. border-radius: 6px;
  148. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  149. font-size: 16px;
  150. opacity: 0;
  151. transition: all 0.3s ease;
  152. z-index: 10000;
  153. pointer-events: none;
  154. }
  155. .toast.show {
  156. opacity: 1;
  157. top: 20px;
  158. }
  159. table th,
  160. table td {
  161. text-align: center;
  162. }
  163. /* 登录验证样式 */
  164. #loginCheckModal {
  165. display: none;
  166. position: fixed;
  167. inset: 0;
  168. background: rgba(0, 0, 0, 0.7);
  169. align-items: center;
  170. justify-content: center;
  171. z-index: 99999;
  172. }
  173. #loginCheckModal .dialog {
  174. background: #fff;
  175. padding: 30px;
  176. border-radius: 12px;
  177. width: 90%;
  178. max-width: 400px;
  179. text-align: center;
  180. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  181. }
  182. #loginCheckModal h3 {
  183. margin: 0 0 16px;
  184. color: #e74c3c;
  185. font-size: 20px;
  186. }
  187. #loginCheckModal p {
  188. margin: 0 0 24px;
  189. color: #666;
  190. line-height: 1.5;
  191. }
  192. #loginCheckModal .btn {
  193. padding: 10px 20px;
  194. font-size: 16px;
  195. }
  196. </style>
  197. </head>
  198. <body>
  199. <!-- 登录验证模态框 -->
  200. <div id="loginCheckModal">
  201. <div class="dialog">
  202. <h3>访问被拒绝</h3>
  203. <p>您尚未登录或登录已过期,请先登录系统。</p>
  204. <button class="btn primary" id="goToLoginBtn">前往登录页面</button>
  205. </div>
  206. </div>
  207. <div class="card">
  208. <table aria-describedby="tableDesc">
  209. <thead>
  210. <tr>
  211. <th style="width: 40px">#</th>
  212. <th style="width: 80px">姓名</th>
  213. <th style="width: 80px">WhatsApp</th>
  214. <th style="width: 90px">国家/地区代码</th>
  215. <th style="width: 120px">电话号码</th>
  216. <th style="width: 120px">微信ID</th>
  217. <th style="width: 120px">邮箱</th>
  218. <th style="width: 80px">获客来源</th>
  219. <th style="width: 150px">添加时间</th>
  220. <th style="width: 100px">是否联系</th>
  221. <th style="width: 150px">备注</th>
  222. <th style="width: 100px">操作</th>
  223. </tr>
  224. </thead>
  225. <tbody id="tableBody"></tbody>
  226. </table>
  227. <div class="controls" style="margin-bottom: 8px; margin-top: 12px">
  228. <div class="small">
  229. 每页显示
  230. <select id="pageSizeSelect">
  231. <option value="20" selected>20</option>
  232. <option value="50">50</option>
  233. <option value="100">100</option>
  234. <option value="200">200</option>
  235. </select>
  236. </div>
  237. <div class="small"><span id="totalCount">0</span></div>
  238. <div class="pagination" id="pagination"></div>
  239. </div>
  240. <!-- 备注编辑模态 -->
  241. <div id="noteModal">
  242. <div class="dialog">
  243. <h3 style="margin: 0 0 8px">编辑备注</h3>
  244. <textarea id="noteTextarea" rows="6" placeholder="输入备注..."></textarea>
  245. <div style="
  246. margin-top: 10px;
  247. display: flex;
  248. justify-content: flex-end;
  249. gap: 8px;
  250. ">
  251. <button class="btn" id="noteCancelBtn">取消</button>
  252. <button class="btn primary" id="noteSaveBtn">保存</button>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. <div id="toast" class="toast"></div>
  258. <script type="module">
  259. import { getMemberListApi, updateMemberStateApi, editMemberNoteApi } from './src/api/member.js'
  260. // 登录验证函数
  261. function checkLoginStatus() {
  262. const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
  263. const loginTime = parseInt(localStorage.getItem('loginTime'));
  264. const currentTime = new Date().getTime();
  265. const hoursDiff = (currentTime - loginTime) / (1000 * 60 * 60);
  266. // 检查是否登录且登录时间在24小时内
  267. if (!isLoggedIn || hoursDiff >= 24) {
  268. // 清除过期的登录状态
  269. localStorage.removeItem('isLoggedIn');
  270. localStorage.removeItem('loginTime');
  271. return false;
  272. }
  273. return true;
  274. }
  275. // 显示登录验证模态框
  276. function showLoginCheckModal() {
  277. const modal = document.getElementById('loginCheckModal');
  278. modal.style.display = 'flex';
  279. }
  280. // 隐藏登录验证模态框
  281. function hideLoginCheckModal() {
  282. const modal = document.getElementById('loginCheckModal');
  283. modal.style.display = 'none';
  284. }
  285. // 跳转到登录页面
  286. function redirectToLogin() {
  287. window.location.href = 'login-management.html';
  288. }
  289. // 检查登录状态
  290. if (!checkLoginStatus()) {
  291. showLoginCheckModal();
  292. }
  293. // 绑定前往登录页面按钮事件
  294. document.getElementById('goToLoginBtn').addEventListener('click', redirectToLogin);
  295. let state = {
  296. pageSize: 20,
  297. currentPage: 1,
  298. total: 0,
  299. items: []
  300. };
  301. // DOM
  302. const tableBody = document.getElementById("tableBody");
  303. const paginationEl = document.getElementById("pagination");
  304. const totalCountEl = document.getElementById("totalCount");
  305. const currentPageEl = document.getElementById("currentPage");
  306. const showingRangeEl = document.getElementById("showingRange");
  307. const pageSizeSelect = document.getElementById("pageSizeSelect");
  308. const gotoInput = document.getElementById("gotoInput");
  309. const noteModal = document.getElementById("noteModal");
  310. const noteTextarea = document.getElementById("noteTextarea");
  311. const noteCancelBtn = document.getElementById("noteCancelBtn");
  312. const noteSaveBtn = document.getElementById("noteSaveBtn");
  313. const toastEl = document.getElementById("toast");
  314. let editingRowId = null;
  315. function showToast(msg) {
  316. toastEl.textContent = msg;
  317. toastEl.classList.add("show");
  318. setTimeout(() => toastEl.classList.remove("show"), 1000);
  319. }
  320. async function fetchPage(page, pageSize) {
  321. // 每次请求数据前都检查登录状态
  322. if (!checkLoginStatus()) {
  323. showLoginCheckModal();
  324. return;
  325. }
  326. try {
  327. const res = await getMemberListApi({
  328. page: page,
  329. page_size: pageSize,
  330. })
  331. if (typeof res.code !== "undefined" && res.code !== 200) {
  332. throw new Error(res.msg || "接口返回错误");
  333. }
  334. console.log(res)
  335. const payload = res.data || {};
  336. state.items = payload.list;
  337. state.total = payload.total;
  338. } catch (err) {
  339. alert("获取数据失败");
  340. state.total = 0;
  341. }
  342. }
  343. // 渲染表格行
  344. function renderTable() {
  345. const startIndex = (state.currentPage - 1) * state.pageSize;
  346. const items = state.items || [];
  347. tableBody.innerHTML = items
  348. .map((item, idx) => {
  349. const serial = startIndex + idx + 1;
  350. const statusClass = item.isRelated ? "status-1" : "status-0";
  351. const statusText = item.isRelated ? "已联系" : "未联系";
  352. // 构建WhatsApp链接 - 移除国家代码中的+号
  353. const cleanCode = (item.code || '').replace(/\+/g, '');
  354. const whatsappPhone = cleanCode + (item.telephone || '');
  355. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  356. return `
  357. <tr>
  358. <td>${serial}</td>
  359. <td>${escapeHtml(item.name || "")}</td>
  360. <td>
  361. <button class="btn whatsapp" data-action="whatsapp" data-id="${item.id}">WhatsApp</button>
  362. </td>
  363. <td>${escapeHtml(item.code || "")}</td>
  364. <td>${escapeHtml(item.telephone || "")}</td>
  365. <td>${escapeHtml(item.wechat || "")}</td>
  366. <td>${escapeHtml(item.email || "")}</td>
  367. <td>${escapeHtml(item.type === 0 ? "其它" : item.type === 1 ? "视频" : item.type === 2 ? "直播" : item.type === 3 ? "帖子" : "其它")}</td>
  368. <td>${escapeHtml(item.createdAt || "")}</td>
  369. <td>
  370. <button class="status-btn ${statusClass}" data-action="toggle" data-id="${item.id
  371. }">${statusText}</button>
  372. </td>
  373. <td>${escapeHtml(item.note || "")}</td>
  374. <td>
  375. <button class="btn" data-action="editNote" data-id="${item.id
  376. }">编辑备注</button>
  377. </td>
  378. </tr>
  379. `;
  380. })
  381. .join("");
  382. totalCountEl.textContent = state.total;
  383. }
  384. tableBody.addEventListener("click", async (e) => {
  385. // 每次操作前检查登录状态
  386. if (!checkLoginStatus()) {
  387. showLoginCheckModal();
  388. return;
  389. }
  390. // WhatsApp跳转
  391. const whatsappBtn = e.target.closest('[data-action="whatsapp"]');
  392. if (whatsappBtn) {
  393. const id = whatsappBtn.getAttribute("data-id");
  394. handleWhatsApp(id);
  395. return;
  396. }
  397. // 切换状态
  398. const toggler = e.target.closest('[data-action="toggle"]');
  399. if (toggler) {
  400. const id = toggler.getAttribute("data-id");
  401. await handleToggle(id, toggler);
  402. return;
  403. }
  404. // 编辑备注
  405. const editBtn = e.target.closest('[data-action="editNote"]');
  406. if (editBtn) {
  407. const id = editBtn.getAttribute("data-id");
  408. openNoteModal(id);
  409. return;
  410. }
  411. });
  412. // ---------- WhatsApp跳转 ----------
  413. function handleWhatsApp(id) {
  414. const item = state.items.find((it) => String(it.id) === String(id));
  415. if (!item) return;
  416. // 移除国家代码中的+号
  417. const cleanCode = (item.code || '').replace(/\+/g, '');
  418. const whatsappPhone = cleanCode + (item.telephone || '');
  419. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  420. window.open(whatsappUrl, '_blank');
  421. }
  422. // ---------- 切换联系状态 ----------
  423. async function handleToggle(id, btnEl) {
  424. const item = state.items.find((it) => String(it.id) === String(id));
  425. if (!item) return;
  426. const prev = item.isRelated;
  427. const newVal = prev ? 0 : 1;
  428. item.isRelated = newVal;
  429. btnEl.textContent = newVal ? "已联系" : "未联系";
  430. btnEl.classList.toggle("status-1", !!newVal);
  431. btnEl.classList.toggle("status-0", !newVal);
  432. try {
  433. const res = await updateMemberStateApi({ id: item.id, state: newVal })
  434. if (typeof res.code !== "undefined" && res.code !== 200) {
  435. throw new Error(res.msg || "更新失败");
  436. }
  437. showToast("状态修改成功");
  438. } catch (err) {
  439. item.isRelated = prev;
  440. btnEl.textContent = prev ? "已联系" : "未联系";
  441. btnEl.classList.toggle("status-1", !!prev);
  442. btnEl.classList.toggle("status-0", !prev);
  443. alert("更新失败");
  444. }
  445. }
  446. // ---------- 备注模态相关 ----------
  447. function openNoteModal(id) {
  448. // 打开模态框前检查登录状态
  449. if (!checkLoginStatus()) {
  450. showLoginCheckModal();
  451. return;
  452. }
  453. const item = state.items.find((it) => String(it.id) === String(id));
  454. if (!item) return;
  455. editingRowId = id;
  456. noteTextarea.value = item.note || "";
  457. noteModal.style.display = "flex";
  458. noteTextarea.focus();
  459. }
  460. function closeNoteModal() {
  461. editingRowId = null;
  462. noteTextarea.value = "";
  463. noteModal.style.display = "none";
  464. }
  465. noteCancelBtn.addEventListener("click", closeNoteModal);
  466. noteSaveBtn.addEventListener("click", async () => {
  467. // 保存前检查登录状态
  468. if (!checkLoginStatus()) {
  469. showLoginCheckModal();
  470. return;
  471. }
  472. if (!editingRowId) return closeNoteModal();
  473. const newNote = noteTextarea.value.trim();
  474. const item = state.items.find((it) => String(it.id) === String(editingRowId));
  475. if (!item) return closeNoteModal();
  476. try {
  477. const res = await editMemberNoteApi({ id: item.id, note: newNote })
  478. if (typeof res.code !== "undefined" && res.code !== 200) {
  479. throw new Error(res.msg || "保存失败");
  480. }
  481. const prevNote = item.note;
  482. item.note = newNote;
  483. renderTable();
  484. showToast("备注保存成功");
  485. } catch (err) {
  486. alert("保存备注失败");
  487. } finally {
  488. closeNoteModal();
  489. }
  490. });
  491. // 渲染分页控件(页码、上一页、下一页)
  492. function renderPagination() {
  493. const totalPages = Math.max(1, Math.ceil(state.total / state.pageSize));
  494. const current = Math.min(Math.max(1, state.currentPage), totalPages);
  495. state.currentPage = current;
  496. const pages = buildPageList(current, totalPages, 2);
  497. let html = "";
  498. html += `<button class="btn" data-action="prev" ${current === 1 ? "disabled" : ""
  499. }>上一页</button>`;
  500. pages.forEach((p) => {
  501. if (p === "...") {
  502. html += `<span class="small" style="padding:6px 8px">...</span>`;
  503. } else {
  504. html += `<button class="btn ${p === current ? "active" : ""
  505. }" data-page="${p}">${p}</button>`;
  506. }
  507. });
  508. html += `<button class="btn" data-action="next" ${current === totalPages ? "disabled" : ""
  509. }>下一页</button>`;
  510. paginationEl.innerHTML = html;
  511. }
  512. function buildPageList(current, total, delta) {
  513. const pages = [];
  514. const left = Math.max(1, current - delta);
  515. const right = Math.min(total, current + delta);
  516. if (left > 1) {
  517. pages.push(1);
  518. if (left > 2) pages.push("...");
  519. }
  520. for (let i = left; i <= right; i++) pages.push(i);
  521. if (right < total) {
  522. if (right < total - 1) pages.push("...");
  523. pages.push(total);
  524. }
  525. return pages;
  526. }
  527. paginationEl.addEventListener("click", (e) => {
  528. // 分页操作前检查登录状态
  529. if (!checkLoginStatus()) {
  530. showLoginCheckModal();
  531. return;
  532. }
  533. const btn = e.target.closest("button");
  534. if (!btn) return;
  535. const action = btn.getAttribute("data-action");
  536. if (action === "prev") {
  537. if (state.currentPage > 1) state.currentPage--;
  538. } else if (action === "next") {
  539. const totalPages = Math.max(
  540. 1,
  541. Math.ceil(state.total / state.pageSize)
  542. );
  543. if (state.currentPage < totalPages) state.currentPage++;
  544. } else {
  545. const p = Number(btn.getAttribute("data-page"));
  546. if (!isNaN(p)) state.currentPage = p;
  547. }
  548. update();
  549. });
  550. // 每页条数变更
  551. pageSizeSelect.addEventListener("change", () => {
  552. // 操作前检查登录状态
  553. if (!checkLoginStatus()) {
  554. showLoginCheckModal();
  555. return;
  556. }
  557. const newSize = parseInt(pageSizeSelect.value, 10);
  558. state.pageSize = newSize;
  559. state.currentPage = 1;
  560. update();
  561. gotoInput.value = "";
  562. });
  563. async function update() {
  564. // 更新数据前检查登录状态
  565. if (!checkLoginStatus()) {
  566. showLoginCheckModal();
  567. return;
  568. }
  569. const p = Math.max(1, state.currentPage);
  570. state.currentPage = p;
  571. await fetchPage(state.currentPage, state.pageSize);
  572. renderTable();
  573. renderPagination();
  574. }
  575. // 简单安全的文本转义(防 XSS)
  576. function escapeHtml(s) {
  577. return String(s)
  578. .replace(/&/g, "&amp;")
  579. .replace(/</g, "&lt;")
  580. .replace(/>/g, "&gt;")
  581. .replace(/"/g, "&quot;")
  582. .replace(/'/g, "&#39;");
  583. }
  584. // 首次渲染 - 检查登录状态
  585. if (checkLoginStatus()) {
  586. update();
  587. } else {
  588. showLoginCheckModal();
  589. }
  590. </script>
  591. </body>
  592. </html>