feat(runtime): 全站前端脚本统一接入 AksrtFrontend 全局 DOM 生命周期

- rehydrate.js 新增 boot()/aksrt:ready 事件,支持 boot 后晚注册立即以 init 触发
- aksrt-runtime.js 初始加载改走 AksrtFrontend.boot,tooltip/倒计时注册为组件
- 约 30 个前端脚本(首页、评论、支付、路由、页面叶子、widgets)
  从直接 DOMContentLoaded 迁移为 AksrtFrontend.register,并加幂等标记
- section-navs 依赖改为 aksrt-runtime,保证注册时序
- 清理死代码:删除孤儿 loader.js/main.js 及 runtime/page-navs 遗留副本
- loader.js 移除已迁移模块的 tbquire 路径映射,main.js 相应瘦身
- build-public-assets.mjs 增加 runtime/main.min.js 自动压缩步骤
- 新增 4 个契约测试(homepage-dom/rehydrate-runtime/global-dom-init/
  public-bundle-parity),3 个既有 harness 适配注册表初始化方式
This commit is contained in:
kate522 committed 2026-09-02 21:48:56 +08:00
1 parent 5984d4e42d
commit 1f4a39d8f8
60 files changed
+1810 -1742

No files matched your search

+68 -55
View File
@@ -15,6 +15,21 @@
return;
}
var activePoll = null;
var balancesRefreshed = false;
function elementsIn(root, selector) {
var elements = [];
root = root || document;
if (root.nodeType === 1 && root.matches(selector)) elements.push(root);
if (root.querySelectorAll) root.querySelectorAll(selector).forEach(function (element) { elements.push(element); });
return elements;
}
function firstIn(root, selector) {
root = root || document;
if (root.nodeType === 1 && root.matches(selector)) return root;
return root.querySelector ? root.querySelector(selector) : null;
}
function operationKey(owner) {
if (!owner.dataset.aksrtOperationKey) {
@@ -89,8 +104,12 @@
}
// Task-list "去签到" → scroll + click the real asset-card sign-in button.
function initSigninGoto() {
document.querySelectorAll('[data-aksrt-signin-goto]').forEach(function (el) {
function initSigninGoto(root) {
root = root || document;
var items = [];
if (root.nodeType === 1 && root.matches('[data-aksrt-signin-goto]')) items.push(root);
if (root.querySelectorAll) root.querySelectorAll('[data-aksrt-signin-goto]').forEach(function (el) { items.push(el); });
items.forEach(function (el) {
if (el.dataset.aksrtSigninGotoInitialized === '1') return;
el.dataset.aksrtSigninGotoInitialized = '1';
el.addEventListener('click', function (e) {
@@ -113,8 +132,8 @@
}
// ===== Forward-only affiliate revenue center =====
function initAffiliateRevenue() {
var root = document.querySelector('[data-aksrt-revenue-page]');
function initAffiliateRevenue(scope) {
var root = firstIn(scope, '[data-aksrt-revenue-page]');
if (!root || root.dataset.affiliateBound) return;
root.dataset.affiliateBound = '1';
var input = root.querySelector('[data-affiliate-link]');
@@ -149,9 +168,10 @@
// ===== VIP 积分兑换 =====
function initVipPointsExchange() {
var root = document.querySelector('[data-aksrt-vip-points]');
if (!root) return;
function initVipPointsExchange(scope) {
var root = firstIn(scope, '[data-aksrt-vip-points]');
if (!root || root.dataset.aksrtVipPointsBound === '1') return;
root.dataset.aksrtVipPointsBound = '1';
var tip = root.querySelector('[data-aksrt-vip-points-tip]');
var busy = false;
var coordinator = window.AksrtVipPurchaseCoordinator;
@@ -191,9 +211,10 @@
}
// ===== VIP 开通 =====
function initVipShop() {
var root = document.querySelector('[data-aksrt-vip-shop]');
if (!root) return;
function initVipShop(scope) {
var root = firstIn(scope, '[data-aksrt-vip-shop]');
if (!root || root.dataset.aksrtVipShopBound === '1') return;
root.dataset.aksrtVipShopBound = '1';
var tip = root.querySelector('[data-aksrt-vip-tip]');
var busy = false;
var coordinator = window.AksrtVipPurchaseCoordinator;
@@ -265,11 +286,13 @@
}
// ===== 卡密兑换(余额 / 会员) =====
function initCardPass() {
var roots = document.querySelectorAll('[data-aksrt-card-pass]');
function initCardPass(scope) {
var roots = elementsIn(scope, '[data-aksrt-card-pass]');
if (!roots || !roots.length) return;
Array.prototype.forEach.call(roots, function (root) {
if (root.dataset.aksrtCardPassBound === '1') return;
root.dataset.aksrtCardPassBound = '1';
var tip = root.querySelector('[data-aksrt-card-tip]');
var busy = false;
resetOperationKeyOnChange(root);
@@ -380,8 +403,8 @@
return handle;
}
function initBalanceCharge() {
var modal = document.querySelector('[data-aksrt-charge-modal]');
function initBalanceCharge(scope) {
var modal = firstIn(scope, '[data-aksrt-charge-modal]');
if (!modal || modal.dataset.aksrtChargeInitialized === '1') return;
modal.dataset.aksrtChargeInitialized = '1';
var form = modal.querySelector('[data-aksrt-charge-form]');
@@ -458,8 +481,8 @@
});
}
function initTransfer() {
var modal = document.querySelector('[data-aksrt-transfer-modal]');
function initTransfer(scope) {
var modal = firstIn(scope, '[data-aksrt-transfer-modal]');
if (!modal || modal.dataset.aksrtTransferInitialized === '1') return;
modal.dataset.aksrtTransferInitialized = '1';
var form = modal.querySelector('[data-aksrt-transfer-form]');
@@ -590,8 +613,8 @@
});
}
function initPointsExchange() {
var modal = document.querySelector('[data-aksrt-points-exchange-modal]');
function initPointsExchange(scope) {
var modal = firstIn(scope, '[data-aksrt-points-exchange-modal]');
if (!modal || modal.dataset.aksrtPointsExchangeInitialized === '1') return;
modal.dataset.aksrtPointsExchangeInitialized = '1';
var form = modal.querySelector('[data-aksrt-points-exchange-form]');
@@ -650,8 +673,8 @@
});
}
function initWithdraw() {
var modal = document.querySelector('[data-aksrt-withdraw-modal]');
function initWithdraw(scope) {
var modal = firstIn(scope, '[data-aksrt-withdraw-modal]');
if (!modal || modal.dataset.aksrtWithdrawInitialized === '1') return;
modal.dataset.aksrtWithdrawInitialized = '1';
var form = modal.querySelector('[data-aksrt-withdraw-form]');
@@ -735,27 +758,28 @@
});
}
function initAssetTabs() {
var nav = document.querySelectorAll('[data-aksrt-asset-tab]');
function initAssetTabs(root) {
var nav = elementsIn(root, '[data-aksrt-asset-tab]');
if (!nav.length) return;
var scope = root || document;
nav.forEach(function (link) {
if (link.dataset.aksrtAssetTabBound === 'true') return;
link.dataset.aksrtAssetTabBound = 'true';
link.addEventListener('click', function (e) {
e.preventDefault();
var key = link.getAttribute('data-aksrt-asset-tab');
document.querySelectorAll('.uc-asset-tabs__nav [data-aksrt-asset-tab]').forEach(function (a) {
elementsIn(scope, '[data-aksrt-asset-tab]').forEach(function (a) {
var li = a.closest('li');
if (!li) return;
var aKey = a.getAttribute('data-aksrt-asset-tab');
var on = aKey === key || (key === 'points_date' && aKey === 'points_free');
li.classList.toggle('active', on);
});
var tabs = document.querySelector('.uc-asset-tabs');
var tabs = firstIn(scope, '.uc-asset-tabs');
if (tabs && typeof tabs.scrollIntoView === 'function') {
tabs.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
document.querySelectorAll('[data-aksrt-asset-pane]').forEach(function (pane) {
elementsIn(scope, '[data-aksrt-asset-pane]').forEach(function (pane) {
var on = pane.getAttribute('data-aksrt-asset-pane') === key;
pane.classList.toggle('is-active', on);
pane.hidden = !on;
@@ -765,8 +789,8 @@
}
function initWithdrawHistory() {
var modal = document.querySelector('[data-aksrt-withdraw-history-modal]');
function initWithdrawHistory(scope) {
var modal = firstIn(scope, '[data-aksrt-withdraw-history-modal]');
if (!modal || modal.dataset.aksrtWithdrawHistoryInitialized === '1') return;
modal.dataset.aksrtWithdrawHistoryInitialized = '1';
function open() { modal.hidden = false; document.body.classList.add('uc-modal-open'); }
@@ -785,36 +809,25 @@
refresh: refreshAssetBalances
};
function bootAssets() {
refreshAssetBalances();
initSigninGoto();
initAffiliateRevenue();
initVipShop();
initVipPointsExchange();
initCardPass();
initBalanceCharge();
initTransfer();
initPointsExchange();
initWithdraw();
initWithdrawHistory();
initAssetTabs();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', bootAssets);
} else {
bootAssets();
function bootAssets(root, reason) {
if (!balancesRefreshed && reason === 'init') {
balancesRefreshed = true;
refreshAssetBalances();
}
initSigninGoto(root);
initAffiliateRevenue(root);
initVipShop(root);
initVipPointsExchange(root);
initCardPass(root);
initBalanceCharge(root);
initTransfer(root);
initPointsExchange(root);
initWithdraw(root);
initWithdrawHistory(root);
initAssetTabs(root);
}
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
window.AksrtFrontend.register('credits', function () {
initSigninGoto();
initBalanceCharge();
initTransfer();
initPointsExchange();
initWithdraw();
initWithdrawHistory();
initAssetTabs();
});
window.AksrtFrontend.register('credits', bootAssets);
}
})();