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 11const getters = {
22 sidebar : state => state . app . sidebar ,
3+ visitedViews : state => state . app . visitedViews ,
34 token : state => state . user . token ,
45 avatar : state => state . user . avatar ,
56 name : state => state . user . name ,
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ const app = {
66 opened : ! + Cookies . get ( 'sidebarStatus' )
77 } ,
88 theme : 'default' ,
9- livenewsChannels : Cookies . get ( 'livenewsChannels' ) || '[]'
9+ livenewsChannels : Cookies . get ( 'livenewsChannels' ) || '[]' ,
10+ visitedViews : [ ]
1011 } ,
1112 mutations : {
1213 TOGGLE_SIDEBAR : state => {
@@ -16,11 +17,25 @@ const app = {
1617 Cookies . set ( 'sidebarStatus' , 0 ) ;
1718 }
1819 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 )
1928 }
2029 } ,
2130 actions : {
2231 ToggleSideBar : ( { commit } ) => {
2332 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 )
2439 }
2540 }
2641} ;
Original file line number Diff line number Diff line change 44 <router-link v-if =' item.redirect==="noredirect"||index==levelList.length-1' to =" " class =" no-redirect" >{{item.name}}</router-link >
55 <router-link v-else :to =" item.path" >{{item.name}}</router-link >
66 </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 >
712 </el-breadcrumb >
813</template >
914
1015<script >
16+
1117 export default {
1218 created () {
1319 this .getBreadcrumb ()
1420 },
21+ computed: {
22+ visitedViews () {
23+ return this .$store .state .app .visitedViews .slice (- 6 )
24+ }
25+ },
1526 data () {
1627 return {
1728 levelList: null
2536 matched = [{ name: ' 首页' , path: ' /' }].concat (matched)
2637 }
2738 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 ])
2846 }
2947 },
3048 watch: {
3149 $route () {
50+ this .addViewTabs ();
3251 this .getBreadcrumb ();
3352 }
3453 }
4665 cursor :text ;
4766 }
4867 }
68+ .view-tabs {
69+ margin-left : 10px ;
70+ }
4971 </style >
You can’t perform that action at this time.
0 commit comments