gaoshp
2024-06-23 fbee7228e2f6e43b417d4c3f03020704831261cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import router from '@/router'
 
export default {
    state: {
        viewTags: []
    },
    mutations: {
        pushViewTags(state, route){
            let backPathIndex = state.viewTags.findIndex(item => item.fullPath == router.options.history.state.back)
            let target = state.viewTags.find((item) => item.fullPath === route.fullPath)
            let isName = route.name
            if(!target && isName){
                if(backPathIndex == -1){
                    state.viewTags.push(route)
                }else{
                    state.viewTags.splice(backPathIndex+1, 0, route)
                }
            }
        },
        removeViewTags(state, route){
            state.viewTags.forEach((item, index) => {
                if (item.fullPath === route.fullPath){
                    state.viewTags.splice(index, 1)
                }
            })
        },
        updateViewTags(state, route){
            state.viewTags.forEach((item) => {
                if (item.fullPath == route.fullPath){
                    item = Object.assign(item, route)
                }
            })
        },
        updateViewTagsTitle(state, title=''){
            const nowFullPath = location.hash.substring(1)
            state.viewTags.forEach((item) => {
                if (item.fullPath == nowFullPath){
                    item.meta.title = title
                }
            })
        },
        clearViewTags(state){
            state.viewTags = []
        }
    }
}