Skip to content

Commit

Permalink
Merge pull request #1017 from iview/2.0
Browse files Browse the repository at this point in the history
修复自定义首页bug
  • Loading branch information
Lison authored Oct 10, 2018
2 parents e885e77 + 5223e77 commit 0425a69
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/components/main/components/tags-nav/tags-nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:name="item.name"
@on-close="handleClose(item)"
@click.native="handleClick(item)"
:closable="item.name !== 'home'"
:closable="item.name !== $config.homeName"
:color="isCurrentTag(item) ? 'primary' : 'default'"
@contextmenu.prevent.native="contextMenu(item, $event)"
>{{ showTitleInside(item) }}</Tag>
Expand Down Expand Up @@ -108,11 +108,11 @@ export default {
handleTagsOption (type) {
if (type.includes('all')) {
// 关闭所有,除了home
let res = this.list.filter(item => item.name === 'home')
let res = this.list.filter(item => item.name === this.$config.homeName)
this.$emit('on-close', res, 'all')
} else if (type.includes('others')) {
// 关闭除当前页和home页的其他页
let res = this.list.filter(item => routeEqual(this.currentRouteObj, item) || item.name === 'home')
let res = this.list.filter(item => routeEqual(this.currentRouteObj, item) || item.name === this.$config.homeName)
this.$emit('on-close', res, 'others', this.currentRouteObj)
setTimeout(() => {
this.getTagElementByName(this.currentRouteObj.name)
Expand Down Expand Up @@ -171,7 +171,7 @@ export default {
})
},
contextMenu (item, e) {
if (item.name === 'home') {
if (item.name === this.$config.homeName) {
return
}
this.visible = true
Expand Down
27 changes: 6 additions & 21 deletions src/components/main/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,12 @@ export default {
this.setBreadCrumb(this.$route)
// 设置初始语言
this.setLocal(this.$i18n.locale)
// 文档提示
this.$Notice.info({
title: '想快速上手,去看文档吧',
duration: 0,
render: (h) => {
return h('p', {
style: {
fontSize: '13px'
}
}, [
'点击',
h('a', {
attrs: {
href: 'https://lison16.github.io/iview-admin-doc/#/',
target: '_blank'
}
}, 'iview-admin2.0文档'),
'快速查看'
])
}
})
// 如果当前打开页面不在标签栏中,跳到homeName页
if (!this.tagNavList.find(item => item.name === this.$route.name)) {
this.$router.push({
name: this.$config.homeName
})
}
}
}
</script>
3 changes: 2 additions & 1 deletion src/libs/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const getMenuByRouter = (list, access) => {
*/
export const getBreadCrumbList = (route, homeRoute) => {
let routeMetched = route.matched
if (routeMetched.some(item => item.name === homeRoute.name)) return [homeRoute]
let res = routeMetched.filter(item => {
return item.meta === undefined || !item.meta.hide
}).map(item => {
Expand Down Expand Up @@ -107,7 +108,7 @@ export const getHomeRoute = (routers, homeName = 'home') => {
while (++i < len) {
let item = routers[i]
if (item.children && item.children.length) {
let res = getHomeRoute(item.children)
let res = getHomeRoute(item.children, homeName)
if (res.name) return res
} else {
if (item.name === homeName) homeRoute = item
Expand Down
4 changes: 3 additions & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import routes from './routers'
import store from '@/store'
import iView from 'iview'
import { getToken, canTurnTo } from '@/libs/util'
import config from '@/config'
const { homeName } = config

Vue.use(Router)
const router = new Router({
Expand Down Expand Up @@ -31,7 +33,7 @@ router.beforeEach((to, from, next) => {
} else if (token && to.name === LOGIN_PAGE_NAME) {
// 已登录且要跳转的页面是登录页
next({
name: 'home' // 跳转到home页
name: homeName // 跳转到homeName页
})
} else {
if (store.state.user.hasGetInfo) {
Expand Down
16 changes: 12 additions & 4 deletions src/store/module/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ export default {
state.breadCrumbList = getBreadCrumbList(route, state.homeRoute)
},
setTagNavList (state, list) {
let tagList = []
if (list) {
state.tagNavList = [...list]
setTagNavListInLocalstorage([...list])
} else state.tagNavList = getTagNavListFromLocalstorage()
tagList = [...list]
} else tagList = getTagNavListFromLocalstorage()
if (tagList[0].name !== homeName) tagList.shift()
let homeTagIndex = tagList.findIndex(item => item.name === homeName)
if (homeTagIndex !== 0) {
let homeTag = tagList.splice(homeTagIndex, 1)[0]
tagList.unshift(homeTag)
}
state.tagNavList = tagList
setTagNavListInLocalstorage([...tagList])
},
closeTag (state, route) {
let tag = state.tagNavList.filter(item => routeEqual(item, route))
Expand All @@ -64,7 +72,7 @@ export default {
if (!routeHasExist(state.tagNavList, router)) {
if (type === 'push') state.tagNavList.push(router)
else {
if (router.name === 'home') state.tagNavList.unshift(router)
if (router.name === homeName) state.tagNavList.unshift(router)
else state.tagNavList.splice(1, 0, router)
}
setTagNavListInLocalstorage([...state.tagNavList])
Expand Down
2 changes: 1 addition & 1 deletion src/view/error-page/back-btn-group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
methods: {
backHome () {
this.$router.replace({
name: 'home'
name: this.$config.homeName
})
},
backPrev () {
Expand Down
2 changes: 1 addition & 1 deletion src/view/login/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
this.handleLogin({ userName, password }).then(res => {
this.getUserInfo().then(res => {
this.$router.push({
name: 'home'
name: this.$config.homeName
})
})
})
Expand Down

0 comments on commit 0425a69

Please sign in to comment.