mirror of https://github.com/halo-dev/halo
feat: support for configuring the redirection location after login for roles (#4918)
#### What type of PR is this? /area console /kind feature /milestone 2.11.x #### What this PR does / why we need it: 支持为自定义的角色配置登录之后默认跳转位置。 #### Special notes for your reviewer: 1. 创建一个新的角色,设置跳转位置。 2. 为一个用户赋予这个角色。 3. 测试登录之后是否正常跳转到设置的位置。 #### Does this PR introduce a user-facing change? ```release-note 支持为自定义的角色配置登录之后默认跳转位置。 ```pull/4878/head^2
parent
927398b6bd
commit
82a6ba6d90
|
@ -154,6 +154,15 @@ const handleResetForm = () => {
|
|||
type="text"
|
||||
validation="required|length:0,50"
|
||||
></FormKit>
|
||||
<FormKit
|
||||
v-model="
|
||||
formState.metadata.annotations[
|
||||
rbacAnnotations.REDIRECT_ON_LOGIN
|
||||
]
|
||||
"
|
||||
type="text"
|
||||
label="登录之后默认跳转位置"
|
||||
></FormKit>
|
||||
</FormKit>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { rbacAnnotations } from "@/constants/annotations";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import type { Router } from "vue-router";
|
||||
|
||||
|
@ -29,12 +30,26 @@ export function setupAuthCheckGuard(router: Router) {
|
|||
redirect_uri: to.query.redirect_uri,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
next({
|
||||
name: "Dashboard",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const roleHasRedirectOnLogin = userStore.currentRoles?.find(
|
||||
(role) =>
|
||||
role.metadata.annotations?.[rbacAnnotations.REDIRECT_ON_LOGIN]
|
||||
);
|
||||
|
||||
if (roleHasRedirectOnLogin) {
|
||||
window.location.href =
|
||||
roleHasRedirectOnLogin.metadata.annotations?.[
|
||||
rbacAnnotations.REDIRECT_ON_LOGIN
|
||||
] || "/";
|
||||
return;
|
||||
}
|
||||
|
||||
next({
|
||||
name: "Dashboard",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ export enum rbacAnnotations {
|
|||
DEPENDENCIES = "rbac.authorization.halo.run/dependencies",
|
||||
AVATAR_ATTACHMENT_NAME = "halo.run/avatar-attachment-name",
|
||||
LAST_AVATAR_ATTACHMENT_NAME = "halo.run/last-avatar-attachment-name",
|
||||
REDIRECT_ON_LOGIN = "rbac.authorization.halo.run/redirect-on-login",
|
||||
}
|
||||
|
||||
// content
|
||||
|
|
Loading…
Reference in New Issue