mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
fix(projects): 修复登录的重定向地址
This commit is contained in:
@ -2,6 +2,7 @@ import useAppTitle from './useAppTitle';
|
||||
import useCreateContext from './useCreateContext';
|
||||
import useRouterChange from './useRouterChange';
|
||||
import useRouteParam from './useRouteParam';
|
||||
import useRouteQuery from './useRouteQuery';
|
||||
import useScrollBehavior from './useScrollBehavior';
|
||||
|
||||
export { useAppTitle, useCreateContext, useRouterChange, useRouteParam, useScrollBehavior };
|
||||
export { useAppTitle, useCreateContext, useRouterChange, useRouteParam, useRouteQuery, useScrollBehavior };
|
||||
|
@ -1,20 +1,7 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { RouteNameMap } from '@/router';
|
||||
// import { computed } from 'vue';
|
||||
// import { useRoute } from 'vue-router';
|
||||
// import { RouteNameMap } from '@/router';
|
||||
|
||||
export default function useRouteParam() {
|
||||
const route = useRoute();
|
||||
|
||||
/** 登录跳转链接 */
|
||||
const loginRedirectUrl = computed(() => {
|
||||
let url = '';
|
||||
if (route.name === RouteNameMap.get('login')) {
|
||||
url = (route.params?.redirectUrl as string) ?? '';
|
||||
}
|
||||
return url;
|
||||
});
|
||||
|
||||
return {
|
||||
loginRedirectUrl
|
||||
};
|
||||
// const route = useRoute();
|
||||
}
|
||||
|
20
src/hooks/common/useRouteQuery.ts
Normal file
20
src/hooks/common/useRouteQuery.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { RouteNameMap } from '@/router';
|
||||
|
||||
export default function useRouteQuery() {
|
||||
const route = useRoute();
|
||||
|
||||
/** 登录跳转链接 */
|
||||
const loginRedirectUrl = computed(() => {
|
||||
let url = '';
|
||||
if (route.name === RouteNameMap.get('login')) {
|
||||
url = (route.query?.redirectUrl as string) ?? '';
|
||||
}
|
||||
return url;
|
||||
});
|
||||
|
||||
return {
|
||||
loginRedirectUrl
|
||||
};
|
||||
}
|
@ -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