You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/public/cloud/invoice-detail.js

43 lines
1.4 KiB
JavaScript

const runtimeUrl = new URL('/cloud/invoice-detail-runtime.js', location.origin);
const assetVersion = new URL(import.meta.url).searchParams.get('v');
if (assetVersion) runtimeUrl.searchParams.set('v', assetVersion);
const {
bindInvoiceDetailCleanup,
byId,
hydrateInvoiceDetail,
readInvoiceDetailBootstrap,
refreshInvoiceDetail,
resumeInvoicePolling,
showError,
state,
stopInvoicePoll,
} = await import(runtimeUrl.href);
export function initialize() {
try {
state.view = 'invoice-detail';
bindInvoiceDetailCleanup();
byId('logout-button')?.addEventListener('click', () => location.assign('/user/logout'));
const invoiceId = String(document.body.dataset.invoiceId || '');
if (!/^[1-9]\d*$/.test(invoiceId)) throw new Error('账单编号无效。');
const bootstrap = readInvoiceDetailBootstrap();
hydrateInvoiceDetail(bootstrap, invoiceId);
byId('invoice-detail-refresh')?.addEventListener('click', () => {
void refreshInvoiceDetail(invoiceId);
});
window.addEventListener('pageshow', event => {
if (event.persisted) void refreshInvoiceDetail(invoiceId);
});
document.addEventListener('visibilitychange', () => {
if (document.hidden) stopInvoicePoll();
else resumeInvoicePolling();
});
} catch (error) {
showError('cloud-page-error', error?.message || '账单详情初始化失败,请刷新后重试。');
}
}