ebike-plus-ui/src/hooks/useRoutingMethod.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-20 16:54:12 +08:00
import pinia from "@/store/index";
import { storeToRefs } from "pinia";
import { useRoutesConfigStore } from "@/store/modules/route-config";
2024-04-20 16:54:12 +08:00
/**
* hooks
* @returns
*/
export const useRoutingMethod = () => {
/**
*
* @param {string} key name
* @returns undefined则表示未找到
*/
const findLinearArray = (key: string) => {
const routerStore = useRoutesConfigStore(pinia);
2024-04-20 16:54:12 +08:00
const { routeList } = storeToRefs(routerStore);
return routeList.value.find((item: Menu.MenuOptions) => item.name == key);
};
/**
* tabs路由中查找路由
* @param {string} key name
* @returns undefined则表示未找到
*/
const findTagsList = (key: string) => {
const routerStore = useRoutesConfigStore(pinia);
2024-04-20 16:54:12 +08:00
const { tabsList } = storeToRefs(routerStore);
return tabsList.value.find((item: Menu.MenuOptions) => item.name == key);
};
/**
* url跳转
* @param {any} route
*/
const openExternalLinks = (route: any) => {
// 处理外链跳转
if (route.meta.link && !route.meta.iframe) {
window.open(route.meta.link as string, "_blank");
}
};
2024-04-20 16:54:12 +08:00
return {
findLinearArray,
findTagsList,
openExternalLinks
2024-04-20 16:54:12 +08:00
};
};