init.sql小bug修复-20260204

This commit is contained in:
Cheng Zhou
2026-02-04 16:17:51 +08:00
parent 737f84bf54
commit 0693f09b1d
4 changed files with 97 additions and 207 deletions
+20 -3
View File
@@ -476,16 +476,33 @@ router.beforeEach(async (to, _from, next) => {
}
}
const token = getToken();
const isAdmin = auth.user?.role === "ADMIN";
if (token && !studyStore.currentStudy) {
await studyStore.ensureDefaultStudy();
if (isAdmin) {
await studyStore.ensureDefaultActiveStudy();
} else {
await studyStore.ensureDefaultStudy();
}
}
if (!to.meta.public && !token) {
next({ path: "/login" });
return;
}
if (isAdmin && (to.path === "/" || to.path === "/workbench")) {
next({ path: studyStore.currentStudy ? "/project/overview" : "/admin/users" });
return;
}
if ((to.path === "/login" || to.path === "/register") && token) {
if (!auth.forceLogin) {
next({ path: studyStore.currentStudy ? "/project/overview" : "/workbench" });
next({
path: isAdmin
? studyStore.currentStudy
? "/project/overview"
: "/admin/users"
: studyStore.currentStudy
? "/project/overview"
: "/workbench",
});
return;
}
}
@@ -502,7 +519,7 @@ router.beforeEach(async (to, _from, next) => {
}
}
if (to.meta.requiresStudy && !studyStore.currentStudy) {
next({ path: "/workbench" });
next({ path: isAdmin ? "/admin/users" : "/workbench" });
return;
}
next();
+17
View File
@@ -63,6 +63,22 @@ export const useStudyStore = defineStore("study", () => {
return null;
};
const ensureDefaultActiveStudy = async () => {
if (currentStudy.value) return currentStudy.value;
try {
const { data } = await fetchStudies();
const items = (data as any).items || [];
const active = items.find((study: Study) => study.status === "ACTIVE" && !study.is_locked);
if (active) {
setCurrentStudy(active as Study);
return active as Study;
}
} catch {
return null;
}
return null;
};
const clearCurrentStudy = () => {
currentStudy.value = null;
currentStudyRole.value = null;
@@ -106,6 +122,7 @@ export const useStudyStore = defineStore("study", () => {
setViewContext,
loadCurrentStudy,
ensureDefaultStudy,
ensureDefaultActiveStudy,
clearCurrentStudy,
};
});
+12 -1
View File
@@ -115,6 +115,7 @@ import { reactive, ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import { ElMessage, type FormInstance, type FormRules } from "element-plus";
import { useAuthStore } from "../store/auth";
import { useStudyStore } from "../store/study";
import { getCachedCredential, setCachedCredential, clearCachedCredential } from "../utils/auth";
import { TEXT, requiredMessage } from "../locales";
@@ -215,7 +216,17 @@ const onSubmit = async () => {
} else {
clearCachedCredential();
}
router.push("/");
if (auth.user?.role === "ADMIN") {
const studyStore = useStudyStore();
await studyStore.ensureDefaultActiveStudy();
if (studyStore.currentStudy) {
router.push("/project/overview");
} else {
router.push("/admin/users");
}
} else {
router.push("/");
}
} catch (error: any) {
const detail = error?.response?.data?.detail || error?.response?.data?.message;
ElMessage.error(detail || TEXT.modules.auth.authFailed);