File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
1
const getters = {
2
2
sidebar : state => state . app . sidebar ,
3
+ visitedViews : state => state . app . visitedViews ,
3
4
token : state => state . user . token ,
4
5
avatar : state => state . user . avatar ,
5
6
name : state => state . user . name ,
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ const app = {
6
6
opened : ! + Cookies . get ( 'sidebarStatus' )
7
7
} ,
8
8
theme : 'default' ,
9
- livenewsChannels : Cookies . get ( 'livenewsChannels' ) || '[]'
9
+ livenewsChannels : Cookies . get ( 'livenewsChannels' ) || '[]' ,
10
+ visitedViews : [ ]
10
11
} ,
11
12
mutations : {
12
13
TOGGLE_SIDEBAR : state => {
@@ -16,11 +17,25 @@ const app = {
16
17
Cookies . set ( 'sidebarStatus' , 0 ) ;
17
18
}
18
19
state . sidebar . opened = ! state . sidebar . opened ;
20
+ } ,
21
+ ADD_VISITED_VIEWS : ( state , view ) => {
22
+ if ( state . visitedViews . includes ( view ) ) return
23
+ state . visitedViews . push ( view )
24
+ } ,
25
+ DEL_VISITED_VIEWS : ( state , view ) => {
26
+ const index = state . visitedViews . indexOf ( view )
27
+ state . visitedViews . splice ( index , 1 )
19
28
}
20
29
} ,
21
30
actions : {
22
31
ToggleSideBar : ( { commit } ) => {
23
32
commit ( 'TOGGLE_SIDEBAR' )
33
+ } ,
34
+ addVisitedViews : ( { commit } , view ) => {
35
+ commit ( 'ADD_VISITED_VIEWS' , view )
36
+ } ,
37
+ delVisitedViews : ( { commit } , view ) => {
38
+ commit ( 'DEL_VISITED_VIEWS' , view )
24
39
}
25
40
}
26
41
} ;
Original file line number Diff line number Diff line change 4
4
<router-link v-if =' item.redirect==="noredirect"||index==levelList.length-1' to =" " class =" no-redirect" >{{item.name}}</router-link >
5
5
<router-link v-else :to =" item.path" >{{item.name}}</router-link >
6
6
</el-breadcrumb-item >
7
+ <router-link class =" view-tabs" v-for =" tag in Array.from(visitedViews)" :to =" tag.path" :key =" tag.path" >
8
+ <el-tag :closable =" true" @close =' closeViewTabs(tag,$event)' >
9
+ {{tag.name}}
10
+ </el-tag >
11
+ </router-link >
7
12
</el-breadcrumb >
8
13
</template >
9
14
10
15
<script >
16
+
11
17
export default {
12
18
created () {
13
19
this .getBreadcrumb ()
14
20
},
21
+ computed: {
22
+ visitedViews () {
23
+ return this .$store .state .app .visitedViews .slice (- 6 )
24
+ }
25
+ },
15
26
data () {
16
27
return {
17
28
levelList: null
25
36
matched = [{ name: ' 首页' , path: ' /' }].concat (matched)
26
37
}
27
38
this .levelList = matched;
39
+ },
40
+ closeViewTabs (view , $event ) {
41
+ this .$store .dispatch (' delVisitedViews' , view)
42
+ $event .preventDefault ()
43
+ },
44
+ addViewTabs () {
45
+ this .$store .dispatch (' addVisitedViews' , this .$route .matched [this .$route .matched .length - 1 ])
28
46
}
29
47
},
30
48
watch: {
31
49
$route () {
50
+ this .addViewTabs ();
32
51
this .getBreadcrumb ();
33
52
}
34
53
}
46
65
cursor :text ;
47
66
}
48
67
}
68
+ .view-tabs {
69
+ margin-left : 10px ;
70
+ }
49
71
</style >
You can’t perform that action at this time.
0 commit comments