Compare commits

...

3 Commits

4 changed files with 43 additions and 39 deletions

View File

@@ -356,7 +356,7 @@ function onClickDrop(key, item, selectRoute?: RouteConfigs) {
break; break;
} }
setTimeout(() => { setTimeout(() => {
showMenuModel(route.fullPath, route.query); showMenuModel(route.fullPath, route.query, route.params);
}); });
} }
@@ -391,15 +391,18 @@ function disabledMenus(value: boolean, fixedTag = false) {
function showMenuModel( function showMenuModel(
currentPath: string, currentPath: string,
query: object = {}, query: object = {},
params: object = {},
refresh = false refresh = false
) { ) {
const allRoute = multiTags.value; const allRoute = multiTags.value;
const routeLength = multiTags.value.length; const routeLength = multiTags.value.length;
let currentIndex = -1; let currentIndex = -1;
if (isAllEmpty(query)) { if (!isAllEmpty(params)) {
currentIndex = allRoute.findIndex(v => v.path === currentPath); currentIndex = allRoute.findIndex(v => isEqual(v.params, params));
} else { } else if (!isAllEmpty(query)) {
currentIndex = allRoute.findIndex(v => isEqual(v.query, query)); currentIndex = allRoute.findIndex(v => isEqual(v.query, query));
} else {
currentIndex = allRoute.findIndex(v => v.path === currentPath);
} }
function fixedTagDisabled() { function fixedTagDisabled() {
if (allRoute[currentIndex]?.meta?.fixedTag) { if (allRoute[currentIndex]?.meta?.fixedTag) {
@@ -465,14 +468,14 @@ function openMenu(tag, e) {
} else if (route.path !== tag.path && route.name !== tag.name) { } else if (route.path !== tag.path && route.name !== tag.name) {
// 右键菜单不匹配当前路由,隐藏刷新 // 右键菜单不匹配当前路由,隐藏刷新
tagsViews[0].show = false; tagsViews[0].show = false;
showMenuModel(tag.path, tag.query); showMenuModel(tag.path, tag.query, tag.params);
} else if (multiTags.value.length === 2 && route.path !== tag.path) { } else if (multiTags.value.length === 2 && route.path !== tag.path) {
showMenus(true); showMenus(true);
// 只有两个标签时不显示关闭其他标签页 // 只有两个标签时不显示关闭其他标签页
tagsViews[4].show = false; tagsViews[4].show = false;
} else if (route.path === tag.path) { showMenuModel(tag.path, tag.query, tag.params);
// 右键当前激活的菜单 } else {
showMenuModel(tag.path, tag.query, true); showMenuModel(tag.path, tag.query, tag.params, true);
} }
currentSelect.value = tag; currentSelect.value = tag;

View File

@@ -114,14 +114,21 @@ export function useTags() {
]); ]);
function conditionHandle(item, previous, next) { function conditionHandle(item, previous, next) {
const currentName = route.name || "";
const itemName = item.name || "";
if (isBoolean(route?.meta?.showLink) && route?.meta?.showLink === false) { if (isBoolean(route?.meta?.showLink) && route?.meta?.showLink === false) {
if (Object.keys(route.query).length > 0) { if (Object.keys(route.query).length > 0) {
return isEqual(route.query, item.query) ? previous : next; return currentName === itemName && isEqual(route.query, item.query)
? previous
: next;
} else { } else {
return isEqual(route.params, item.params) ? previous : next; return currentName === itemName && isEqual(route.params, item.params)
? previous
: next;
} }
} else { } else {
return route.path === item.path ? previous : next; return currentName === itemName ? previous : next;
} }
} }

View File

@@ -80,22 +80,15 @@ export const useMultiTagsStore = defineStore("pure-multiTags", {
if (isBoolean(tagVal?.meta?.showLink) && !tagVal?.meta?.showLink) if (isBoolean(tagVal?.meta?.showLink) && !tagVal?.meta?.showLink)
return; return;
const tagPath = tagVal.path; const tagPath = tagVal.path;
// 判断tag是否已存在
const tagHasExits = this.multiTags.some(tag => { const tagHasExits = this.multiTags.some(tag => {
return tag.path === tagPath; return (
tag.path === tagPath &&
isEqual(tag?.query, tagVal?.query) &&
isEqual(tag?.params, tagVal?.params)
);
}); });
// 判断tag中的query键值是否相等 if (tagHasExits) return;
const tagQueryHasExits = this.multiTags.some(tag => {
return isEqual(tag?.query, tagVal?.query);
});
// 判断tag中的params键值是否相等
const tagParamsHasExits = this.multiTags.some(tag => {
return isEqual(tag?.params, tagVal?.params);
});
if (tagHasExits && tagQueryHasExits && tagParamsHasExits) return;
// 动态路由可打开的最大数量 // 动态路由可打开的最大数量
const dynamicLevel = tagVal?.meta?.dynamicLevel ?? -1; const dynamicLevel = tagVal?.meta?.dynamicLevel ?? -1;

View File

@@ -2,7 +2,6 @@ import { defineStore } from "pinia";
import { import {
type cacheType, type cacheType,
store, store,
debounce,
ascending, ascending,
getKeyList, getKeyList,
filterTree, filterTree,
@@ -33,33 +32,35 @@ export const usePermissionStore = defineStore("pure-permission", {
this.constantMenus.concat(routes) as any this.constantMenus.concat(routes) as any
); );
}, },
/** 监听缓存页面是否存在于标签页,不存在则删除 */
clearCache() {
let cacheLength = this.cachePageList.length;
const nameList = getKeyList(useMultiTagsStoreHook().multiTags, "name");
while (cacheLength > 0) {
nameList.findIndex(v => v === this.cachePageList[cacheLength - 1]) ===
-1 &&
this.cachePageList.splice(
this.cachePageList.indexOf(this.cachePageList[cacheLength - 1]),
1
);
cacheLength--;
}
},
cacheOperate({ mode, name }: cacheType) { cacheOperate({ mode, name }: cacheType) {
const delIndex = this.cachePageList.findIndex(v => v === name); const delIndex = this.cachePageList.findIndex(v => v === name);
switch (mode) { switch (mode) {
case "refresh": case "refresh":
this.cachePageList = this.cachePageList.filter(v => v !== name); this.cachePageList = this.cachePageList.filter(v => v !== name);
this.clearCache();
break; break;
case "add": case "add":
this.cachePageList.push(name); this.cachePageList.push(name);
break; break;
case "delete": case "delete":
delIndex !== -1 && this.cachePageList.splice(delIndex, 1); delIndex !== -1 && this.cachePageList.splice(delIndex, 1);
this.clearCache();
break; break;
} }
/** 监听缓存页面是否存在于标签页,不存在则删除 */
debounce(() => {
let cacheLength = this.cachePageList.length;
const nameList = getKeyList(useMultiTagsStoreHook().multiTags, "name");
while (cacheLength > 0) {
nameList.findIndex(v => v === this.cachePageList[cacheLength - 1]) ===
-1 &&
this.cachePageList.splice(
this.cachePageList.indexOf(this.cachePageList[cacheLength - 1]),
1
);
cacheLength--;
}
})();
}, },
/** 清空缓存页面 */ /** 清空缓存页面 */
clearAllCachePage() { clearAllCachePage() {