mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-07 16:56:23 +08:00
feat(projects): support pinning and unpinning of tabs
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
getTabByRoute,
|
||||
getTabIdByRoute,
|
||||
isTabInTabs,
|
||||
reorderFixedTabs,
|
||||
updateTabByI18nKey,
|
||||
updateTabsByI18nKey
|
||||
} from './shared';
|
||||
@@ -248,6 +249,48 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
||||
await clearTabs(excludes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix tab
|
||||
*
|
||||
* @param tabId
|
||||
*/
|
||||
function fixTab(tabId: string) {
|
||||
const tabIndex = tabs.value.findIndex(t => t.id === tabId);
|
||||
if (tabIndex === -1) return;
|
||||
|
||||
const tab = tabs.value[tabIndex];
|
||||
const fixedCount = getFixedTabIds(tabs.value).length;
|
||||
tab.fixedIndex = fixedCount;
|
||||
|
||||
if (tabIndex !== fixedCount) {
|
||||
tabs.value.splice(tabIndex, 1);
|
||||
tabs.value.splice(fixedCount, 0, tab);
|
||||
}
|
||||
|
||||
reorderFixedTabs(tabs.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unfix tab
|
||||
*
|
||||
* @param tabId
|
||||
*/
|
||||
function unfixTab(tabId: string) {
|
||||
const tabIndex = tabs.value.findIndex(t => t.id === tabId);
|
||||
if (tabIndex === -1) return;
|
||||
|
||||
const tab = tabs.value[tabIndex];
|
||||
tab.fixedIndex = undefined;
|
||||
|
||||
const fixedCount = getFixedTabIds(tabs.value).length;
|
||||
if (tabIndex !== fixedCount) {
|
||||
tabs.value.splice(tabIndex, 1);
|
||||
tabs.value.splice(fixedCount, 0, tab);
|
||||
}
|
||||
|
||||
reorderFixedTabs(tabs.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new label of tab
|
||||
*
|
||||
@@ -328,6 +371,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
||||
clearTabs,
|
||||
clearLeftTabs,
|
||||
clearRightTabs,
|
||||
fixTab,
|
||||
unfixTab,
|
||||
switchRouteByTab,
|
||||
setTabLabel,
|
||||
resetTabLabel,
|
||||
|
||||
@@ -198,6 +198,18 @@ export function getFixedTabIds(tabs: App.Global.Tab[]) {
|
||||
return fixedTabs.map(tab => tab.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder fixed tabs fixedIndex
|
||||
*
|
||||
* @param tabs
|
||||
*/
|
||||
export function reorderFixedTabs(tabs: App.Global.Tab[]) {
|
||||
const fixedTabs = getFixedTabs(tabs);
|
||||
fixedTabs.forEach((t, i) => {
|
||||
t.fixedIndex = i;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update tabs label
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user