|
|
@@ -1,75 +1,75 @@
|
|
|
-import { defineStore } from 'pinia'
|
|
|
-import tool from '@/utils/tool'
|
|
|
+import { defineStore } from "pinia";
|
|
|
+import tool from "@/utils/tool";
|
|
|
|
|
|
const defaultTag = [
|
|
|
- { name: 'dashboard', title: '仪表盘', path: '/dashboard', affix: true }
|
|
|
-]
|
|
|
-const useTagStore = defineStore('tag', {
|
|
|
+ { name: "dashboard", title: "仪表盘", path: "/dashboard", affix: true },
|
|
|
+];
|
|
|
+const useTagStore = defineStore("tag", {
|
|
|
state: () => ({
|
|
|
tags:
|
|
|
- !tool.local.get('tags') || tool.local.get('tags').length === 0
|
|
|
+ !tool.local.get("tags") || tool.local.get("tags").length === 0
|
|
|
? defaultTag
|
|
|
- : tool.local.get('tags')
|
|
|
+ : tool.local.get("tags"),
|
|
|
}),
|
|
|
|
|
|
getters: {
|
|
|
getState() {
|
|
|
- return { ...this.$state }
|
|
|
- }
|
|
|
+ return { ...this.$state };
|
|
|
+ },
|
|
|
},
|
|
|
|
|
|
actions: {
|
|
|
addTag(tag) {
|
|
|
- const target = this.tags.find((item) => item.path === tag.path)
|
|
|
+ const target = this.tags.find((item) => item.path === tag.path);
|
|
|
if (!target && tag.path) {
|
|
|
- this.tags.push(tag)
|
|
|
+ this.tags.push(tag);
|
|
|
}
|
|
|
- this.updateTagsToLocal()
|
|
|
+ this.updateTagsToLocal();
|
|
|
},
|
|
|
|
|
|
removeTag(tag) {
|
|
|
- let index = 0
|
|
|
+ let index = 0;
|
|
|
this.tags.map((item, idx) => {
|
|
|
if (item.path === tag.path && !item.affix) {
|
|
|
if (this.tags[idx + 1]) {
|
|
|
- index = idx
|
|
|
+ index = idx;
|
|
|
} else if (idx > 0) {
|
|
|
- index = idx - 1
|
|
|
+ index = idx - 1;
|
|
|
}
|
|
|
- this.tags.splice(idx, 1)
|
|
|
+ this.tags.splice(idx, 1);
|
|
|
}
|
|
|
- })
|
|
|
- this.updateTagsToLocal()
|
|
|
- return this.tags[index]
|
|
|
+ });
|
|
|
+ this.updateTagsToLocal();
|
|
|
+ return this.tags[index];
|
|
|
},
|
|
|
|
|
|
updateTag(tag) {
|
|
|
this.tags.map((item) => {
|
|
|
if (item.path == tag.path) {
|
|
|
- item = Object.assign(item, tag)
|
|
|
+ item = Object.assign(item, tag);
|
|
|
}
|
|
|
- })
|
|
|
- this.updateTagsToLocal()
|
|
|
+ });
|
|
|
+ this.updateTagsToLocal();
|
|
|
},
|
|
|
|
|
|
updateTagTitle(path, title) {
|
|
|
this.tags.map((item) => {
|
|
|
if (item.path == path) {
|
|
|
- item.customTitle = title
|
|
|
+ item.customTitle = title;
|
|
|
}
|
|
|
- })
|
|
|
- this.updateTagsToLocal()
|
|
|
+ });
|
|
|
+ this.updateTagsToLocal();
|
|
|
},
|
|
|
|
|
|
updateTagsToLocal() {
|
|
|
- tool.local.set('tags', this.tags)
|
|
|
+ tool.local.set("tags", this.tags);
|
|
|
},
|
|
|
|
|
|
clearTags() {
|
|
|
- this.tags = defaultTag
|
|
|
- tool.local.set('tags', defaultTag)
|
|
|
- }
|
|
|
- }
|
|
|
-})
|
|
|
+ this.tags = defaultTag;
|
|
|
+ tool.local.set("tags", defaultTag);
|
|
|
+ },
|
|
|
+ },
|
|
|
+});
|
|
|
|
|
|
-export default useTagStore
|
|
|
+export default useTagStore;
|