mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-25 14:20:21 +08:00
fix(projects): 修复登录的重定向地址
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
import { useRouter } from 'vue-router';
|
||||
import { EnumRoutePath } from '@/enum';
|
||||
import { RouteNameMap } from '@/router';
|
||||
import { router as globalRouter, RouteNameMap } from '@/router';
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
|
||||
export default function useRouterChange() {
|
||||
const router = useRouter();
|
||||
interface LoginRedirect {
|
||||
/**
|
||||
* 重定向类型
|
||||
* - current: 取当前的地址作为重定向地址
|
||||
* - custom: 自定义地址作为重定向地址
|
||||
*/
|
||||
type: 'current' | 'custom';
|
||||
/** 自定义地址 */
|
||||
url: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由跳转
|
||||
* @param inSetup - 是否在vue页面/组件的setup里面调用
|
||||
*/
|
||||
export default function useRouterChange(inSetup: boolean = true) {
|
||||
const router = inSetup ? useRouter() : globalRouter;
|
||||
|
||||
/** 跳转首页 */
|
||||
function toHome() {
|
||||
@@ -14,35 +28,19 @@ export default function useRouterChange() {
|
||||
/**
|
||||
* 跳转登录页面(通过vue路由)
|
||||
* @param module - 展示的登录模块
|
||||
* @param redirectUrl - 登录后重定向的页面路径
|
||||
* @param redirect - 登录后重定向相关配置
|
||||
*/
|
||||
function toLogin(module: LoginModuleType = 'pwd-login', redirectUrl?: string) {
|
||||
function toLogin(module: LoginModuleType = 'pwd-login', redirect: LoginRedirect = { type: 'current', url: '' }) {
|
||||
const redirectUrl = redirect.type === 'current' ? window.location.href : redirect.url;
|
||||
router.push({
|
||||
name: RouteNameMap.get('login'),
|
||||
params: {
|
||||
module
|
||||
},
|
||||
query: {
|
||||
redirectUrl
|
||||
}
|
||||
params: { module },
|
||||
query: { redirectUrl }
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 跳转登录页面(通过window.location)
|
||||
* @param module - 展示的登录模块
|
||||
* @param redirectUrl - 登录后重定向的页面路径
|
||||
*/
|
||||
function toLoginByLocation(module: LoginModuleType = 'pwd-login', redirectUrl?: string) {
|
||||
let href = `${window.location.origin + EnumRoutePath.login}/${module}`;
|
||||
if (redirectUrl) {
|
||||
href += redirectUrl;
|
||||
}
|
||||
window.location.href = href;
|
||||
}
|
||||
|
||||
return {
|
||||
toHome,
|
||||
toLogin,
|
||||
toLoginByLocation
|
||||
toLogin
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user