fix:levelbar&&tabsview bug

This commit is contained in:
Pan 2017-11-01 17:55:11 +08:00
parent 8211016078
commit aaf24b4654
4 changed files with 20 additions and 13 deletions

View file

@ -21,7 +21,8 @@ const app = {
if (state.visitedViews.some(v => v.path === view.path)) return if (state.visitedViews.some(v => v.path === view.path)) return
state.visitedViews.push({ state.visitedViews.push({
name: view.name, name: view.name,
path: view.path path: view.path,
title: view.meta.title || 'no-name'
}) })
if (!view.meta.noCache) { if (!view.meta.noCache) {
state.cachedViews.push(view.name) state.cachedViews.push(view.name)

View file

@ -5,7 +5,7 @@
<sticky :className="'sub-navbar '+postForm.status"> <sticky :className="'sub-navbar '+postForm.status">
<template v-if="fetchSuccess"> <template v-if="fetchSuccess">
<router-link style="margin-right:15px;" v-show='isEdit' :to="{ path:'create'}"> <router-link style="margin-right:15px;" v-show='isEdit' :to="{ path:'create-form'}">
<el-button type="info">创建form</el-button> <el-button type="info">创建form</el-button>
</router-link> </router-link>

View file

@ -20,6 +20,10 @@ export default {
methods: { methods: {
getBreadcrumb() { getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name) let matched = this.$route.matched.filter(item => item.name)
if (matched.length === 0) {
this.levelList = [{ path: '/', meta: { title: '首页' }}]
return
}
const first = matched[0] const first = matched[0]
if (first && (first.name !== '首页' || first.path !== '')) { if (first && (first.name !== '首页' || first.path !== '')) {
matched = [{ path: '/', meta: { title: '首页' }}].concat(matched) matched = [{ path: '/', meta: { title: '首页' }}].concat(matched)

View file

@ -1,8 +1,7 @@
<template> <template>
<scroll-pane class='tabs-view-container'> <scroll-pane class='tabs-view-container'>
<router-link class="tabs-view-item" :class="isActive(tag.path)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path" <router-link class="tabs-view-item" :class="isActive(tag)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path" :key="tag.path">
:key="tag.path"> {{tag.title}}
{{tag.name}}
<span class='el-icon-close' @click='closeViewTabs(tag,$event)'></span> <span class='el-icon-close' @click='closeViewTabs(tag,$event)'></span>
</router-link> </router-link>
</scroll-pane> </scroll-pane>
@ -20,7 +19,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.$store.dispatch('addVisitedViews', this.generateRoute()) this.addViewTabs()
}, },
methods: { methods: {
closeViewTabs(view, $event) { closeViewTabs(view, $event) {
@ -37,17 +36,20 @@ export default {
$event.preventDefault() $event.preventDefault()
}, },
generateRoute() { generateRoute() {
if (this.$route.matched[this.$route.matched.length - 1].name) { if (this.$route.name) {
return this.$route.matched[this.$route.matched.length - 1] return this.$route
} }
this.$route.matched[0].path = '/' return false
return this.$route.matched[0]
}, },
addViewTabs() { addViewTabs() {
this.$store.dispatch('addVisitedViews', this.generateRoute()) const route = this.generateRoute()
if (!route) {
return false
}
this.$store.dispatch('addVisitedViews', route)
}, },
isActive(path) { isActive(route) {
return path === this.$route.path return route.path === this.$route.path || route.name === this.$route.name
} }
}, },