From 5223e771a5c06012f5399a1a5624caddd24bf982 Mon Sep 17 00:00:00 2001 From: "zhigang.li@tendcloud.com" Date: Wed, 10 Oct 2018 18:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=A6=96=E9=A1=B5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/components/tags-nav/tags-nav.vue | 8 +++--- src/components/main/main.vue | 27 +++++-------------- src/libs/util.js | 3 ++- src/router/index.js | 4 ++- src/store/module/app.js | 16 ++++++++--- src/view/error-page/back-btn-group.vue | 2 +- src/view/login/login.vue | 2 +- 7 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/components/main/components/tags-nav/tags-nav.vue b/src/components/main/components/tags-nav/tags-nav.vue index 242f83687..53676a26f 100644 --- a/src/components/main/components/tags-nav/tags-nav.vue +++ b/src/components/main/components/tags-nav/tags-nav.vue @@ -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) }} @@ -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) @@ -171,7 +171,7 @@ export default { }) }, contextMenu (item, e) { - if (item.name === 'home') { + if (item.name === this.$config.homeName) { return } this.visible = true diff --git a/src/components/main/main.vue b/src/components/main/main.vue index 40f90dbfe..0b8435288 100644 --- a/src/components/main/main.vue +++ b/src/components/main/main.vue @@ -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 + }) + } } } diff --git a/src/libs/util.js b/src/libs/util.js index 53f1613b7..7428e1f15 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -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 => { @@ -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 diff --git a/src/router/index.js b/src/router/index.js index 76acfdf8a..8c1c11433 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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({ @@ -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) { diff --git a/src/store/module/app.js b/src/store/module/app.js index 92f096e66..887a8b582 100644 --- a/src/store/module/app.js +++ b/src/store/module/app.js @@ -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)) @@ -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]) diff --git a/src/view/error-page/back-btn-group.vue b/src/view/error-page/back-btn-group.vue index 7292dc0ac..a5fe7fdd5 100644 --- a/src/view/error-page/back-btn-group.vue +++ b/src/view/error-page/back-btn-group.vue @@ -18,7 +18,7 @@ export default { methods: { backHome () { this.$router.replace({ - name: 'home' + name: this.$config.homeName }) }, backPrev () { diff --git a/src/view/login/login.vue b/src/view/login/login.vue index 7cd051878..7595e01b6 100755 --- a/src/view/login/login.vue +++ b/src/view/login/login.vue @@ -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 }) }) })