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

35 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pinia from "@/store/index";
import { storeToRefs } from "pinia";
import { useRoutesListStore } from "@/store/modules/route-list";
/**
* 路由处理hooks内置多种路由处理场景
* @returns 路由方法
*/
export const useRoutingMethod = () => {
/**
* 从一维路由中查找路由
* @param {string} key 路由的name
* @returns 查找到的路由undefined则表示未找到
*/
const findLinearArray = (key: string) => {
const routerStore = useRoutesListStore(pinia);
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 = useRoutesListStore(pinia);
const { tabsList } = storeToRefs(routerStore);
return tabsList.value.find((item: Menu.MenuOptions) => item.name == key);
};
return {
findLinearArray,
findTagsList
};
};