-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
66 lines (53 loc) · 1.87 KB
/
main.js
File metadata and controls
66 lines (53 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { createApp } from 'vue';
import App from './App.vue';
import '@/registerServiceWorker';
import { createRouter, createWebHashHistory } from 'vue-router';
const Cookie = () => import('./Display interface/Cookie.vue');
const MainView = () => import('./Display interface/MainView.vue');
const Login = () => import('./Display interface/Login.vue');
const routes = [
{ path: "/", redirect: "/login" },
{ path: "/login", component: Login, meta: { title: "Login" } },
{ path: "/main", component: MainView, meta: { title: "Chatbot" } },
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
// Authentication check
router.beforeEach((to, from, next) => {
const isAuthenticated = localStorage.getItem('sessionID');
if (to.path !== '/login' && !isAuthenticated) {
next('/login');
} else if (to.path === '/login' && isAuthenticated) {
next('/main');
} else {
next();
}
});
// Page title update
router.afterEach((to) => {
document.title = to.meta.title || "Default title";
});
// Detect if it is a mobile device
function isMobileDevice() {
return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
}
// Attempts to lock screen orientation, performed on mobile only
function lockOrientation() {
if (!isMobileDevice()) return; // Mobile only
if (screen.orientation && screen.orientation.lock) {
screen.orientation.lock("portrait").catch(err => {
console.warn("Screen orientation lock failed:", err);
});
}
}
// Vue mounts and then tries to lock the orientation
document.addEventListener("DOMContentLoaded", lockOrientation);
document.addEventListener("fullscreenchange", lockOrientation);
const app = createApp(App);
app.use(router);
app.mount("#app");
// Try locking again (make sure it takes effect after Vue is mounted)
lockOrientation();
export default router;