Browse Source

动态菜单路由完成

daxiongYang 7 years ago
parent
commit
b5175bf16c

+ 3 - 3
src/main.js

@ -9,7 +9,7 @@ import '@/element-ui'
9 9
import '@/icons'
10 10
import '@/assets/scss/index.scss'
11 11
12
import http from '@/utils/http'
12
import httpRequest from '@/utils/httpRequest'
13 13
import { isAuth } from '@/utils'
14 14
15 15
Vue.use(VueCookie)
@ -20,8 +20,8 @@ if (process.env.NODE_ENV !== 'production') {
20 20
  require('@/mock')
21 21
}
22 22
23
Vue.prototype.$http = http    // 挂载, ajax请求方法
24
Vue.prototype.isAuth = isAuth // 挂载, 权限方法
23
Vue.prototype.$http = httpRequest // 挂载, ajax请求方法
24
Vue.prototype.isAuth = isAuth     // 挂载, 权限方法
25 25
26 26
/* eslint-disable no-new */
27 27
new Vue({

+ 1 - 1
src/mock/create.js

@ -1,5 +1,5 @@
1 1
import Mock from 'mockjs'
2
import http from '@/utils/http'
2
import http from '@/utils/httpRequest'
3 3
import merge from 'lodash/merge'
4 4
5 5
/**

+ 37 - 18
src/router/index.js

@ -6,7 +6,8 @@
6 6
 */
7 7
import Vue from 'vue'
8 8
import Router from 'vue-router'
9
import http from '@/utils/http'
9
import http from '@/utils/httpRequest'
10
import { isURL } from '@/utils/validate'
10 11
11 12
Vue.use(Router)
12 13
@ -15,8 +16,8 @@ const _import = require('./import-' + process.env.NODE_ENV)
15 16
16 17
// 全局路由(无需嵌套上左右整体布局)
17 18
const globalRoutes = [
18
  { path: '/404', component: _import('common/404'), name: '404', desc: '404未找到' },
19
  { path: '/login', component: _import('common/login'), name: 'login', desc: '登录' }
19
  { path: '/404', component: _import('common/404'), name: '404', meta: { title: '404未找到' } },
20
  { path: '/login', component: _import('common/login'), name: 'login', meta: { title: '登录' } }
20 21
]
21 22
22 23
// 主入口路由(需嵌套上左右整体布局)
@ -25,10 +26,23 @@ const mainRoutes = {
25 26
  component: _import('main'),
26 27
  name: 'main',
27 28
  redirect: { name: 'home' },
28
  desc: '主入口整体布局',
29
  meta: { title: '主入口整体布局' },
29 30
  children: [
30
    { path: '/home', component: _import('common/home'), name: 'home', desc: '首页' },
31
    { path: '/theme', component: _import('common/theme'), name: 'theme', desc: '主题' }
31
    // 通过meta对象设置路由展示方式
32
    // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
33
    // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
34
    { path: '/home', component: _import('common/home'), name: 'home', meta: { title: '首页' } },
35
    { path: '/theme', component: _import('common/theme'), name: 'theme', meta: { title: '主题' } },
36
    {
37
      path: '/demo-01',
38
      component: null, // 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
39
      name: 'demo-01',
40
      meta: {
41
        title: '我是一个通过iframe嵌套展示内容, 并通过tab打开 demo',
42
        isTab: true,
43
        iframeUrl: 'http://fast.demo.renren.io/'
44
      }
45
    }
32 46
  ],
33 47
  beforeEnter (to, from, next) {
34 48
    let token = Vue.cookie.get('token')
@ -42,7 +56,7 @@ const mainRoutes = {
42 56
const router = new Router({
43 57
  mode: 'hash',
44 58
  scrollBehavior: () => ({ y: 0 }),
45
  isAddDynamicRoutes: false, // 是否已经添加动态(菜单)路由
59
  isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
46 60
  routes: globalRoutes.concat(mainRoutes)
47 61
})
48 62
@ -50,7 +64,7 @@ router.beforeEach((to, from, next) => {
50 64
  // 添加动态(菜单)路由
51 65
  // 1. 已经添加 or 全局路由, 直接访问
52 66
  // 2. 获取菜单列表, 添加并保存本地存储
53
  if (router.options.isAddDynamicRoutes || fnCurrentRouteType(to) === 'global') {
67
  if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to) === 'global') {
54 68
    next()
55 69
  } else {
56 70
    http({
@ -59,8 +73,8 @@ router.beforeEach((to, from, next) => {
59 73
      params: http.adornParams()
60 74
    }).then(({data}) => {
61 75
      if (data && data.code === 0) {
62
        fnAddDynamicRoutes(data.menuList)
63
        router.options.isAddDynamicRoutes = true
76
        fnAddDynamicMenuRoutes(data.menuList)
77
        router.options.isAddDynamicMenuRoutes = true
64 78
        sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]'))
65 79
        sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]'))
66 80
      } else {
@ -93,7 +107,7 @@ function fnCurrentRouteType (route) {
93 107
 * @param {*} menuList 菜单列表
94 108
 * @param {*} routes 递归创建的动态(菜单)路由
95 109
 */
96
function fnAddDynamicRoutes (menuList = [], routes = []) {
110
function fnAddDynamicMenuRoutes (menuList = [], routes = []) {
97 111
  var temp = []
98 112
  for (var i = 0; i < menuList.length; i++) {
99 113
    if (menuList[i].list && menuList[i].list.length >= 1) {
@ -103,14 +117,19 @@ function fnAddDynamicRoutes (menuList = [], routes = []) {
103 117
        path: menuList[i].url.replace('/', '-'),
104 118
        component: null,
105 119
        name: menuList[i].url.replace('/', '-'),
106
        desc: menuList[i].name,
107
        meta: { menuId: menuList[i].menuId, isTab: true }
120
        meta: {
121
          menuId: menuList[i].menuId,
122
          title: menuList[i].name,
123
          isDynamic: true,
124
          isTab: true,
125
          iframeUrl: ''
126
        }
108 127
      }
109
      // url以http[s]?开头, 通过iframe展示
110
      if (/^http[s]?:\/\/.*/.test(menuList[i].url)) {
128
      // url以http[s]://开头, 通过iframe展示
129
      if (isURL(menuList[i].url)) {
111 130
        route['path'] = `i-${menuList[i].menuId}`
112 131
        route['name'] = `i-${menuList[i].menuId}`
113
        route['meta']['isIframe'] = true
132
        route['meta']['iframeUrl'] = menuList[i].url
114 133
      } else {
115 134
        try {
116 135
          route['component'] = _import(`modules/${menuList[i].url}`) || null
@ -120,7 +139,7 @@ function fnAddDynamicRoutes (menuList = [], routes = []) {
120 139
    }
121 140
  }
122 141
  if (temp.length >= 1) {
123
    fnAddDynamicRoutes(temp, routes)
142
    fnAddDynamicMenuRoutes(temp, routes)
124 143
  } else {
125 144
    mainRoutes.name = 'main-dynamic'
126 145
    mainRoutes.children = routes
@ -128,7 +147,7 @@ function fnAddDynamicRoutes (menuList = [], routes = []) {
128 147
      mainRoutes,
129 148
      { path: '*', redirect: { name: '404' } }
130 149
    ])
131
    sessionStorage.setItem('dynamicRoutes', JSON.stringify(mainRoutes.children || '[]'))
150
    sessionStorage.setItem('dynamicMenuRoutes', JSON.stringify(mainRoutes.children || '[]'))
132 151
    console.log('\n%c!<-------------------- 动态(菜单)路由 s -------------------->', 'color:blue')
133 152
    console.log(mainRoutes.children)
134 153
    console.log('%c!<-------------------- 动态(菜单)路由 e -------------------->\n\n', 'color:blue')

src/utils/http.js → src/utils/httpRequest.js


+ 8 - 0
src/utils/validate.js

@ -21,3 +21,11 @@ export function isMobile (s) {
21 21
export function isPhone (s) {
22 22
  return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
23 23
}
24
25
/**
26
 * URL地址
27
 * @param {*} s
28
 */
29
export function isURL (s) {
30
  return /^http[s]?:\/\/.*/.test(s)
31
}

+ 126 - 0
src/views/main-content.vue

@ -0,0 +1,126 @@
1
<template>
2
  <main class="site-content" :class="{ 'site-content--tabs': $route.meta.isTab }">
3
    <!-- 主入口标签页 s -->
4
    <el-tabs
5
      v-if="$route.meta.isTab"
6
      v-model="mainTabsActiveName"
7
      :closable="true"
8
      @tab-click="selectedTabHandle"
9
      @tab-remove="removeTabHandle">
10
      <el-dropdown class="site-tabs__tools" :show-timeout="0">
11
        <i class="el-icon-arrow-down el-icon--right"></i>
12
        <el-dropdown-menu slot="dropdown">
13
          <el-dropdown-item @click.native="tabsCloseCurrentHandle">关闭当前标签页</el-dropdown-item>
14
          <el-dropdown-item @click.native="tabsCloseOtherHandle">关闭其它标签页</el-dropdown-item>
15
          <el-dropdown-item @click.native="tabsCloseAllHandle">关闭全部标签页</el-dropdown-item>
16
          <el-dropdown-item @click.native="tabsRefreshCurrentHandle">刷新当前标签页</el-dropdown-item>
17
        </el-dropdown-menu>
18
      </el-dropdown>
19
      <el-tab-pane
20
        v-for="item in mainTabs"
21
        :key="item.name"
22
        :label="item.title"
23
        :name="item.name">
24
        <el-card :body-style="siteContentViewHeight">
25
          <iframe
26
            v-if="item.type === 'iframe'"
27
            :src="item.iframeUrl"
28
            width="100%" height="100%" frameborder="0" scrolling="yes">
29
          </iframe>
30
          <keep-alive v-else>
31
            <router-view v-if="item.name === mainTabsActiveName" />
32
          </keep-alive>
33
        </el-card>
34
      </el-tab-pane>
35
    </el-tabs>
36
    <!-- 主入口标签页 e -->
37
    <el-card v-else :body-style="siteContentViewHeight">
38
      <keep-alive>
39
        <router-view />
40
      </keep-alive>
41
    </el-card>
42
  </main>
43
</template>
44
45
<script>
46
  import { isURL } from '@/utils/validate'
47
  export default {
48
    data () {
49
      return {
50
      }
51
    },
52
    computed: {
53
      documentClientHeight: {
54
        get () { return this.$store.state.common.documentClientHeight }
55
      },
56
      menuActiveName: {
57
        get () { return this.$store.state.common.menuActiveName },
58
        set (val) { this.$store.commit('common/updateMenuActiveName', val) }
59
      },
60
      mainTabs: {
61
        get () { return this.$store.state.common.mainTabs },
62
        set (val) { this.$store.commit('common/updateMainTabs', val) }
63
      },
64
      mainTabsActiveName: {
65
        get () { return this.$store.state.common.mainTabsActiveName },
66
        set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
67
      },
68
      siteContentViewHeight () {
69
        var height = this.documentClientHeight - 50 - 30 - 2
70
        if (this.$route.meta.isTab) {
71
          height -= 40
72
          return isURL(this.$route.meta.iframeUrl) ? { height: height + 'px' } : { minHeight: height + 'px' }
73
        }
74
        return { minHeight: height + 'px' }
75
      }
76
    },
77
    methods: {
78
      // tabs, 选中tab
79
      selectedTabHandle (tab) {
80
        tab = this.mainTabs.filter(item => item.name === tab.name)
81
        if (tab.length >= 1) {
82
          this.$router.push({ name: tab[0].name })
83
        }
84
      },
85
      // tabs, 删除tab
86
      removeTabHandle (tabName) {
87
        var newTabs = this.mainTabs.filter(item => item.name !== tabName)
88
        if (newTabs.length >= 1) {
89
          // 当前选中tab被删除
90
          if (tabName === this.mainTabsActiveName) {
91
            this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
92
              this.mainTabsActiveName = this.$route.name
93
            })
94
          }
95
          this.mainTabs = newTabs
96
        } else {
97
          this.menuActiveName = ''
98
          this.$router.push({ name: 'home' })
99
        }
100
      },
101
      // tabs, 关闭当前
102
      tabsCloseCurrentHandle () {
103
        this.removeTabHandle(this.mainTabsActiveName)
104
      },
105
      // tabs, 关闭其它
106
      tabsCloseOtherHandle () {
107
        this.mainTabs = this.mainTabs.filter(item => item.name === this.mainTabsActiveName)
108
      },
109
      // tabs, 关闭全部
110
      tabsCloseAllHandle () {
111
        this.mainTabs = []
112
        this.menuActiveName = ''
113
        this.$router.push({ name: 'home' })
114
      },
115
      // tabs, 刷新当前
116
      tabsRefreshCurrentHandle () {
117
        var tempTabName = this.mainTabsActiveName
118
        this.removeTabHandle(tempTabName)
119
        this.$nextTick(() => {
120
          this.$router.push({ name: tempTabName })
121
        })
122
      }
123
    }
124
  }
125
</script>
126

+ 3 - 3
src/views/main-sidebar-sub-menu.vue

@ -8,7 +8,7 @@
8 8
      v-for="item in menu.list" 
9 9
      :key="item.menuId"
10 10
      :menu="item"
11
      :dynamicRoutes="dynamicRoutes">
11
      :dynamicMenuRoutes="dynamicMenuRoutes">
12 12
    </sub-menu>
13 13
  </el-submenu>
14 14
  <el-menu-item v-else :index="menu.menuId + ''" @click="gotoRouteHandle(menu)">
@ -26,7 +26,7 @@
26 26
        type: Object,
27 27
        required: true
28 28
      },
29
      dynamicRoutes: {
29
      dynamicMenuRoutes: {
30 30
        type: Array,
31 31
        required: true
32 32
      }
@ -37,7 +37,7 @@
37 37
    methods: {
38 38
      // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
39 39
      gotoRouteHandle (menu) {
40
        var route = this.dynamicRoutes.filter(item => item.meta.menuId === menu.menuId)
40
        var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.menuId)
41 41
        if (route.length >= 1) {
42 42
          this.$router.push({ name: route[0].name })
43 43
        }

+ 35 - 42
src/views/main-sidebar.vue

@ -2,19 +2,23 @@
2 2
  <aside class="site-sidebar" :class="sidebarClasses">
3 3
    <div class="site-sidebar__inner">
4 4
      <el-menu
5
        :default-active="menuActiveName"
5
        :default-active="menuActiveName || 'home'"
6 6
        :collapse="sidebarFold"
7 7
        :collapseTransition="false"
8 8
        class="site-sidebar__menu">
9
        <el-menu-item index="1-1" @click="$router.push({ name: 'home' })">
9
        <el-menu-item index="home" @click="$router.push({ name: 'home' })">
10 10
          <icon-svg name="shouye" class="site-sidebar__menu-icon"></icon-svg>
11 11
          <span slot="title">首页</span>
12 12
        </el-menu-item>
13
        <el-menu-item index="demo-01" @click="$router.push({ name: 'demo-01' })">
14
          <icon-svg name="mudedi" class="site-sidebar__menu-icon"></icon-svg>
15
          <span slot="title">demo-01</span>
16
        </el-menu-item>
13 17
        <sub-menu
14 18
          v-for="menu in menuList" 
15 19
          :key="menu.menuId"
16 20
          :menu="menu"
17
          :dynamicRoutes="dynamicRoutes">
21
          :dynamicMenuRoutes="dynamicMenuRoutes">
18 22
        </sub-menu>
19 23
      </el-menu>
20 24
    </div>
@ -23,11 +27,11 @@
23 27
24 28
<script>
25 29
  import SubMenu from './main-sidebar-sub-menu'
26
  import isEmpty from 'lodash/isEmpty'
30
  import { isURL } from '@/utils/validate'
27 31
  export default {
28 32
    data () {
29 33
      return {
30
        dynamicRoutes: []
34
        dynamicMenuRoutes: []
31 35
      }
32 36
    },
33 37
    components: {
@ -45,10 +49,7 @@
45 49
        set (val) { this.$store.commit('common/updateMenuList', val) }
46 50
      },
47 51
      menuActiveName: {
48
        get () {
49
          let name = this.$store.state.common.menuActiveName
50
          return /\S/.test(name) ? name : '1-1'
51
        },
52
        get () { return this.$store.state.common.menuActiveName },
52 53
        set (val) { this.$store.commit('common/updateMenuActiveName', val) }
53 54
      },
54 55
      mainTabs: {
@ -66,46 +67,38 @@
66 67
      }
67 68
    },
68 69
    watch: {
69
      '$route' (route) {
70
        if (route.meta.isTab) {
71
          var tab = this.mainTabs.filter(item => item.name === route.name)[0]
72
          // tab不存在, 先添加
73
          if (isEmpty(tab)) {
74
            var menu = this.getMenuByRouteName(route.name, this.menuList)
75
            if (!isEmpty(menu)) {
76
              tab = {
77
                id: menu.menuId,
78
                name: route.name,
79
                title: menu.name,
80
                type: (window.SITE_CONFIG.nestIframeRouteNameList || []).indexOf(route.name) !== -1 ? 'iframe' : 'module',
81
                url: menu.url
82
              }
83
              this.mainTabs = this.mainTabs.concat(tab)
84
            } else {
85
              return console.error('未能找到可用标签页!')
86
            }
87
          }
88
          this.menuActiveName = tab.id + ''
89
          this.mainTabsActiveName = route.name
90
        }
91
      }
70
      $route: 'routeHandle'
92 71
    },
93 72
    created () {
94 73
      this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]')
95
      this.dynamicRoutes = JSON.parse(sessionStorage.getItem('dynamicRoutes') || '[]')
74
      this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]')
75
      this.routeHandle(this.$route)
96 76
    },
97 77
    methods: {
98
      // 获取菜单, 根据路由名称
99
      getMenuByRouteName (name, menuList) {
100
        var temp = []
101
        for (var i = 0; i < menuList.length; i++) {
102
          if (menuList[i].list && menuList[i].list.length >= 1) {
103
            temp = temp.concat(menuList[i].list)
104
          } else if (menuList[i].url === name) {
105
            return menuList[i]
78
      // 路由操作
79
      routeHandle (route) {
80
        if (route.meta.isTab) {
81
          // tab选中, 不存在先添加
82
          var tab = this.mainTabs.filter(item => item.name === route.name)[0]
83
          if (!tab) {
84
            if (route.meta.isDynamic) {
85
              route = this.dynamicMenuRoutes.filter(item => item.name === route.name)[0]
86
              if (!route) {
87
                return console.error('未能找到可用标签页!')
88
              }
89
            }
90
            tab = {
91
              menuId: route.meta.menuId || route.name,
92
              name: route.name,
93
              title: route.meta.title,
94
              type: isURL(route.meta.iframeUrl) ? 'iframe' : 'module',
95
              iframeUrl: route.meta.iframeUrl || ''
96
            }
97
            this.mainTabs = this.mainTabs.concat(tab)
106 98
          }
99
          this.menuActiveName = tab.menuId + ''
100
          this.mainTabsActiveName = tab.name
107 101
        }
108
        return temp.length >= 1 ? this.getMenuByRouteName(name, temp) : []
109 102
      }
110 103
    }
111 104
  }

+ 4 - 109
src/views/main.vue

@ -8,47 +8,7 @@
8 8
      <main-navbar />
9 9
      <main-sidebar />
10 10
      <div class="site-content__wrapper" :style="{ 'min-height': documentClientHeight + 'px' }">
11
        <main class="site-content" :class="{ 'site-content--tabs': $route.meta.isTab }">
12
          <!-- 主入口标签页 s -->
13
          <el-tabs
14
            v-if="$route.meta.isTab"
15
            v-model="mainTabsActiveName"
16
            :closable="true"
17
            @tab-click="selectedTabHandle"
18
            @tab-remove="removeTabHandle">
19
            <el-dropdown class="site-tabs__tools" :show-timeout="0">
20
              <i class="el-icon-arrow-down el-icon--right"></i>
21
              <el-dropdown-menu slot="dropdown">
22
                <el-dropdown-item @click.native="tabsCloseCurrentHandle">关闭当前标签页</el-dropdown-item>
23
                <el-dropdown-item @click.native="tabsCloseOtherHandle">关闭其它标签页</el-dropdown-item>
24
                <el-dropdown-item @click.native="tabsCloseAllHandle">关闭全部标签页</el-dropdown-item>
25
                <el-dropdown-item @click.native="tabsRefreshCurrentHandle">刷新当前标签页</el-dropdown-item>
26
              </el-dropdown-menu>
27
            </el-dropdown>
28
            <el-tab-pane
29
              v-for="item in mainTabs"
30
              :key="item.name"
31
              :label="item.title"
32
              :name="item.name">
33
              <el-card :style="siteContentViewHeight">
34
                <iframe
35
                  v-if="item.type === 'iframe'"
36
                  :src="item.url"
37
                  width="100%" height="100%" frameborder="0" scrolling="yes">
38
                </iframe>
39
                <keep-alive v-else>
40
                  <router-view v-if="item.name === mainTabsActiveName" />
41
                </keep-alive>
42
              </el-card>
43
            </el-tab-pane>
44
          </el-tabs>
45
          <!-- 主入口标签页 e -->
46
          <el-card v-else :style="siteContentViewHeight">
47
            <keep-alive>
48
              <router-view />
49
            </keep-alive>
50
          </el-card>
51
        </main>
11
        <main-content />
52 12
      </div>
53 13
    </template>
54 14
  </div>
@ -57,7 +17,7 @@
57 17
<script>
58 18
  import MainNavbar from './main-navbar'
59 19
  import MainSidebar from './main-sidebar'
60
  import isEmpty from 'lodash/isEmpty'
20
  import MainContent from './main-content'
61 21
  export default {
62 22
    data () {
63 23
      return {
@ -66,7 +26,8 @@
66 26
    },
67 27
    components: {
68 28
      MainNavbar,
69
      MainSidebar
29
      MainSidebar,
30
      MainContent
70 31
    },
71 32
    computed: {
72 33
      documentClientHeight: {
@ -76,18 +37,6 @@
76 37
      sidebarFold: {
77 38
        get () { return this.$store.state.common.sidebarFold }
78 39
      },
79
      menuActiveName: {
80
        get () { return this.$store.state.common.menuActiveName },
81
        set (val) { this.$store.commit('common/updateMenuActiveName', val) }
82
      },
83
      mainTabs: {
84
        get () { return this.$store.state.common.mainTabs },
85
        set (val) { this.$store.commit('common/updateMainTabs', val) }
86
      },
87
      mainTabsActiveName: {
88
        get () { return this.$store.state.common.mainTabsActiveName },
89
        set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
90
      },
91 40
      userId: {
92 41
        get () { return this.$store.state.user.id },
93 42
        set (val) { this.$store.commit('user/updateId', val) }
@ -95,14 +44,6 @@
95 44
      userName: {
96 45
        get () { return this.$store.state.user.name },
97 46
        set (val) { this.$store.commit('user/updateName', val) }
98
      },
99
      siteContentViewHeight () {
100
        var height = this.documentClientHeight - 50 - 30 - 2
101
        if (this.$route.meta.isTab) {
102
          height -= 40
103
          return this.$route.meta.isIframe ? { height: height + 'px' } : { minHeight: height + 'px' }
104
        }
105
        return { minHeight: height + 'px' }
106 47
      }
107 48
    },
108 49
    created () {
@ -128,56 +69,10 @@
128 69
        }).then(({data}) => {
129 70
          if (data && data.code === 0) {
130 71
            this.loading = false
131
            this.mainTabs = []
132 72
            this.userId = data.user.userId
133 73
            this.userName = data.user.username
134 74
          }
135 75
        })
136
      },
137
      // tabs, 选中tab
138
      selectedTabHandle (tab) {
139
        tab = this.mainTabs.filter(item => item.name === tab.name)
140
        if (!isEmpty(tab)) {
141
          this.$router.push({ name: tab[0].name })
142
        }
143
      },
144
      // tabs, 删除tab
145
      removeTabHandle (tabName) {
146
        var newTabs = this.mainTabs.filter(item => item.name !== tabName)
147
        if (newTabs.length <= 0) {
148
          this.menuActiveName = ''
149
          this.$router.push({ name: 'home' })
150
        } else {
151
          // 当前选中tab被删除
152
          if (tabName === this.mainTabsActiveName) {
153
            this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
154
              this.mainTabsActiveName = this.$route.name
155
            })
156
          }
157
          this.mainTabs = newTabs
158
        }
159
      },
160
      // tabs, 关闭当前
161
      tabsCloseCurrentHandle () {
162
        this.removeTabHandle(this.mainTabsActiveName)
163
      },
164
      // tabs, 关闭其它
165
      tabsCloseOtherHandle () {
166
        this.mainTabs = this.mainTabs.filter(item => item.name === this.mainTabsActiveName)
167
      },
168
      // tabs, 关闭全部
169
      tabsCloseAllHandle () {
170
        this.mainTabs = []
171
        this.menuActiveName = ''
172
        this.$router.push({ name: 'home' })
173
      },
174
      // tabs, 刷新当前
175
      tabsRefreshCurrentHandle () {
176
        var tempTabName = this.mainTabsActiveName
177
        this.removeTabHandle(tempTabName)
178
        this.$nextTick(() => {
179
          this.$router.push({ name: tempTabName })
180
        })
181 76
      }
182 77
    }
183 78
  }