refactor(projects): 路由声明重构,添加composables,BaseLayout进行中,文件夹规范

This commit is contained in:
Soybean
2021-11-19 01:33:36 +08:00
parent 1c5fdca596
commit 1e84d13d54
75 changed files with 668 additions and 565 deletions

View File

@ -0,0 +1,63 @@
import { computed, watch } from 'vue';
import { useRoute } from 'vue-router';
import { routeName } from '@/router';
import type { RouteKey } from '@/interface';
/**
* 路由属性
* @description - 必须要在setup里面调用
*/
export 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;
}
/**
* 路由查询参数
* @description - 必须要在setup里面调用
*/
export function useRouteQuery() {
const route = useRoute();
/** 登录跳转链接 */
const loginRedirectUrl = computed(() => {
let url: string | undefined;
if (route.name === routeName('login')) {
url = (route.query?.redirectUrl as string) || '';
}
return url;
});
return {
loginRedirectUrl
};
}
/**
* 路由名称变化后的回调
* @param callback
*/
export function routeNameWatcher(callback: (name: RouteKey) => void) {
const route = useRoute();
watch(
() => route.name,
newValue => {
callback(newValue as RouteKey);
}
);
}