mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 16:46:19 +08:00
36 lines
884 B
TypeScript
36 lines
884 B
TypeScript
import { toRaw } from 'vue';
|
|
import router from '/@/router';
|
|
import { AppRouteRecordRaw } from '/@/router/types';
|
|
import { TabItem, tabStore } from '/@/store/modules/tab';
|
|
|
|
export function initAffixTabs() {
|
|
/**
|
|
* @description: Filter all fixed routes
|
|
*/
|
|
function filterAffixTabs(routes: AppRouteRecordRaw[]) {
|
|
const tabs: TabItem[] = [];
|
|
routes &&
|
|
routes.forEach((route) => {
|
|
if (route.meta && route.meta.affix) {
|
|
tabs.push(toRaw(route) as TabItem);
|
|
}
|
|
});
|
|
return tabs;
|
|
}
|
|
|
|
/**
|
|
* @description: Set fixed tabs
|
|
*/
|
|
function addAffixTabs(): void {
|
|
const affixTabs = filterAffixTabs((router.getRoutes() as unknown) as AppRouteRecordRaw[]);
|
|
for (const tab of affixTabs) {
|
|
tabStore.commitAddTab(tab);
|
|
}
|
|
}
|
|
let isAddAffix = false;
|
|
if (!isAddAffix) {
|
|
addAffixTabs();
|
|
isAddAffix = true;
|
|
}
|
|
}
|