fix: improve promotion tabs and referral layout
This commit is contained in:
+7
-202
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* 功能:
|
||||
* - 签到 panel:拉取 /signin/today,按钮触发 POST /signin
|
||||
* - 邀请 panel:拉取 /invite/me,复制邀请链接
|
||||
* - revenue panel:拉取 /revenue/me,复制推广链接
|
||||
*
|
||||
* 仅在 page-profile 页面 + 启用积分时加载。
|
||||
*/
|
||||
@@ -189,210 +189,16 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 邀请 =====
|
||||
function initInvite() {
|
||||
var root = document.querySelector('[data-aksrt-invite]');
|
||||
if (!root) return;
|
||||
var linkInput = root.querySelector('[data-invite-link]');
|
||||
var copyBtn = root.querySelector('[data-invite-copy]');
|
||||
var stats = root.querySelector('[data-invite-stats]');
|
||||
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)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function formatDate(value) {
|
||||
if (!value || value === '0000-00-00 00:00:00') return '';
|
||||
var date = new Date(String(value).replace(' ', 'T') + 'Z');
|
||||
if (isNaN(date.getTime())) return String(value).slice(0, 16);
|
||||
function pad(n) { return n < 10 ? '0' + n : String(n); }
|
||||
return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + ' ' + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
}
|
||||
|
||||
function statusMeta(status) {
|
||||
if (status === 'rewarded') {
|
||||
return { label: '已奖励', text: '奖励已发放', className: 'is-rewarded' };
|
||||
}
|
||||
if (status === 'verified') {
|
||||
return { label: '已验证', text: '等待奖励发放', className: 'is-verified' };
|
||||
}
|
||||
return { label: '已注册', text: '等待完成验证', className: 'is-registered' };
|
||||
}
|
||||
|
||||
function setCopyText(text) {
|
||||
if (!copyBtn) return;
|
||||
var label = copyBtn.querySelector('span');
|
||||
if (label) label.textContent = text;
|
||||
else copyBtn.textContent = text;
|
||||
}
|
||||
|
||||
function renderInviteList(items, total) {
|
||||
if (!listEl) return;
|
||||
listEl.classList.remove('is-loading');
|
||||
if (totalEl) {
|
||||
if (total > items.length) totalEl.textContent = '最近 ' + items.length + ' 条 / 共 ' + total + ' 条';
|
||||
else totalEl.textContent = total ? '共 ' + total + ' 条' : '暂无记录';
|
||||
}
|
||||
if (!items.length) {
|
||||
listEl.innerHTML = '<div class="uc-promotion-record-empty">分享链接后,好友注册记录会显示在这里。</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
listEl.innerHTML = items.map(function (item) {
|
||||
var name = item.invitee_name || (item.invitee_id ? '用户 #' + item.invitee_id : '受邀用户');
|
||||
var first = name ? name.charAt(0).toUpperCase() : '?';
|
||||
var meta = statusMeta(item.status);
|
||||
var createdAt = formatDate(item.created_at);
|
||||
var rewardedAt = formatDate(item.rewarded_at);
|
||||
var statusText = meta.text;
|
||||
if (item.status === 'rewarded' && rewardedAt) statusText = '奖励于 ' + rewardedAt;
|
||||
var avatar = item.invitee_avatar
|
||||
? '<img src="' + escapeHtml(item.invitee_avatar) + '" alt="">'
|
||||
: '<span>' + escapeHtml(first) + '</span>';
|
||||
|
||||
return '<div class="uc-promotion-record ' + meta.className + '">' +
|
||||
'<div class="uc-promotion-record__avatar">' + avatar + '</div>' +
|
||||
'<div class="uc-promotion-record__main">' +
|
||||
'<strong>' + escapeHtml(name) + '</strong>' +
|
||||
'<span>' + (createdAt ? '注册于 ' + escapeHtml(createdAt) : '注册时间未知') + '</span>' +
|
||||
'</div>' +
|
||||
'<div class="uc-promotion-record__status">' +
|
||||
'<span class="uc-promotion-badge ' + meta.className + '">' + meta.label + '</span>' +
|
||||
'<small>' + escapeHtml(statusText) + '</small>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
api('/invite/me').then(function (r) {
|
||||
if (!r.ok) {
|
||||
if (linkInput) linkInput.value = '';
|
||||
if (copyBtn) copyBtn.disabled = true;
|
||||
if (codeEl) codeEl.textContent = '--';
|
||||
if (stats) {
|
||||
stats.querySelectorAll('[data-stat]').forEach(function (el) {
|
||||
el.textContent = '—';
|
||||
});
|
||||
}
|
||||
setStatus((r.json && r.json.message) || '推广数据加载失败,请稍后刷新。', true);
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
var k = el.getAttribute('data-stat');
|
||||
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 = '<div class="uc-promotion-record-empty">邀请记录加载失败,请稍后刷新。</div>';
|
||||
if (totalEl) totalEl.textContent = '加载失败';
|
||||
return;
|
||||
}
|
||||
var j = r.json || {};
|
||||
renderInviteList(j.items || [], Number(j.total || 0));
|
||||
}).catch(function () {
|
||||
listEl.classList.remove('is-loading');
|
||||
listEl.innerHTML = '<div class="uc-promotion-record-empty">邀请记录加载失败,请稍后刷新。</div>';
|
||||
if (totalEl) totalEl.textContent = '加载失败';
|
||||
});
|
||||
}
|
||||
|
||||
if (!copyBtn) return;
|
||||
var copying = false;
|
||||
copyBtn.addEventListener('click', function () {
|
||||
if (copying || !linkInput || !linkInput.value) return;
|
||||
copying = true;
|
||||
copyBtn.disabled = true;
|
||||
setCopyFeedback('正在复制…');
|
||||
|
||||
function copied() {
|
||||
setCopyText('已复制');
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
// ===== Forward-only affiliate promotion center =====
|
||||
function initAffiliatePromotion() {
|
||||
var root = document.querySelector('[data-aksrt-promotion-page]');
|
||||
// ===== Forward-only affiliate revenue center =====
|
||||
function initAffiliateRevenue() {
|
||||
var root = document.querySelector('[data-aksrt-revenue-page]');
|
||||
if (!root || root.dataset.affiliateBound) return;
|
||||
root.dataset.affiliateBound = '1';
|
||||
var input = root.querySelector('[data-affiliate-link]');
|
||||
var copy = root.querySelector('[data-affiliate-copy]');
|
||||
var feedback = root.querySelector('[data-affiliate-feedback]');
|
||||
function setFeedback(text, error) { if (feedback) { feedback.textContent = text; feedback.classList.toggle('is-error', !!error); } }
|
||||
api('/promotion/me').then(function (r) {
|
||||
api('/revenue/me').then(function (r) {
|
||||
if (!r.ok) { setFeedback((r.json && r.json.message) || '推广数据加载失败。', true); return; }
|
||||
var j = r.json || {}, stats = j.stats || {};
|
||||
if (input) {
|
||||
@@ -415,7 +221,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
window.AKSRTAffiliatePromotionInit = initAffiliatePromotion;
|
||||
window.AKSRTAffiliateRevenueInit = initAffiliateRevenue;
|
||||
|
||||
|
||||
|
||||
@@ -1030,8 +836,7 @@
|
||||
function bootAssets() {
|
||||
initSignin();
|
||||
initSigninGoto();
|
||||
initInvite();
|
||||
initAffiliatePromotion();
|
||||
initAffiliateRevenue();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
|
||||
Reference in New Issue
Block a user