This commit is contained in:
2023-06-05 21:02:25 +08:00
parent bdbda8b68e
commit d778ceab61
41 changed files with 1259 additions and 94 deletions

View File

@@ -0,0 +1,40 @@
import NProgress from "nprogress" // progress bar
import { useUserStore } from "@/store"
// userInfo守卫
export default function setupUserLoginInfoGuard(router) {
router.beforeEach(async (to, from, next) => {
NProgress.start()
const userStore = useUserStore()
if (userStore.isLogin()) {
if (userStore.role) {
next()
} else {
try {
await userStore.info()
next()
} catch (error) {
await userStore.logout()
next({
name: "login",
query: {
redirect: to.name,
...to.query
}
})
}
}
} else {
if (to.name === "login") {
next()
return
}
next({
name: "login",
query: {
redirect: to.name,
...to.query
}
})
}
})
}