修复报错页面
This commit is contained in:
@@ -63,10 +63,23 @@ function emptyState(title, description, route, action) {
|
||||
}
|
||||
|
||||
function renderError(error) {
|
||||
app.innerHTML = `<section class="fatal-error"><span>!</span><h1>页面暂时无法加载</h1><p>${h(error.message)}</p><button class="solid-button" data-action="retry">重新加载</button></section>`;
|
||||
if (error?.status === 401) return requireLogin();
|
||||
console.error('Page failed to render', error);
|
||||
const message = error?.status ? error.message : '请求未能完成,请稍后重试或返回首页。';
|
||||
app.innerHTML = `<section class="fatal-error"><span>!</span><h1>页面暂时无法加载</h1><p>${h(message)}</p><div class="fatal-error-actions"><button class="ghost-button" data-route="home">返回首页</button><button class="solid-button" data-action="retry">重试</button></div></section>`;
|
||||
}
|
||||
|
||||
const baseViewContext = { state, app, h, formatDate, dateRange, badge, money, passPolicyText, statusLabels, icons, api, renderError, emptyState };
|
||||
function requireLogin() {
|
||||
state.user = null;
|
||||
state.profile = null;
|
||||
state.permissions = [];
|
||||
state.scopeLabel = '';
|
||||
state.pageData = null;
|
||||
state.authNotice = '登录状态已失效,请重新登录。';
|
||||
navigate('login');
|
||||
}
|
||||
|
||||
const baseViewContext = { state, app, h, formatDate, dateRange, badge, money, passPolicyText, statusLabels, icons, api, renderError, requireLogin, emptyState };
|
||||
const { brand, renderHome, renderNoticeCenter, renderAuth } = createPublicViews(baseViewContext);
|
||||
const { adminNavForUser, portalShell, loadingPanel, renderCandidate, accountSecurity } = createCandidateViews({ ...baseViewContext, brand });
|
||||
const { renderAdmin, workflowStepEditor } = createAdminViews({ ...baseViewContext, brand, portalShell, loadingPanel, adminNavForUser, accountSecurity });
|
||||
@@ -82,6 +95,7 @@ async function renderRoute() {
|
||||
window.scrollTo({ top: 0, behavior: 'instant' });
|
||||
const route = location.hash.slice(1) || 'home';
|
||||
const [section, page = 'dashboard'] = route.split('/');
|
||||
if (section !== 'login') state.authNotice = '';
|
||||
if (section === 'home') renderHome();
|
||||
else if (section === 'notices' || section === 'announcements') { state.publicAnnouncements = await api('/api/public/announcements'); renderNoticeCenter(state.publicAnnouncements); }
|
||||
else if (section === 'notice') { state.publicAnnouncements = await api('/api/public/announcements'); renderNoticeCenter(state.publicAnnouncements, page); }
|
||||
@@ -240,6 +254,7 @@ async function refreshSession() {
|
||||
|
||||
async function finishLogin(data) {
|
||||
state.user = data.user;
|
||||
state.authNotice = '';
|
||||
await refreshSession();
|
||||
closeModal();
|
||||
toast(data.usedRecoveryCode ? '已使用恢复码登录' : '登录成功', data.usedRecoveryCode ? '该恢复码已失效,请检查剩余恢复码' : `欢迎,${data.user.displayName}`);
|
||||
|
||||
Reference in New Issue
Block a user