153 lines
3.4 KiB
JavaScript
153 lines
3.4 KiB
JavaScript
import {createRouter, createWebHistory} from "vue-router";
|
|
import Main from "@pages/Main/index.vue"
|
|
import Auth from "@pages/Auth/index.vue"
|
|
import Communication from "@pages/Communication/index.vue"
|
|
import LastPacksNum from "@pages/LastPacksNum/index.vue"
|
|
import Fuel from "@pages/Fuel/index.vue"
|
|
import Cron from "@pages/Cron/index.vue"
|
|
import ICCID from "@pages/ICCID/index.vue"
|
|
import Devices from "@pages/Devices/index.vue"
|
|
import FreePacks from "@pages/FreePacks/index.vue"
|
|
import Packs from "@pages/Packs/index.vue"
|
|
import FileViewer from "@pages/FileViewer/index.vue"
|
|
import NotFound from "@pages/404/index.vue"
|
|
import Diap from "@admin_pages/Diap/index.vue"
|
|
import News from "@admin_pages/News/index.vue"
|
|
import Machines from "@pages/Main/Machines/Machines.vue"
|
|
import FinderPacks from "@pages/Main/FinderPacks/FinderPacks.vue"
|
|
import AddUsers from "@pages/Main/AddUsers/AddUsers.vue"
|
|
import Services from "@admin_pages/Services/Services.vue"
|
|
import ServiceManage from "@admin_pages/ServiceManage/index.vue"
|
|
import {get} from "@store/modules/apiHelpers"
|
|
import {cond, T} from 'ramda'
|
|
|
|
|
|
const routes = [
|
|
{
|
|
path: "/",
|
|
name: "main",
|
|
component: Main,
|
|
children: [
|
|
{
|
|
path: "/",
|
|
name: "machines",
|
|
component: Machines
|
|
},
|
|
{
|
|
path: "finder_packs",
|
|
name: "finder_packs",
|
|
component: FinderPacks
|
|
},
|
|
{
|
|
path: "add_users",
|
|
name: "add_users",
|
|
component: AddUsers
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: "/html/last_packs",
|
|
name: "last_packs",
|
|
component: import("@pages/LastPacks/index.vue")
|
|
},
|
|
{
|
|
path: "/html/controll_com_service",
|
|
name: "communication",
|
|
component: import("@pages/Communication/index.vue")
|
|
},
|
|
{
|
|
path: "/html/last_packs_by_pack",
|
|
name: "last_packs_by_pack",
|
|
component: LastPacksNum
|
|
},
|
|
{
|
|
path: "/html/live_fuel",
|
|
name: "fuel",
|
|
component: Fuel
|
|
},
|
|
{
|
|
path: "/html/cron",
|
|
name: "cron",
|
|
component: Cron
|
|
},
|
|
{
|
|
path: "/html/fetch_iccid",
|
|
name: "iccid",
|
|
component: ICCID
|
|
},
|
|
{
|
|
path: "/html/fetch_askr_devices",
|
|
name: "devices",
|
|
component: Devices
|
|
},
|
|
{
|
|
path: "/html/packs/:pack",
|
|
name: "packs",
|
|
component: Packs
|
|
},
|
|
{
|
|
path: "/html/free_packs",
|
|
name: "free_packs",
|
|
component: FreePacks
|
|
},
|
|
{
|
|
path: "/html/file_viewer/:mode",
|
|
name: "file_viewer",
|
|
component: FileViewer
|
|
},
|
|
{
|
|
path: "/admin_panel/diap",
|
|
name: "diap",
|
|
component: Diap
|
|
},
|
|
{
|
|
path: "/admin_panel/services",
|
|
name: "services",
|
|
component: Services
|
|
},
|
|
{
|
|
path: "/users/log_out",
|
|
name: "auth",
|
|
component: Auth
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
name: '404',
|
|
component: NotFound
|
|
},
|
|
];
|
|
|
|
const routerHistory = createWebHistory();
|
|
|
|
const router = createRouter({
|
|
history: routerHistory,
|
|
routes
|
|
});
|
|
|
|
const logout = (from, next) => {
|
|
localStorage.removeItem("token")
|
|
sessionStorage.setItem("pathname", from.fullPath)
|
|
next()
|
|
}
|
|
|
|
const auth_check = async () => {
|
|
return await get("/api/auth/loginStatus", ({data}) => {
|
|
return data
|
|
})
|
|
}
|
|
|
|
// router.beforeEach(async (to, from, next) => {
|
|
// const status = await auth_check()
|
|
|
|
// return cond([
|
|
// [() => to.name === "auth" && from.name === "auth", () => next()],
|
|
// [() => to.name === "auth", () => logout(from, () => next())],
|
|
// [() => !status, () => logout(from, () => next({name: "auth"}))],
|
|
// [T, () => next()],
|
|
// ])()
|
|
// })
|
|
|
|
|
|
export {routes};
|
|
export default router;
|