市场夺宝奇兵
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.

669 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
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: 100px">姓名</th>
  213. <th style="width: 100px">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: 150px">邮箱</th>
  218. <th style="width: 160px">添加时间</th>
  219. <th style="width: 100px">是否联系</th>
  220. <th style="width: 160px">备注</th>
  221. <th style="width: 100px">操作</th>
  222. </tr>
  223. </thead>
  224. <tbody id="tableBody"></tbody>
  225. </table>
  226. <div class="controls" style="margin-bottom: 8px; margin-top: 12px">
  227. <div class="small">
  228. 每页显示
  229. <select id="pageSizeSelect">
  230. <option value="20" selected>20</option>
  231. <option value="50">50</option>
  232. <option value="100">100</option>
  233. <option value="200">200</option>
  234. </select>
  235. </div>
  236. <div class="small"><span id="totalCount">0</span></div>
  237. <div class="pagination" id="pagination"></div>
  238. </div>
  239. <!-- 备注编辑模态 -->
  240. <div id="noteModal">
  241. <div class="dialog">
  242. <h3 style="margin: 0 0 8px">编辑备注</h3>
  243. <textarea id="noteTextarea" rows="6" placeholder="输入备注..."></textarea>
  244. <div style="
  245. margin-top: 10px;
  246. display: flex;
  247. justify-content: flex-end;
  248. gap: 8px;
  249. ">
  250. <button class="btn" id="noteCancelBtn">取消</button>
  251. <button class="btn primary" id="noteSaveBtn">保存</button>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. <div id="toast" class="toast"></div>
  257. <script type="module">
  258. import { getMemberListApi, updateMemberStateApi, editMemberNoteApi } from './src/api/member.js'
  259. // 登录验证函数
  260. function checkLoginStatus() {
  261. const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
  262. const loginTime = parseInt(localStorage.getItem('loginTime'));
  263. const currentTime = new Date().getTime();
  264. const hoursDiff = (currentTime - loginTime) / (1000 * 60 * 60);
  265. // 检查是否登录且登录时间在24小时内
  266. if (!isLoggedIn || hoursDiff >= 24) {
  267. // 清除过期的登录状态
  268. localStorage.removeItem('isLoggedIn');
  269. localStorage.removeItem('loginTime');
  270. return false;
  271. }
  272. return true;
  273. }
  274. // 显示登录验证模态框
  275. function showLoginCheckModal() {
  276. const modal = document.getElementById('loginCheckModal');
  277. modal.style.display = 'flex';
  278. }
  279. // 隐藏登录验证模态框
  280. function hideLoginCheckModal() {
  281. const modal = document.getElementById('loginCheckModal');
  282. modal.style.display = 'none';
  283. }
  284. // 跳转到登录页面
  285. function redirectToLogin() {
  286. window.location.href = 'login-management.html';
  287. }
  288. // 检查登录状态
  289. if (!checkLoginStatus()) {
  290. showLoginCheckModal();
  291. }
  292. // 绑定前往登录页面按钮事件
  293. document.getElementById('goToLoginBtn').addEventListener('click', redirectToLogin);
  294. let state = {
  295. pageSize: 20,
  296. currentPage: 1,
  297. total: 0,
  298. items: []
  299. };
  300. // DOM
  301. const tableBody = document.getElementById("tableBody");
  302. const paginationEl = document.getElementById("pagination");
  303. const totalCountEl = document.getElementById("totalCount");
  304. const currentPageEl = document.getElementById("currentPage");
  305. const showingRangeEl = document.getElementById("showingRange");
  306. const pageSizeSelect = document.getElementById("pageSizeSelect");
  307. const gotoInput = document.getElementById("gotoInput");
  308. const noteModal = document.getElementById("noteModal");
  309. const noteTextarea = document.getElementById("noteTextarea");
  310. const noteCancelBtn = document.getElementById("noteCancelBtn");
  311. const noteSaveBtn = document.getElementById("noteSaveBtn");
  312. const toastEl = document.getElementById("toast");
  313. let editingRowId = null;
  314. function showToast(msg) {
  315. toastEl.textContent = msg;
  316. toastEl.classList.add("show");
  317. setTimeout(() => toastEl.classList.remove("show"), 1000);
  318. }
  319. async function fetchPage(page, pageSize) {
  320. // 每次请求数据前都检查登录状态
  321. if (!checkLoginStatus()) {
  322. showLoginCheckModal();
  323. return;
  324. }
  325. try {
  326. const res = await getMemberListApi({
  327. page: page,
  328. page_size: pageSize,
  329. })
  330. if (typeof res.code !== "undefined" && res.code !== 200) {
  331. throw new Error(res.msg || "接口返回错误");
  332. }
  333. console.log(res)
  334. const payload = res.data || {};
  335. state.items = payload.list;
  336. state.total = payload.total;
  337. } catch (err) {
  338. alert("获取数据失败");
  339. state.total = 0;
  340. }
  341. }
  342. // 渲染表格行
  343. function renderTable() {
  344. const startIndex = (state.currentPage - 1) * state.pageSize;
  345. const items = state.items || [];
  346. tableBody.innerHTML = items
  347. .map((item, idx) => {
  348. const serial = startIndex + idx + 1;
  349. const statusClass = item.isRelated ? "status-1" : "status-0";
  350. const statusText = item.isRelated ? "已联系" : "未联系";
  351. // 构建WhatsApp链接 - 移除国家代码中的+号
  352. const cleanCode = (item.code || '').replace(/\+/g, '');
  353. const whatsappPhone = cleanCode + (item.telephone || '');
  354. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  355. return `
  356. <tr>
  357. <td>${serial}</td>
  358. <td>${escapeHtml(item.name || "")}</td>
  359. <td>
  360. <button class="btn whatsapp" data-action="whatsapp" data-id="${item.id}">WhatsApp</button>
  361. </td>
  362. <td>${escapeHtml(item.code || "")}</td>
  363. <td>${escapeHtml(item.telephone || "")}</td>
  364. <td>${escapeHtml(item.wechat || "")}</td>
  365. <td>${escapeHtml(item.email || "")}</td>
  366. <td>${escapeHtml(item.createdAt || "")}</td>
  367. <td>
  368. <button class="status-btn ${statusClass}" data-action="toggle" data-id="${item.id
  369. }">${statusText}</button>
  370. </td>
  371. <td>${escapeHtml(item.note || "")}</td>
  372. <td>
  373. <button class="btn" data-action="editNote" data-id="${item.id
  374. }">编辑备注</button>
  375. </td>
  376. </tr>
  377. `;
  378. })
  379. .join("");
  380. totalCountEl.textContent = state.total;
  381. }
  382. tableBody.addEventListener("click", async (e) => {
  383. // 每次操作前检查登录状态
  384. if (!checkLoginStatus()) {
  385. showLoginCheckModal();
  386. return;
  387. }
  388. // WhatsApp跳转
  389. const whatsappBtn = e.target.closest('[data-action="whatsapp"]');
  390. if (whatsappBtn) {
  391. const id = whatsappBtn.getAttribute("data-id");
  392. handleWhatsApp(id);
  393. return;
  394. }
  395. // 切换状态
  396. const toggler = e.target.closest('[data-action="toggle"]');
  397. if (toggler) {
  398. const id = toggler.getAttribute("data-id");
  399. await handleToggle(id, toggler);
  400. return;
  401. }
  402. // 编辑备注
  403. const editBtn = e.target.closest('[data-action="editNote"]');
  404. if (editBtn) {
  405. const id = editBtn.getAttribute("data-id");
  406. openNoteModal(id);
  407. return;
  408. }
  409. });
  410. // ---------- WhatsApp跳转 ----------
  411. function handleWhatsApp(id) {
  412. const item = state.items.find((it) => String(it.id) === String(id));
  413. if (!item) return;
  414. // 移除国家代码中的+号
  415. const cleanCode = (item.code || '').replace(/\+/g, '');
  416. const whatsappPhone = cleanCode + (item.telephone || '');
  417. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  418. window.open(whatsappUrl, '_blank');
  419. }
  420. // ---------- 切换联系状态 ----------
  421. async function handleToggle(id, btnEl) {
  422. const item = state.items.find((it) => String(it.id) === String(id));
  423. if (!item) return;
  424. const prev = item.isRelated;
  425. const newVal = prev ? 0 : 1;
  426. item.isRelated = newVal;
  427. btnEl.textContent = newVal ? "已联系" : "未联系";
  428. btnEl.classList.toggle("status-1", !!newVal);
  429. btnEl.classList.toggle("status-0", !newVal);
  430. try {
  431. const res = await updateMemberStateApi({ id: item.id, state: newVal })
  432. if (typeof res.code !== "undefined" && res.code !== 200) {
  433. throw new Error(res.msg || "更新失败");
  434. }
  435. showToast("状态修改成功");
  436. } catch (err) {
  437. item.isRelated = prev;
  438. btnEl.textContent = prev ? "已联系" : "未联系";
  439. btnEl.classList.toggle("status-1", !!prev);
  440. btnEl.classList.toggle("status-0", !prev);
  441. alert("更新失败");
  442. }
  443. }
  444. // ---------- 备注模态相关 ----------
  445. function openNoteModal(id) {
  446. // 打开模态框前检查登录状态
  447. if (!checkLoginStatus()) {
  448. showLoginCheckModal();
  449. return;
  450. }
  451. const item = state.items.find((it) => String(it.id) === String(id));
  452. if (!item) return;
  453. editingRowId = id;
  454. noteTextarea.value = item.note || "";
  455. noteModal.style.display = "flex";
  456. noteTextarea.focus();
  457. }
  458. function closeNoteModal() {
  459. editingRowId = null;
  460. noteTextarea.value = "";
  461. noteModal.style.display = "none";
  462. }
  463. noteCancelBtn.addEventListener("click", closeNoteModal);
  464. noteSaveBtn.addEventListener("click", async () => {
  465. // 保存前检查登录状态
  466. if (!checkLoginStatus()) {
  467. showLoginCheckModal();
  468. return;
  469. }
  470. if (!editingRowId) return closeNoteModal();
  471. const newNote = noteTextarea.value.trim();
  472. const item = state.items.find((it) => String(it.id) === String(editingRowId));
  473. if (!item) return closeNoteModal();
  474. try {
  475. const res = await editMemberNoteApi({ id: item.id, note: newNote })
  476. if (typeof res.code !== "undefined" && res.code !== 200) {
  477. throw new Error(res.msg || "保存失败");
  478. }
  479. const prevNote = item.note;
  480. item.note = newNote;
  481. renderTable();
  482. showToast("备注保存成功");
  483. } catch (err) {
  484. alert("保存备注失败");
  485. } finally {
  486. closeNoteModal();
  487. }
  488. });
  489. // 渲染分页控件(页码、上一页、下一页)
  490. function renderPagination() {
  491. const totalPages = Math.max(1, Math.ceil(state.total / state.pageSize));
  492. const current = Math.min(Math.max(1, state.currentPage), totalPages);
  493. state.currentPage = current;
  494. const pages = buildPageList(current, totalPages, 2);
  495. let html = "";
  496. html += `<button class="btn" data-action="prev" ${current === 1 ? "disabled" : ""
  497. }>上一页</button>`;
  498. pages.forEach((p) => {
  499. if (p === "...") {
  500. html += `<span class="small" style="padding:6px 8px">...</span>`;
  501. } else {
  502. html += `<button class="btn ${p === current ? "active" : ""
  503. }" data-page="${p}">${p}</button>`;
  504. }
  505. });
  506. html += `<button class="btn" data-action="next" ${current === totalPages ? "disabled" : ""
  507. }>下一页</button>`;
  508. paginationEl.innerHTML = html;
  509. }
  510. function buildPageList(current, total, delta) {
  511. const pages = [];
  512. const left = Math.max(1, current - delta);
  513. const right = Math.min(total, current + delta);
  514. if (left > 1) {
  515. pages.push(1);
  516. if (left > 2) pages.push("...");
  517. }
  518. for (let i = left; i <= right; i++) pages.push(i);
  519. if (right < total) {
  520. if (right < total - 1) pages.push("...");
  521. pages.push(total);
  522. }
  523. return pages;
  524. }
  525. paginationEl.addEventListener("click", (e) => {
  526. // 分页操作前检查登录状态
  527. if (!checkLoginStatus()) {
  528. showLoginCheckModal();
  529. return;
  530. }
  531. const btn = e.target.closest("button");
  532. if (!btn) return;
  533. const action = btn.getAttribute("data-action");
  534. if (action === "prev") {
  535. if (state.currentPage > 1) state.currentPage--;
  536. } else if (action === "next") {
  537. const totalPages = Math.max(
  538. 1,
  539. Math.ceil(state.total / state.pageSize)
  540. );
  541. if (state.currentPage < totalPages) state.currentPage++;
  542. } else {
  543. const p = Number(btn.getAttribute("data-page"));
  544. if (!isNaN(p)) state.currentPage = p;
  545. }
  546. update();
  547. });
  548. // 每页条数变更
  549. pageSizeSelect.addEventListener("change", () => {
  550. // 操作前检查登录状态
  551. if (!checkLoginStatus()) {
  552. showLoginCheckModal();
  553. return;
  554. }
  555. const newSize = parseInt(pageSizeSelect.value, 10);
  556. state.pageSize = newSize;
  557. state.currentPage = 1;
  558. update();
  559. gotoInput.value = "";
  560. });
  561. async function update() {
  562. // 更新数据前检查登录状态
  563. if (!checkLoginStatus()) {
  564. showLoginCheckModal();
  565. return;
  566. }
  567. const p = Math.max(1, state.currentPage);
  568. state.currentPage = p;
  569. await fetchPage(state.currentPage, state.pageSize);
  570. renderTable();
  571. renderPagination();
  572. }
  573. // 简单安全的文本转义(防 XSS)
  574. function escapeHtml(s) {
  575. return String(s)
  576. .replace(/&/g, "&amp;")
  577. .replace(/</g, "&lt;")
  578. .replace(/>/g, "&gt;")
  579. .replace(/"/g, "&quot;")
  580. .replace(/'/g, "&#39;");
  581. }
  582. // 首次渲染 - 检查登录状态
  583. if (checkLoginStatus()) {
  584. update();
  585. } else {
  586. showLoginCheckModal();
  587. }
  588. </script>
  589. </body>
  590. </html>