feat(frontend): add debugMode global variable to store debug mode state

This commit is contained in:
2026-09-10 19:36:29 +08:00
parent bc7eb9dfdd
commit 93d5ac2707
3 changed files with 33 additions and 0 deletions
+8
View File
@@ -2,10 +2,18 @@ import { createApp } from 'vue';
import App from './App.vue';
import router from './router/index.js';
import { initTheme } from './utils/theme.js';
import { isLoggedIn } from './utils/auth.js';
import { loadDebugMode } from './utils/runtime.js';
import '@fortawesome/fontawesome-free/css/all.min.css';
import './styles/theme.css';
import './styles/ui.css';
initTheme();
// A persisted session can fetch the runtime flags right away; a fresh visitor
// has no token yet and picks them up after signing in.
if (isLoggedIn()) {
loadDebugMode();
}
createApp(App).use(router).mount('#app');
+22
View File
@@ -0,0 +1,22 @@
import { ref } from 'vue';
import { settingsApi } from '../api/index.js';
// Runtime flags mirrored from the backend config so any view can read them
// without refetching the whole config.
// debugMode mirrors system.debugMode from the global config (config.json).
export const debugMode = ref(false);
// loadDebugMode reads the global config and mirrors system.debugMode into the
// `debugMode` global. The endpoint needs an admin session, so callers only
// invoke it once logged in; a failed request keeps the current value.
export async function loadDebugMode() {
try {
const res = await settingsApi.get('global');
const config = (res && res.data && res.data.config) || {};
const system = config.system || {};
debugMode.value = !!system.debugMode;
} catch {
// Non-fatal: the flag simply keeps its current value.
}
}
+3
View File
@@ -3,6 +3,7 @@ import { reactive, ref, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { authApi } from '../api/index.js';
import { setSession } from '../utils/auth.js';
import { loadDebugMode } from '../utils/runtime.js';
import { toast } from '../utils/toast.js';
const router = useRouter();
@@ -23,6 +24,8 @@ function goTo(target) {
function afterLogin(token, user) {
setSession(token, user);
// The settings endpoint requires the token we just stored.
loadDebugMode();
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/overview';
router.push(redirect);
}