|
@@ -1,12 +1,15 @@
|
|
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
|
|
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
|
|
import Login from "@/features/login/Login.vue";
|
|
import Login from "@/features/login/Login.vue";
|
|
import Layout from "@/components/Layout.vue";
|
|
import Layout from "@/components/Layout.vue";
|
|
|
|
+import { getToken } from "@/auth/auth";
|
|
|
|
+import { isNil } from "lodash-es";
|
|
|
|
+import { useMainStore } from "@/store";
|
|
|
|
|
|
const routes = [
|
|
const routes = [
|
|
- { path: "/", component: Login },
|
|
|
|
- { path: "/Login", component: Login, name: "Login" },
|
|
|
|
|
|
+ { path: "/", redirect: "/login" },
|
|
|
|
+ { path: "/login", component: Login, name: "Login" },
|
|
{
|
|
{
|
|
- path: "/admin/",
|
|
|
|
|
|
+ path: "/",
|
|
children: [
|
|
children: [
|
|
{
|
|
{
|
|
path: "rootOrg",
|
|
path: "rootOrg",
|
|
@@ -31,4 +34,27 @@ const router = createRouter({
|
|
routes, // short for `routes: routes`
|
|
routes, // short for `routes: routes`
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+export async function routeLogout(params: {
|
|
|
|
+ cause?: string;
|
|
|
|
+ redirectTo: string;
|
|
|
|
+}) {
|
|
|
|
+ const store = useMainStore();
|
|
|
|
+ return router.push(
|
|
|
|
+ `/login?rootOrgId=${
|
|
|
|
+ store.userInfo.rootOrgId === "-1" ? 1 : store.userInfo.rootOrgId
|
|
|
|
+ }&redirectTo=${encodeURI(params.redirectTo)}`
|
|
|
|
+ );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+router.beforeEach((to, from, next) => {
|
|
|
|
+ const token = getToken();
|
|
|
|
+ if (isNil(token) && to.path.includes("/login") === false) {
|
|
|
|
+ routeLogout({ cause: "missingToken", redirectTo: to.fullPath }).then(() =>
|
|
|
|
+ next(false)
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ next();
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
export default router;
|
|
export default router;
|