|
@@ -4,6 +4,13 @@ import { getConfig } from "/@/config";
|
|
import { positionType } from "./types";
|
|
import { positionType } from "./types";
|
|
import { storageLocal } from "/@/utils/storage";
|
|
import { storageLocal } from "/@/utils/storage";
|
|
|
|
|
|
|
|
+interface Itag {
|
|
|
|
+ path: string;
|
|
|
|
+ parentPath: string;
|
|
|
|
+ name: string;
|
|
|
|
+ meta: any;
|
|
|
|
+}
|
|
|
|
+
|
|
export const useMultiTagsStore = defineStore({
|
|
export const useMultiTagsStore = defineStore({
|
|
id: "pure-multiTags",
|
|
id: "pure-multiTags",
|
|
state: () => ({
|
|
state: () => ({
|
|
@@ -34,14 +41,44 @@ export const useMultiTagsStore = defineStore({
|
|
this.getMultiTagsCache &&
|
|
this.getMultiTagsCache &&
|
|
storageLocal.setItem("responsive-tags", multiTags);
|
|
storageLocal.setItem("responsive-tags", multiTags);
|
|
},
|
|
},
|
|
- handleTags<T>(mode: string, value?: T, position?: positionType): any {
|
|
|
|
|
|
+ handleTags<T>(
|
|
|
|
+ mode: string,
|
|
|
|
+ value?: T | Itag,
|
|
|
|
+ position?: positionType
|
|
|
|
+ ): any {
|
|
switch (mode) {
|
|
switch (mode) {
|
|
case "equal":
|
|
case "equal":
|
|
this.multiTags = value;
|
|
this.multiTags = value;
|
|
break;
|
|
break;
|
|
case "push":
|
|
case "push":
|
|
- this.multiTags.push(value);
|
|
|
|
- this.tagsCache(this.multiTags);
|
|
|
|
|
|
+ {
|
|
|
|
+ const tagVal = value as Itag;
|
|
|
|
+ // 判断tag是否已存在:
|
|
|
|
+ const tagHasExits = this.multiTags.some(tag => {
|
|
|
|
+ return tag.path === tagVal?.path;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (tagHasExits) return;
|
|
|
|
+ const meta = tagVal?.meta;
|
|
|
|
+ const dynamicLevel = meta?.dynamicLevel ?? -1;
|
|
|
|
+ if (dynamicLevel > 0) {
|
|
|
|
+ // dynamicLevel动态路由可打开的数量
|
|
|
|
+ const realPath = meta?.realPath ?? "";
|
|
|
|
+ // 获取到已经打开的动态路由数, 判断是否大于dynamicLevel
|
|
|
|
+ if (
|
|
|
|
+ this.multiTags.filter(e => e.meta?.realPath ?? "" === realPath)
|
|
|
|
+ .length >= dynamicLevel
|
|
|
|
+ ) {
|
|
|
|
+ // 关闭第一个
|
|
|
|
+ const index = this.multiTags.findIndex(
|
|
|
|
+ item => item.meta?.realPath === realPath
|
|
|
|
+ );
|
|
|
|
+ index !== -1 && this.multiTags.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.multiTags.push(value);
|
|
|
|
+ this.tagsCache(this.multiTags);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case "splice":
|
|
case "splice":
|
|
this.multiTags.splice(position?.startIndex, position?.length);
|
|
this.multiTags.splice(position?.startIndex, position?.length);
|