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

533 lines
15 KiB

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
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
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
3 months ago
3 months ago
3 months ago
3 months ago
3 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. </style>
  164. </head>
  165. <body>
  166. <div class="card">
  167. <table aria-describedby="tableDesc">
  168. <thead>
  169. <tr>
  170. <th style="width: 40px">#</th>
  171. <th style="width: 100px">姓名</th>
  172. <th style="width: 100px">WhatsApp</th>
  173. <th style="width: 90px">国家/地区代码</th>
  174. <th style="width: 120px">电话号码</th>
  175. <th style="width: 120px">微信ID</th>
  176. <th style="width: 150px">邮箱</th>
  177. <th style="width: 160px">添加时间</th>
  178. <th style="width: 100px">是否联系</th>
  179. <th style="width: 160px">备注</th>
  180. <th style="width: 100px">操作</th>
  181. </tr>
  182. </thead>
  183. <tbody id="tableBody"></tbody>
  184. </table>
  185. <div class="controls" style="margin-bottom: 8px; margin-top: 12px">
  186. <div class="small">
  187. 每页显示
  188. <select id="pageSizeSelect">
  189. <option value="20" selected>20</option>
  190. <option value="50">50</option>
  191. <option value="100">100</option>
  192. <option value="200">200</option>
  193. </select>
  194. </div>
  195. <div class="small"><span id="totalCount">0</span></div>
  196. <div class="pagination" id="pagination"></div>
  197. </div>
  198. <!-- 备注编辑模态 -->
  199. <div id="noteModal">
  200. <div class="dialog">
  201. <h3 style="margin: 0 0 8px">编辑备注</h3>
  202. <textarea id="noteTextarea" rows="6" placeholder="输入备注..."></textarea>
  203. <div style="
  204. margin-top: 10px;
  205. display: flex;
  206. justify-content: flex-end;
  207. gap: 8px;
  208. ">
  209. <button class="btn" id="noteCancelBtn">取消</button>
  210. <button class="btn primary" id="noteSaveBtn">保存</button>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. <div id="toast" class="toast"></div>
  216. <script type="module">
  217. import { getMemberListApi, updateMemberStateApi, editMemberNoteApi } from './src/api/member.js'
  218. let state = {
  219. pageSize: 20,
  220. currentPage: 1,
  221. total: 0,
  222. items: []
  223. };
  224. // DOM
  225. const tableBody = document.getElementById("tableBody");
  226. const paginationEl = document.getElementById("pagination");
  227. const totalCountEl = document.getElementById("totalCount");
  228. const currentPageEl = document.getElementById("currentPage");
  229. const showingRangeEl = document.getElementById("showingRange");
  230. const pageSizeSelect = document.getElementById("pageSizeSelect");
  231. const gotoInput = document.getElementById("gotoInput");
  232. const noteModal = document.getElementById("noteModal");
  233. const noteTextarea = document.getElementById("noteTextarea");
  234. const noteCancelBtn = document.getElementById("noteCancelBtn");
  235. const noteSaveBtn = document.getElementById("noteSaveBtn");
  236. const toastEl = document.getElementById("toast");
  237. let editingRowId = null;
  238. function showToast(msg) {
  239. toastEl.textContent = msg;
  240. toastEl.classList.add("show");
  241. setTimeout(() => toastEl.classList.remove("show"), 1000);
  242. }
  243. async function fetchPage(page, pageSize) {
  244. try {
  245. const res = await getMemberListApi({
  246. page: page,
  247. page_size: pageSize,
  248. })
  249. if (typeof res.code !== "undefined" && res.code !== 200) {
  250. throw new Error(res.msg || "接口返回错误");
  251. }
  252. console.log(res)
  253. const payload = res.data || {};
  254. state.items = payload.list;
  255. state.total = payload.total;
  256. } catch (err) {
  257. alert("获取数据失败");
  258. state.total = 0;
  259. }
  260. }
  261. // 渲染表格行
  262. function renderTable() {
  263. const startIndex = (state.currentPage - 1) * state.pageSize;
  264. const items = state.items || [];
  265. tableBody.innerHTML = items
  266. .map((item, idx) => {
  267. const serial = startIndex + idx + 1;
  268. const statusClass = item.isRelated ? "status-1" : "status-0";
  269. const statusText = item.isRelated ? "已联系" : "未联系";
  270. // 构建WhatsApp链接 - 移除国家代码中的+号
  271. const cleanCode = (item.code || '').replace(/\+/g, '');
  272. const whatsappPhone = cleanCode + (item.telephone || '');
  273. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  274. return `
  275. <tr>
  276. <td>${serial}</td>
  277. <td>${escapeHtml(item.name || "")}</td>
  278. <td>
  279. <button class="btn whatsapp" data-action="whatsapp" data-id="${item.id}">WhatsApp</button>
  280. </td>
  281. <td>${escapeHtml(item.code || "")}</td>
  282. <td>${escapeHtml(item.telephone || "")}</td>
  283. <td>${escapeHtml(item.wechat || "")}</td>
  284. <td>${escapeHtml(item.email || "")}</td>
  285. <td>${escapeHtml(item.createdAt || "")}</td>
  286. <td>
  287. <button class="status-btn ${statusClass}" data-action="toggle" data-id="${item.id
  288. }">${statusText}</button>
  289. </td>
  290. <td>${escapeHtml(item.note || "")}</td>
  291. <td>
  292. <button class="btn" data-action="editNote" data-id="${item.id
  293. }">编辑备注</button>
  294. </td>
  295. </tr>
  296. `;
  297. })
  298. .join("");
  299. totalCountEl.textContent = state.total;
  300. }
  301. tableBody.addEventListener("click", async (e) => {
  302. // WhatsApp跳转
  303. const whatsappBtn = e.target.closest('[data-action="whatsapp"]');
  304. if (whatsappBtn) {
  305. const id = whatsappBtn.getAttribute("data-id");
  306. handleWhatsApp(id);
  307. return;
  308. }
  309. // 切换状态
  310. const toggler = e.target.closest('[data-action="toggle"]');
  311. if (toggler) {
  312. const id = toggler.getAttribute("data-id");
  313. await handleToggle(id, toggler);
  314. return;
  315. }
  316. // 编辑备注
  317. const editBtn = e.target.closest('[data-action="editNote"]');
  318. if (editBtn) {
  319. const id = editBtn.getAttribute("data-id");
  320. openNoteModal(id);
  321. return;
  322. }
  323. });
  324. // ---------- WhatsApp跳转 ----------
  325. function handleWhatsApp(id) {
  326. const item = state.items.find((it) => String(it.id) === String(id));
  327. if (!item) return;
  328. // 移除国家代码中的+号
  329. const cleanCode = (item.code || '').replace(/\+/g, '');
  330. const whatsappPhone = cleanCode + (item.telephone || '');
  331. const whatsappUrl = `https://api.whatsapp.com/send?phone=${encodeURIComponent(whatsappPhone)}&text=${encodeURIComponent('hello欢迎来到赢在美股')}`;
  332. window.open(whatsappUrl, '_blank');
  333. }
  334. // ---------- 切换联系状态 ----------
  335. async function handleToggle(id, btnEl) {
  336. const item = state.items.find((it) => String(it.id) === String(id));
  337. if (!item) return;
  338. const prev = item.isRelated;
  339. const newVal = prev ? 0 : 1;
  340. item.isRelated = newVal;
  341. btnEl.textContent = newVal ? "已联系" : "未联系";
  342. btnEl.classList.toggle("status-1", !!newVal);
  343. btnEl.classList.toggle("status-0", !newVal);
  344. try {
  345. const res = await updateMemberStateApi({ id: item.id, state: newVal })
  346. if (typeof res.code !== "undefined" && res.code !== 200) {
  347. throw new Error(res.msg || "更新失败");
  348. }
  349. showToast("状态修改成功");
  350. } catch (err) {
  351. item.isRelated = prev;
  352. btnEl.textContent = prev ? "已联系" : "未联系";
  353. btnEl.classList.toggle("status-1", !!prev);
  354. btnEl.classList.toggle("status-0", !prev);
  355. alert("更新失败");
  356. }
  357. }
  358. // ---------- 备注模态相关 ----------
  359. function openNoteModal(id) {
  360. const item = state.items.find((it) => String(it.id) === String(id));
  361. if (!item) return;
  362. editingRowId = id;
  363. noteTextarea.value = item.note || "";
  364. noteModal.style.display = "flex";
  365. noteTextarea.focus();
  366. }
  367. function closeNoteModal() {
  368. editingRowId = null;
  369. noteTextarea.value = "";
  370. noteModal.style.display = "none";
  371. }
  372. noteCancelBtn.addEventListener("click", closeNoteModal);
  373. noteSaveBtn.addEventListener("click", async () => {
  374. if (!editingRowId) return closeNoteModal();
  375. const newNote = noteTextarea.value.trim();
  376. const item = state.items.find((it) => String(it.id) === String(editingRowId));
  377. if (!item) return closeNoteModal();
  378. try {
  379. const res = await editMemberNoteApi({ id: item.id, note: newNote })
  380. if (typeof res.code !== "undefined" && res.code !== 200) {
  381. throw new Error(res.msg || "保存失败");
  382. }
  383. const prevNote = item.note;
  384. item.note = newNote;
  385. renderTable();
  386. showToast("备注保存成功");
  387. } catch (err) {
  388. alert("保存备注失败");
  389. } finally {
  390. closeNoteModal();
  391. }
  392. });
  393. // 渲染分页控件(页码、上一页、下一页)
  394. function renderPagination() {
  395. const totalPages = Math.max(1, Math.ceil(state.total / state.pageSize));
  396. const current = Math.min(Math.max(1, state.currentPage), totalPages);
  397. state.currentPage = current;
  398. const pages = buildPageList(current, totalPages, 2);
  399. let html = "";
  400. html += `<button class="btn" data-action="prev" ${current === 1 ? "disabled" : ""
  401. }>上一页</button>`;
  402. pages.forEach((p) => {
  403. if (p === "...") {
  404. html += `<span class="small" style="padding:6px 8px">...</span>`;
  405. } else {
  406. html += `<button class="btn ${p === current ? "active" : ""
  407. }" data-page="${p}">${p}</button>`;
  408. }
  409. });
  410. html += `<button class="btn" data-action="next" ${current === totalPages ? "disabled" : ""
  411. }>下一页</button>`;
  412. paginationEl.innerHTML = html;
  413. }
  414. function buildPageList(current, total, delta) {
  415. const pages = [];
  416. const left = Math.max(1, current - delta);
  417. const right = Math.min(total, current + delta);
  418. if (left > 1) {
  419. pages.push(1);
  420. if (left > 2) pages.push("...");
  421. }
  422. for (let i = left; i <= right; i++) pages.push(i);
  423. if (right < total) {
  424. if (right < total - 1) pages.push("...");
  425. pages.push(total);
  426. }
  427. return pages;
  428. }
  429. paginationEl.addEventListener("click", (e) => {
  430. const btn = e.target.closest("button");
  431. if (!btn) return;
  432. const action = btn.getAttribute("data-action");
  433. if (action === "prev") {
  434. if (state.currentPage > 1) state.currentPage--;
  435. } else if (action === "next") {
  436. const totalPages = Math.max(
  437. 1,
  438. Math.ceil(state.total / state.pageSize)
  439. );
  440. if (state.currentPage < totalPages) state.currentPage++;
  441. } else {
  442. const p = Number(btn.getAttribute("data-page"));
  443. if (!isNaN(p)) state.currentPage = p;
  444. }
  445. update();
  446. });
  447. // 每页条数变更
  448. pageSizeSelect.addEventListener("change", () => {
  449. const newSize = parseInt(pageSizeSelect.value, 10);
  450. state.pageSize = newSize;
  451. state.currentPage = 1;
  452. update();
  453. gotoInput.value = "";
  454. });
  455. async function update() {
  456. const p = Math.max(1, state.currentPage);
  457. state.currentPage = p;
  458. await fetchPage(state.currentPage, state.pageSize);
  459. renderTable();
  460. renderPagination();
  461. }
  462. // 简单安全的文本转义(防 XSS)
  463. function escapeHtml(s) {
  464. return String(s)
  465. .replace(/&/g, "&amp;")
  466. .replace(/</g, "&lt;")
  467. .replace(/>/g, "&gt;")
  468. .replace(/"/g, "&quot;")
  469. .replace(/'/g, "&#39;");
  470. }
  471. // 首次渲染
  472. update();
  473. </script>
  474. </body>
  475. </html>