feat(projects): 登录页面实现

This commit is contained in:
Soybean
2021-09-11 02:34:36 +08:00
parent 5c01006306
commit f1e7cf608e
47 changed files with 780 additions and 153 deletions

View File

@ -0,0 +1,5 @@
import useAppTitle from './useAppTitle';
import useCreateContext from './useCreateContext';
import useRouterChange from './useRouterChange';
export { useAppTitle, useCreateContext, useRouterChange };

View File

@ -0,0 +1,6 @@
/** 项目名称 */
export default function useAppTitle() {
const title = import.meta.env.VITE_APP_TITLE as string;
return title;
}

View File

@ -0,0 +1,20 @@
import { provide, inject } from 'vue';
import type { InjectionKey } from 'vue';
/** 创建共享上下文状态 */
export default function useCreateContext<T>(contextName: string = 'context') {
const injectKey: InjectionKey<T> = Symbol(contextName);
function useProvider(shareState: T) {
provide(injectKey, shareState);
}
function useContext() {
return inject(injectKey);
}
return {
useProvider,
useContext
};
}

View File

@ -0,0 +1,42 @@
import { useRouter } from 'vue-router';
import { EnumRoutePaths } from '@/enum';
import { RouteNameMap } from '@/router';
import type { LoginModuleType } from '@/interface';
export default function useRouterChange() {
const router = useRouter();
/**
* 跳转登录页面(通过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) {
let href = `${window.location.origin + EnumRoutePaths.login}/${module}`;
if (redirectUrl) {
href += redirectUrl;
}
window.location.href = href;
}
return {
toLogin,
toLoginByLocation
};
}