mirror of
https://github.com/certd/certd.git
synced 2026-05-18 14:27:36 +08:00
chore: 插件编辑与运行测试beta
This commit is contained in:
@@ -45,7 +45,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* Close tabs in bulk
|
||||
*/
|
||||
async _bulkCloseByPaths(paths: string[]) {
|
||||
this.tabs = this.tabs.filter((item) => {
|
||||
this.tabs = this.tabs.filter(item => {
|
||||
return !paths.includes(getTabPath(item));
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
if (isAffixTab(tab)) {
|
||||
return;
|
||||
}
|
||||
const index = this.tabs.findIndex((item) => item.fullPath === fullPath);
|
||||
const index = this.tabs.findIndex(item => item.fullPath === fullPath);
|
||||
index !== -1 && this.tabs.splice(index, 1);
|
||||
},
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
const toParams = {
|
||||
params: params || {},
|
||||
path,
|
||||
query: query || {}
|
||||
query: query || {},
|
||||
};
|
||||
await router.replace(toParams);
|
||||
},
|
||||
@@ -99,7 +99,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
return;
|
||||
}
|
||||
|
||||
const tabIndex = this.tabs.findIndex((tab) => {
|
||||
const tabIndex = this.tabs.findIndex(tab => {
|
||||
return getTabPath(tab) === getTabPath(routeTab);
|
||||
});
|
||||
|
||||
@@ -109,13 +109,13 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
const maxNumOfOpenTab = (routeTab?.meta?.maxNumOfOpenTab ?? -1) as number;
|
||||
// 如果动态路由层级大于 0 了,那么就要限制该路由的打开数限制了
|
||||
// 获取到已经打开的动态路由数, 判断是否大于某一个值
|
||||
if (maxNumOfOpenTab > 0 && this.tabs.filter((tab) => tab.name === routeTab.name).length >= maxNumOfOpenTab) {
|
||||
if (maxNumOfOpenTab > 0 && this.tabs.filter(tab => tab.name === routeTab.name).length >= maxNumOfOpenTab) {
|
||||
// 关闭第一个
|
||||
const index = this.tabs.findIndex((item) => item.name === routeTab.name);
|
||||
const index = this.tabs.findIndex(item => item.name === routeTab.name);
|
||||
index !== -1 && this.tabs.splice(index, 1);
|
||||
} else if (maxCount > 0 && this.tabs.length >= maxCount) {
|
||||
// 关闭第一个
|
||||
const index = this.tabs.findIndex((item) => !Reflect.has(item.meta, "affixTab") || !item.meta.affixTab);
|
||||
const index = this.tabs.findIndex(item => !Reflect.has(item.meta, "affixTab") || !item.meta.affixTab);
|
||||
index !== -1 && this.tabs.splice(index, 1);
|
||||
}
|
||||
this.tabs.push(tab);
|
||||
@@ -125,7 +125,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
const mergedTab = {
|
||||
...currentTab,
|
||||
...tab,
|
||||
meta: { ...currentTab?.meta, ...tab.meta }
|
||||
meta: { ...currentTab?.meta, ...tab.meta },
|
||||
};
|
||||
if (currentTab) {
|
||||
const curMeta = currentTab.meta;
|
||||
@@ -145,7 +145,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @zh_CN 关闭所有标签页
|
||||
*/
|
||||
async closeAllTabs(router: Router) {
|
||||
const newTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
const newTabs = this.tabs.filter(tab => isAffixTab(tab));
|
||||
this.tabs = newTabs.length > 0 ? newTabs : [...this.tabs].splice(0, 1);
|
||||
await this._goToDefaultTab(router);
|
||||
this.updateCacheTabs();
|
||||
@@ -155,7 +155,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param tab
|
||||
*/
|
||||
async closeLeftTabs(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex((item) => getTabPath(item) === getTabPath(tab));
|
||||
const index = this.tabs.findIndex(item => getTabPath(item) === getTabPath(tab));
|
||||
|
||||
if (index < 1) {
|
||||
return;
|
||||
@@ -176,13 +176,13 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param tab
|
||||
*/
|
||||
async closeOtherTabs(tab: TabDefinition) {
|
||||
const closePaths = this.tabs.map((item) => getTabPath(item));
|
||||
const closePaths = this.tabs.map(item => getTabPath(item));
|
||||
|
||||
const paths: string[] = [];
|
||||
|
||||
for (const path of closePaths) {
|
||||
if (path !== tab.fullPath) {
|
||||
const closeTab = this.tabs.find((item) => getTabPath(item) === path);
|
||||
const closeTab = this.tabs.find(item => getTabPath(item) === path);
|
||||
if (!closeTab) {
|
||||
continue;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param tab
|
||||
*/
|
||||
async closeRightTabs(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex((item) => getTabPath(item) === getTabPath(tab));
|
||||
const index = this.tabs.findIndex(item => getTabPath(item) === getTabPath(tab));
|
||||
|
||||
if (index !== -1 && index < this.tabs.length - 1) {
|
||||
const rightTabs = this.tabs.slice(index + 1);
|
||||
@@ -227,7 +227,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
this.updateCacheTabs();
|
||||
return;
|
||||
}
|
||||
const index = this.getTabs.findIndex((item) => getTabPath(item) === getTabPath(currentRoute.value));
|
||||
const index = this.getTabs.findIndex(item => getTabPath(item) === getTabPath(currentRoute.value));
|
||||
|
||||
const before = this.getTabs[index - 1];
|
||||
const after = this.getTabs[index + 1];
|
||||
@@ -252,7 +252,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
*/
|
||||
async closeTabByKey(key: string, router: Router) {
|
||||
const originKey = decodeURIComponent(key);
|
||||
const index = this.tabs.findIndex((item) => getTabPath(item) === originKey);
|
||||
const index = this.tabs.findIndex(item => getTabPath(item) === originKey);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
@@ -268,7 +268,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param path
|
||||
*/
|
||||
getTabByPath(path: string) {
|
||||
return this.getTabs.find((item) => getTabPath(item) === path) as TabDefinition;
|
||||
return this.getTabs.find(item => getTabPath(item) === path) as TabDefinition;
|
||||
},
|
||||
/**
|
||||
* @zh_CN 新窗口打开标签页
|
||||
@@ -283,7 +283,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param tab
|
||||
*/
|
||||
async pinTab(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex((item) => getTabPath(item) === getTabPath(tab));
|
||||
const index = this.tabs.findIndex(item => getTabPath(item) === getTabPath(tab));
|
||||
if (index !== -1) {
|
||||
const oldTab = this.tabs[index];
|
||||
tab.meta.affixTab = true;
|
||||
@@ -292,9 +292,9 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
this.tabs.splice(index, 1, tab);
|
||||
}
|
||||
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
||||
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
const affixTabs = this.tabs.filter(tab => isAffixTab(tab));
|
||||
// 获得固定tabs的index
|
||||
const newIndex = affixTabs.findIndex((item) => getTabPath(item) === getTabPath(tab));
|
||||
const newIndex = affixTabs.findIndex(item => getTabPath(item) === getTabPath(tab));
|
||||
// 交换位置重新排序
|
||||
await this.sortTabs(index, newIndex);
|
||||
},
|
||||
@@ -310,7 +310,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
this.renderRouteView = false;
|
||||
startProgress();
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
|
||||
this.excludeCachedTabs.delete(name as string);
|
||||
this.renderRouteView = true;
|
||||
@@ -324,7 +324,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
if (tab?.meta?.newTabTitle) {
|
||||
return;
|
||||
}
|
||||
const findTab = this.tabs.find((item) => getTabPath(item) === getTabPath(tab));
|
||||
const findTab = this.tabs.find(item => getTabPath(item) === getTabPath(tab));
|
||||
if (findTab) {
|
||||
findTab.meta.newTabTitle = undefined;
|
||||
await this.updateCacheTabs();
|
||||
@@ -348,7 +348,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param title
|
||||
*/
|
||||
async setTabTitle(tab: TabDefinition, title: string) {
|
||||
const findTab = this.tabs.find((item) => getTabPath(item) === getTabPath(tab));
|
||||
const findTab = this.tabs.find(item => getTabPath(item) === getTabPath(tab));
|
||||
|
||||
if (findTab) {
|
||||
findTab.meta.newTabTitle = title;
|
||||
@@ -389,7 +389,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
* @param tab
|
||||
*/
|
||||
async unpinTab(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex((item) => getTabPath(item) === getTabPath(tab));
|
||||
const index = this.tabs.findIndex(item => getTabPath(item) === getTabPath(tab));
|
||||
|
||||
if (index !== -1) {
|
||||
const oldTab = this.tabs[index];
|
||||
@@ -399,7 +399,7 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
this.tabs.splice(index, 1, tab);
|
||||
}
|
||||
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
||||
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
const affixTabs = this.tabs.filter(tab => isAffixTab(tab));
|
||||
// 获得固定tabs的index,使用固定tabs的下一个位置也就是活动tabs的第一个位置
|
||||
const newIndex = affixTabs.length;
|
||||
// 交换位置重新排序
|
||||
@@ -428,11 +428,11 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
cacheMap.add(name);
|
||||
}
|
||||
this.cachedTabs = cacheMap;
|
||||
}
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
affixTabs(): TabDefinition[] {
|
||||
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
const affixTabs = this.tabs.filter(tab => isAffixTab(tab));
|
||||
|
||||
return affixTabs.sort((a, b) => {
|
||||
const orderA = (a.meta?.affixTabOrder ?? 0) as number;
|
||||
@@ -447,16 +447,16 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
return [...this.excludeCachedTabs];
|
||||
},
|
||||
getTabs(): TabDefinition[] {
|
||||
const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab));
|
||||
const normalTabs = this.tabs.filter(tab => !isAffixTab(tab));
|
||||
return [...this.affixTabs, ...normalTabs].filter(Boolean);
|
||||
}
|
||||
},
|
||||
},
|
||||
persist: [
|
||||
// tabs不需要保存在localStorage
|
||||
{
|
||||
pick: ["tabs"],
|
||||
storage: sessionStorage
|
||||
}
|
||||
storage: sessionStorage,
|
||||
},
|
||||
],
|
||||
state: (): TabbarState => ({
|
||||
cachedTabs: new Set(),
|
||||
@@ -464,8 +464,8 @@ export const useTabbarStore = defineStore("core-tabbar", {
|
||||
excludeCachedTabs: new Set(),
|
||||
renderRouteView: true,
|
||||
tabs: [],
|
||||
updateTime: Date.now()
|
||||
})
|
||||
updateTime: Date.now(),
|
||||
}),
|
||||
});
|
||||
|
||||
// 解决热更新问题
|
||||
@@ -486,16 +486,16 @@ function cloneTab(route: TabDefinition): TabDefinition {
|
||||
return {
|
||||
...opt,
|
||||
matched: (matched
|
||||
? matched.map((item) => ({
|
||||
? matched.map(item => ({
|
||||
meta: item.meta,
|
||||
name: item.name,
|
||||
path: item.path
|
||||
path: item.path,
|
||||
}))
|
||||
: undefined) as RouteRecordNormalized[],
|
||||
meta: {
|
||||
...meta,
|
||||
newTabTitle: meta.newTabTitle
|
||||
}
|
||||
newTabTitle: meta.newTabTitle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ function isAffixTab(tab: TabDefinition) {
|
||||
*/
|
||||
function isTabShown(tab: TabDefinition) {
|
||||
const matched = tab?.matched ?? [];
|
||||
return !tab.meta.hideInTab && matched.every((item) => !item.meta.hideInTab);
|
||||
return !tab.meta.hideInTab && matched.every(item => !item.meta.hideInTab);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,6 +528,6 @@ function routeToTab(route: RouteRecordNormalized) {
|
||||
return {
|
||||
meta: route.meta,
|
||||
name: route.name,
|
||||
path: route.path
|
||||
path: route.path,
|
||||
} as TabDefinition;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user