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

759 lines
21 KiB

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