|
@@ -1,23 +1,27 @@
|
|
|
import { defineStore } from 'pinia'
|
|
import { defineStore } from 'pinia'
|
|
|
import tool from '@/utils/tool'
|
|
import tool from '@/utils/tool'
|
|
|
|
|
|
|
|
-const defaultTag = [ { name: 'dashboard', title: '仪表盘', path: '/dashboard', affix: true } ]
|
|
|
|
|
|
|
+const defaultTag = [
|
|
|
|
|
+ { name: 'dashboard', title: '仪表盘1', path: '/dashboard', affix: true }
|
|
|
|
|
+]
|
|
|
const useTagStore = defineStore('tag', {
|
|
const useTagStore = defineStore('tag', {
|
|
|
state: () => ({
|
|
state: () => ({
|
|
|
- tags: (! tool.local.get('tags') || tool.local.get('tags').length === 0 ) ? defaultTag : tool.local.get('tags')
|
|
|
|
|
|
|
+ tags:
|
|
|
|
|
+ !tool.local.get('tags') || tool.local.get('tags').length === 0
|
|
|
|
|
+ ? defaultTag
|
|
|
|
|
+ : tool.local.get('tags')
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
getters: {
|
|
getters: {
|
|
|
getState() {
|
|
getState() {
|
|
|
return { ...this.$state }
|
|
return { ...this.$state }
|
|
|
- },
|
|
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
actions: {
|
|
|
-
|
|
|
|
|
addTag(tag) {
|
|
addTag(tag) {
|
|
|
- const target = this.tags.find( item => item.path === tag.path )
|
|
|
|
|
- if (! target && 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()
|
|
@@ -26,10 +30,10 @@ const useTagStore = defineStore('tag', {
|
|
|
removeTag(tag) {
|
|
removeTag(tag) {
|
|
|
let index = 0
|
|
let index = 0
|
|
|
this.tags.map((item, idx) => {
|
|
this.tags.map((item, idx) => {
|
|
|
- if ( item.path === tag.path && ! item.affix ) {
|
|
|
|
|
- if (this.tags[(idx + 1)]) {
|
|
|
|
|
|
|
+ if (item.path === tag.path && !item.affix) {
|
|
|
|
|
+ if (this.tags[idx + 1]) {
|
|
|
index = idx
|
|
index = idx
|
|
|
- } else if ( idx > 0) {
|
|
|
|
|
|
|
+ } else if (idx > 0) {
|
|
|
index = idx - 1
|
|
index = idx - 1
|
|
|
}
|
|
}
|
|
|
this.tags.splice(idx, 1)
|
|
this.tags.splice(idx, 1)
|
|
@@ -40,7 +44,7 @@ const useTagStore = defineStore('tag', {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
updateTag(tag) {
|
|
updateTag(tag) {
|
|
|
- this.tags.map(item => {
|
|
|
|
|
|
|
+ this.tags.map((item) => {
|
|
|
if (item.path == tag.path) {
|
|
if (item.path == tag.path) {
|
|
|
item = Object.assign(item, tag)
|
|
item = Object.assign(item, tag)
|
|
|
}
|
|
}
|
|
@@ -49,7 +53,7 @@ const useTagStore = defineStore('tag', {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
updateTagTitle(path, title) {
|
|
updateTagTitle(path, title) {
|
|
|
- this.tags.map(item => {
|
|
|
|
|
|
|
+ this.tags.map((item) => {
|
|
|
if (item.path == path) {
|
|
if (item.path == path) {
|
|
|
item.customTitle = title
|
|
item.customTitle = title
|
|
|
}
|
|
}
|
|
@@ -64,8 +68,8 @@ const useTagStore = defineStore('tag', {
|
|
|
clearTags() {
|
|
clearTags() {
|
|
|
this.tags = defaultTag
|
|
this.tags = defaultTag
|
|
|
tool.local.set('tags', defaultTag)
|
|
tool.local.set('tags', defaultTag)
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-export default useTagStore
|
|
|
|
|
|
|
+export default useTagStore
|