mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 路由声明重构,添加composables,BaseLayout进行中,文件夹规范
This commit is contained in:
@ -1,23 +1,5 @@
|
||||
import useAppTitle from './useAppTitle';
|
||||
import useContext from './useContext';
|
||||
import useRouterChange from './useRouterChange';
|
||||
import useRouteParam from './useRouteParam';
|
||||
import useRouteQuery from './useRouteQuery';
|
||||
import useRouteProps from './useRouteProps';
|
||||
import useBoolean from './useBoolean';
|
||||
import useLoading from './useLoading';
|
||||
import useScrollBehavior from './useScrollBehavior';
|
||||
import useIsMobile from './useIsMobile';
|
||||
|
||||
export {
|
||||
useAppTitle,
|
||||
useContext,
|
||||
useRouterChange,
|
||||
useRouteParam,
|
||||
useRouteQuery,
|
||||
useRouteProps,
|
||||
useBoolean,
|
||||
useLoading,
|
||||
useScrollBehavior,
|
||||
useIsMobile
|
||||
};
|
||||
export { useContext, useBoolean, useLoading };
|
||||
|
@ -1,6 +0,0 @@
|
||||
/** 项目名称 */
|
||||
export default function useAppTitle() {
|
||||
const title = import.meta.env.VITE_APP_TITLE as string;
|
||||
|
||||
return title;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import { useBreakpoints, breakpointsTailwind } from '@vueuse/core';
|
||||
|
||||
/** 是否是移动端 */
|
||||
export default function useIsMobile() {
|
||||
const breakpoints = useBreakpoints(breakpointsTailwind);
|
||||
const isMobile = breakpoints.smaller('lg');
|
||||
|
||||
return {
|
||||
isMobile
|
||||
};
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
// import { computed } from 'vue';
|
||||
// import { useRoute } from 'vue-router';
|
||||
// import { ROUTE_NAME_MAP } from '@/utils';
|
||||
|
||||
export default function useRouteParam() {
|
||||
// const route = useRoute();
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
export default function useRouteProps() {
|
||||
const route = useRoute();
|
||||
const props = computed(() => {
|
||||
/** 路由名称 */
|
||||
const name = route.name as string;
|
||||
/** 混存页面 */
|
||||
const keepAlive = Boolean(route.meta?.keepAlive);
|
||||
/** 视高100% */
|
||||
const fullPage = Boolean(route.meta?.fullPage);
|
||||
|
||||
return {
|
||||
name,
|
||||
keepAlive,
|
||||
fullPage
|
||||
};
|
||||
});
|
||||
|
||||
return props;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { EnumRoutePath } from '@/enum';
|
||||
import { ROUTE_NAME_MAP } from '@/utils';
|
||||
|
||||
export default function useRouteQuery() {
|
||||
const route = useRoute();
|
||||
|
||||
/** 登录跳转链接 */
|
||||
const loginRedirectUrl = computed(() => {
|
||||
let url: EnumRoutePath | undefined;
|
||||
if (route.name === ROUTE_NAME_MAP.get('login')) {
|
||||
url = (route.query?.redirectUrl as EnumRoutePath) || '';
|
||||
}
|
||||
return url;
|
||||
});
|
||||
|
||||
return {
|
||||
loginRedirectUrl
|
||||
};
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import type { RouteLocationRaw } from 'vue-router';
|
||||
import { EnumRoutePath } from '@/enum';
|
||||
import { router as globalRouter } from '@/router';
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
|
||||
/**
|
||||
* 重定向地址
|
||||
* - current: 取当前的path作为重定向地址
|
||||
*/
|
||||
type LoginRedirect = 'current' | EnumRoutePath;
|
||||
|
||||
/**
|
||||
* 路由跳转
|
||||
* @param inSetup - 是否在vue页面/组件的setup里面调用
|
||||
*/
|
||||
export default function useRouterChange(inSetup: boolean = true) {
|
||||
const router = inSetup ? useRouter() : globalRouter;
|
||||
const route = inSetup ? useRoute() : null;
|
||||
|
||||
/** 跳转首页 */
|
||||
function toHome() {
|
||||
router.push('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转登录页面(通过vue路由)
|
||||
* @param module - 展示的登录模块
|
||||
* @param redirectUrl - 重定向地址
|
||||
*/
|
||||
function toLogin(module: LoginModuleType = 'pwd-login', redirectUrl: LoginRedirect = 'current') {
|
||||
const routeLocation: RouteLocationRaw = {
|
||||
path: EnumRoutePath.login,
|
||||
query: { module }
|
||||
};
|
||||
if (redirectUrl) {
|
||||
let url = redirectUrl;
|
||||
if (redirectUrl === 'current') {
|
||||
url = router.currentRoute.value.fullPath as EnumRoutePath;
|
||||
}
|
||||
routeLocation.query!.redirectUrl = url;
|
||||
}
|
||||
router.push(routeLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登陆页跳转登陆页
|
||||
* @param module - 展示的登录模块
|
||||
* @param query - 查询参数
|
||||
*/
|
||||
function toCurrentLogin(module: LoginModuleType) {
|
||||
if (route) {
|
||||
const { query } = route;
|
||||
router.push({ path: EnumRoutePath.login, query: { ...query, module } });
|
||||
}
|
||||
}
|
||||
|
||||
/** 登录后跳转重定向的地址 */
|
||||
function toLoginRedirectUrl(path: EnumRoutePath) {
|
||||
router.push(path);
|
||||
}
|
||||
|
||||
return {
|
||||
toHome,
|
||||
toLogin,
|
||||
toCurrentLogin,
|
||||
toLoginRedirectUrl
|
||||
};
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
/** 滚动行为 */
|
||||
export default function useScrollBehavior() {
|
||||
const scrollbar = ref<HTMLElement | null>(null);
|
||||
|
||||
/** 重置滚动条行为 */
|
||||
function resetScrollBehavior() {
|
||||
scrollbar.value?.scrollTo({ left: 0, top: 0 });
|
||||
}
|
||||
|
||||
return {
|
||||
scrollbar,
|
||||
resetScrollBehavior
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user