fix event record

This commit is contained in:
Timi
2026-08-07 19:39:48 +08:00
parent 16fa5fdd36
commit 45ea8b46aa
9 changed files with 205 additions and 53 deletions
+33 -2
View File
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from "vue-router";
import { createRouter, createWebHistory, type RouteLocationNormalized } from "vue-router";
import RootLayout from "@/layout/RootLayout.vue";
import MainLayout from "@/layout/MainLayout.vue";
import Login from "@/pages/Login.vue";
@@ -9,7 +9,9 @@ import permissionRoutes from "@/router/routes/permissionRoutes";
import registrationRoutes from "@/router/routes/registrationRoutes";
import tabRoutes from "@/router/routes/tabRoutes";
import userRoutes from "@/router/routes/userRoutes";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { useGlobalUIStore } from "@/store/globalUI";
import { gaoRoleCodes } from "@/utils/permission";
import { useUserStore } from "timi-web";
const detailRoutes = [
@@ -80,7 +82,7 @@ const router = createRouter({
]
});
router.beforeEach((to) => {
router.beforeEach(async (to) => {
const userStore = useUserStore();
if (to.path === "/login") {
return userStore.isLogged() ? "/management" : true;
@@ -95,9 +97,38 @@ router.beforeEach((to) => {
};
}
const storeAccessRedirect = await resolveStoreAccessRedirect(to);
if (storeAccessRedirect) {
return storeAccessRedirect;
}
return true;
});
async function resolveStoreAccessRedirect(to: RouteLocationNormalized): Promise<string | undefined> {
const userStore = useUserStore();
if (!userStore.hasRoles(gaoRoleCodes.storeManager) || userStore.hasRoles(gaoRoleCodes.globalManager)) {
return undefined;
}
const storeRouteNameList = ["StoreList", "StoreCreate", "StoreSort", "StoreEdit", "StoreBusinessDayCalendar"];
if (!storeRouteNameList.includes(String(to.name || ""))) {
return undefined;
}
const currentStoreStore = useCurrentStoreStore();
const store = await currentStoreStore.loadLoginStore();
if (!store?.id) {
return "/management";
}
if (to.name === "StoreEdit" || to.name === "StoreBusinessDayCalendar") {
return String(to.params.id || "") === store.id ? undefined : `/management/stores/${store.id}`;
}
return `/management/stores/${store.id}`;
}
router.afterEach((to) => {
const globalUIStore = useGlobalUIStore();
const isDarkMode = globalUIStore.themeMode === "dark";