修复报错页面

This commit is contained in:
biss committed 2026-07-21 17:08:03 +08:00
1 parent fe5fcc9dc2
commit 5477a261f8
10 files changed
+91 -9

No files matched your search

+17 -2
View File
@@ -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}`);
+1 -1
View File
@@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"start": "node server.mjs",
"test": "node tests/cache.test.mjs && node tests/admission.test.mjs && node tests/system.test.mjs",
"test": "node tests/client-auth.test.mjs && node tests/cache.test.mjs && node tests/admission.test.mjs && node tests/system.test.mjs",
"test:cache": "node tests/cache.test.mjs",
"reset-db": "node scripts/reset-dev-database.mjs",
"seed-test-data": "node scripts/import-test-data.mjs",
+2 -1
View File
@@ -21,6 +21,7 @@ export function createAdminViews(context) {
icons,
api,
renderError,
requireLogin,
emptyState,
brand,
portalShell,
@@ -30,7 +31,7 @@ export function createAdminViews(context) {
} = context;
async function renderAdmin(page) {
if (state.user?.role !== 'admin') return navigate('login');
if (state.user?.role !== 'admin') return requireLogin();
app.classList.add('admin-readable');
const meta = {
dashboard: ['考务工作台', '掌握当前报名、审核和发布任务。'], candidates: ['考生资料审核', '核验考生实名、学籍与联系信息。'],
Loaded 3 of 10 files, more files were not shown because too many files have changed in this diff. Show more