From 156060d2ec26ac3780afe1f9fcd2efc80321a83f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Aug 2026 13:57:32 +0800 Subject: [PATCH] feat(users): build promotion invite panel --- assets/js/credits.js | 85 +++++++++++++++---- .../profile-promotion.php | 76 ++++++++++++++++- 2 files changed, 140 insertions(+), 21 deletions(-) diff --git a/assets/js/credits.js b/assets/js/credits.js index 031e3a51..5357cf7d 100644 --- a/assets/js/credits.js +++ b/assets/js/credits.js @@ -225,6 +225,20 @@ var codeEl = root.querySelector('[data-invite-code]'); var listEl = root.querySelector('[data-invite-list]'); var totalEl = root.querySelector('[data-invite-total]'); + var statusEl = root.querySelector('[data-invite-status]'); + var copyFeedback = root.querySelector('[data-invite-copy-feedback]'); + + function setStatus(text, isError) { + if (!statusEl) return; + statusEl.textContent = text; + statusEl.classList.toggle('is-error', !!isError); + } + + function setCopyFeedback(text, isError) { + if (!copyFeedback) return; + copyFeedback.textContent = text; + copyFeedback.classList.toggle('is-error', !!isError); + } function escapeHtml(value) { return String(value == null ? '' : value) @@ -268,7 +282,7 @@ else totalEl.textContent = total ? '共 ' + total + ' 条' : '暂无记录'; } if (!items.length) { - listEl.innerHTML = '
分享链接后,好友注册记录会显示在这里。
'; + listEl.innerHTML = '
分享链接后,好友注册记录会显示在这里。
'; return; } @@ -284,14 +298,14 @@ ? '' : '' + escapeHtml(first) + ''; - return '
' + - '
' + avatar + '
' + - '
' + + return '
' + + '
' + avatar + '
' + + '
' + '' + escapeHtml(name) + '' + '' + (createdAt ? '注册于 ' + escapeHtml(createdAt) : '注册时间未知') + '' + '
' + - '
' + - '' + meta.label + '' + + '
' + + '' + meta.label + '' + '' + escapeHtml(statusText) + '' + '
' + '
'; @@ -308,10 +322,12 @@ el.textContent = '—'; }); } + setStatus((r.json && r.json.message) || '推广数据加载失败,请稍后刷新。', true); return; } - var j = r.json; + var j = r.json || {}; if (linkInput) linkInput.value = j.invite_url || ''; + if (copyBtn) copyBtn.disabled = !j.invite_url; if (codeEl) codeEl.textContent = j.code || '--'; if (stats && j.stats) { stats.querySelectorAll('[data-stat]').forEach(function (el) { @@ -319,16 +335,23 @@ el.textContent = (j.stats[k] || 0).toString(); }); } + setStatus('推广数据已更新。'); }).catch(function () { if (copyBtn) copyBtn.disabled = true; if (codeEl) codeEl.textContent = '--'; + if (stats) { + stats.querySelectorAll('[data-stat]').forEach(function (el) { + el.textContent = '—'; + }); + } + setStatus('推广数据加载失败,请检查网络后重试。', true); }); if (listEl) { api('/invite/list?per_page=8').then(function (r) { if (!r.ok) { listEl.classList.remove('is-loading'); - listEl.innerHTML = '
邀请记录加载失败,请稍后刷新。
'; + listEl.innerHTML = '
邀请记录加载失败,请稍后刷新。
'; if (totalEl) totalEl.textContent = '加载失败'; return; } @@ -336,7 +359,7 @@ renderInviteList(j.items || [], Number(j.total || 0)); }).catch(function () { listEl.classList.remove('is-loading'); - listEl.innerHTML = '
邀请记录加载失败,请稍后刷新。
'; + listEl.innerHTML = '
邀请记录加载失败,请稍后刷新。
'; if (totalEl) totalEl.textContent = '加载失败'; }); } @@ -346,17 +369,43 @@ copyBtn.addEventListener('click', function () { if (copying || !linkInput || !linkInput.value) return; copying = true; - if (navigator.clipboard) { - navigator.clipboard.writeText(linkInput.value).then(function () { - setCopyText('已复制'); - setTimeout(function () { setCopyText('复制链接'); copying = false; }, 2000); - }).catch(function () { copying = false; }); - } else { - linkInput.select(); - document.execCommand('copy'); + copyBtn.disabled = true; + setCopyFeedback('正在复制…'); + + function copied() { setCopyText('已复制'); - setTimeout(function () { setCopyText('复制链接'); copying = false; }, 2000); + setCopyFeedback('推广链接已复制到剪贴板。'); + setTimeout(function () { + setCopyText('复制链接'); + setCopyFeedback(''); + copyBtn.disabled = false; + copying = false; + }, 2000); } + + function copyFailed() { + setCopyText('复制链接'); + setCopyFeedback('复制失败,请手动选择并复制链接。', true); + copyBtn.disabled = false; + copying = false; + linkInput.focus(); + linkInput.select(); + } + + if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') { + navigator.clipboard.writeText(linkInput.value).then(copied).catch(copyFailed); + return; + } + + linkInput.focus(); + linkInput.select(); + try { + if (document.execCommand('copy')) { + copied(); + return; + } + } catch (_) {} + copyFailed(); }); } diff --git a/inc/helpers/user-center-renderers/profile-promotion.php b/inc/helpers/user-center-renderers/profile-promotion.php index 1f20a113..e4755602 100644 --- a/inc/helpers/user-center-renderers/profile-promotion.php +++ b/inc/helpers/user-center-renderers/profile-promotion.php @@ -1,6 +1,6 @@ -
+
@@ -18,5 +18,75 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_

-

+

+ +
+ +
+ +
+
+

+

+
+
+
+ + — + +
+
+ + — + +
+
+ + — + +
+
+
+ + + +
+
+

+
+

+
+ +
+
+
+

+

+
+ +
+
+
+
+