ebike-plus-ui/src/store/modules/route-list.ts

89 lines
2.8 KiB
TypeScript
Raw Normal View History

2024-04-11 00:15:57 +08:00
import { defineStore } from "pinia";
/**
*
2024-04-13 15:54:07 +08:00
* @methods setRouteTree
* @methods setRoutesList
2024-04-18 00:24:07 +08:00
* @methods setRouteNames
2024-04-21 00:26:49 +08:00
* @methods setTabs tabs标签页
* @methods setCurrentRoute
* @methods removeTabsList tabs页的指定路由
2024-04-11 00:15:57 +08:00
*/
export const useRoutesListStore = defineStore("route-list", {
2024-04-11 00:15:57 +08:00
state: (): any => ({
2024-04-20 16:54:12 +08:00
routeTree: [], // 有访问权限的路由树
routeList: [], // 有访问权限的一维路由数组
2024-04-21 00:26:49 +08:00
cacheRoutes: [], // 所有可缓存路由的路由名
2024-04-20 16:54:12 +08:00
tabsList: [], // 标签页数据
2024-04-18 13:01:43 +08:00
currentRoute: {} // 当前路由
2024-04-11 00:15:57 +08:00
}),
actions: {
2024-04-21 00:26:49 +08:00
/**
* 访
* @param {Array} data
*/
2024-04-21 16:08:59 +08:00
async setRouteTree(data: Menu.MenuOptions) {
2024-04-12 00:31:21 +08:00
this.routeTree = data;
},
2024-04-20 16:54:12 +08:00
/**
* 访
* @param {Array} data
*/
2024-04-13 15:54:07 +08:00
setRouteList(data: any) {
this.routeList = data;
2024-04-11 00:15:57 +08:00
},
2024-04-20 16:54:12 +08:00
/**
2024-04-21 17:09:20 +08:00
*
2024-04-21 16:08:59 +08:00
* @param {string} name
2024-04-20 16:54:12 +08:00
*/
2024-04-21 16:08:59 +08:00
setRouteNames(name: string) {
let state = this.cacheRoutes.some((item: string) => item === name);
if (state) return;
this.cacheRoutes.push(name);
2024-04-18 00:24:07 +08:00
},
2024-04-20 16:54:12 +08:00
/**
* tabs标签页
* @param {object} data tabs路由
*/
setTabs(data: Menu.MenuOptions) {
// 当前路由在tags中是否存在不存在则缓存
let isExist = this.tabsList.some((item: Menu.MenuOptions) => item.name === data.name);
if (isExist) return;
this.tabsList.push(data);
2024-04-18 13:01:43 +08:00
},
2024-04-20 16:54:12 +08:00
/**
*
* @param {object} data
*/
setCurrentRoute(data: Menu.MenuOptions) {
if (this.currentRoute.name && data.name === this.currentRoute.name) return;
2024-04-18 13:01:43 +08:00
this.currentRoute = data;
2024-04-20 16:54:12 +08:00
},
/**
* tabs页的指定路由
* @param {string} key name
*/
removeTabsList(key: string) {
const index = this.tabsList.findIndex((item: Menu.MenuOptions) => item.name === key);
if (index === -1) return;
this.tabsList.splice(index, 1);
2024-04-21 16:08:59 +08:00
},
/**
2024-04-22 00:14:26 +08:00
*
2024-04-21 16:08:59 +08:00
* @param {string} key
*/
2024-04-22 00:14:26 +08:00
removeRouteName(key: string) {
2024-04-21 16:08:59 +08:00
const index = this.cacheRoutes.findIndex((item: string) => item === key);
if (index === -1) return;
this.cacheRoutes.splice(index, 1);
2024-04-22 00:14:26 +08:00
},
/**
*
* @param {Array} list
*/
removeRouteNames(list: Array<string>) {
this.cacheRoutes = this.cacheRoutes.filter((item: string) => !list.includes(item));
2024-04-11 00:15:57 +08:00
}
}
});