2021-09-11 02:34:36 +08:00
|
|
|
import { useRouter } from 'vue-router';
|
2021-09-14 01:31:29 +08:00
|
|
|
import { EnumRoutePath } from '@/enum';
|
2021-09-11 02:34:36 +08:00
|
|
|
import { RouteNameMap } from '@/router';
|
|
|
|
import type { LoginModuleType } from '@/interface';
|
|
|
|
|
|
|
|
export default function useRouterChange() {
|
|
|
|
const router = useRouter();
|
|
|
|
|
2021-09-14 01:31:29 +08:00
|
|
|
/** 跳转首页 */
|
|
|
|
function toHome() {
|
|
|
|
router.push('/');
|
|
|
|
}
|
|
|
|
|
2021-09-11 02:34:36 +08:00
|
|
|
/**
|
|
|
|
* 跳转登录页面(通过vue路由)
|
|
|
|
* @param module - 展示的登录模块
|
|
|
|
* @param redirectUrl - 登录后重定向的页面路径
|
|
|
|
*/
|
|
|
|
function toLogin(module: LoginModuleType = 'pwd-login', redirectUrl?: string) {
|
|
|
|
router.push({
|
|
|
|
name: RouteNameMap.get('login'),
|
|
|
|
params: {
|
|
|
|
module
|
|
|
|
},
|
|
|
|
query: {
|
|
|
|
redirectUrl
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 跳转登录页面(通过window.location)
|
|
|
|
* @param module - 展示的登录模块
|
|
|
|
* @param redirectUrl - 登录后重定向的页面路径
|
|
|
|
*/
|
|
|
|
function toLoginByLocation(module: LoginModuleType = 'pwd-login', redirectUrl?: string) {
|
2021-09-14 01:31:29 +08:00
|
|
|
let href = `${window.location.origin + EnumRoutePath.login}/${module}`;
|
2021-09-11 02:34:36 +08:00
|
|
|
if (redirectUrl) {
|
|
|
|
href += redirectUrl;
|
|
|
|
}
|
|
|
|
window.location.href = href;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2021-09-14 01:31:29 +08:00
|
|
|
toHome,
|
2021-09-11 02:34:36 +08:00
|
|
|
toLogin,
|
|
|
|
toLoginByLocation
|
|
|
|
};
|
|
|
|
}
|