Browse Source

新增内容tabs标签页,关闭当前/其它/全部、刷新当前功能

daxiongYang 7 years ago
parent
commit
17c05ea398

+ 18 - 0
CHANGELOG.md

1
## 更新日志
2
3
### 1.1.0
4
5
*待定*
6
7
- 更新element-ui 2.2.1 用于修复tree半选中状态项不能传给后台接口问题
8
- 修复本地开发找不到baseUrl问题
9
- 新增Mock本地开发模拟数据功能
10
- 更新element-ui 2.3.2 用于修复左侧菜单收缩卡顿问题
11
- 优化路由机制,通过meta isTab属性, 设定是否通过tab标签页展示内容
12
- 新增scss变量皮肤定制
13
- 新增内容tabs标签页,关闭当前/其它/全部、刷新当前功能
14
- 修复其它已知bug
15
16
### 1.0.0
17
18
*2018-02-11*

+ 20 - 3
src/assets/scss/_base.scss

258
258
259
  &--dark {
259
  &--dark {
260
    background-color: $sidebar--background-color-dark;
260
    background-color: $sidebar--background-color-dark;
261
262
    .site-sidebar__menu.el-menu {
261
    .site-sidebar__menu.el-menu {
263
      background-color: $sidebar--background-color-dark;
262
      background-color: $sidebar--background-color-dark;
264
      .el-menu-item,
263
      .el-menu-item,
280
      }
279
      }
281
    }
280
    }
282
  }
281
  }
283
284
  &__inner {
282
  &__inner {
285
    position: relative;
283
    position: relative;
286
    z-index: 1;
284
    z-index: 1;
319
  &--tabs {
317
  &--tabs {
320
    padding: 55px 0 0;
318
    padding: 55px 0 0;
321
  }
319
  }
320
  .site-tabs__tools {
321
    position: fixed;
322
    top: 50px;
323
    right: 0;
324
    z-index: 931;
325
    height: 40px;
326
    padding: 0 12px;
327
    font-size: 16px;
328
    line-height: 40px;
329
    background-color: $content--background-color;
330
    cursor: pointer;
331
    .el-icon--right {
332
      margin-left: 0;
333
    }
334
  }
322
  > .el-tabs {
335
  > .el-tabs {
323
    .el-tabs__header {
336
    .el-tabs__header {
324
      position: fixed;
337
      position: fixed;
326
      left: 230px;
339
      left: 230px;
327
      right: 0;
340
      right: 0;
328
      z-index: 930;
341
      z-index: 930;
329
      padding: 0 15px;
342
      padding: 0 55px 0 15px;
330
      box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
343
      box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
331
      background-color: #fff;
344
      background-color: #fff;
332
    }
345
    }
341
    }
354
    }
342
  }
355
  }
343
}
356
}
357
358
359
/* Dropdown
360
------------------------------ */

+ 4 - 0
src/assets/scss/_variables.scss

7
7
8
// ---------- #1 ----------
8
// ---------- #1 ----------
9
$--color-primary: #17b3a3;
9
$--color-primary: #17b3a3;
10
$--color-success: #67c23a;
11
$--color-warning: #e6a23c;
12
$--color-danger: #f56c6c;
13
$--color-info: #909399;
10
$--color-text-primary: #303133;
14
$--color-text-primary: #303133;
11
15
12
16

+ 2 - 1
src/store/index.js

11
  // 导航条, 布局风格, defalut(默认) / inverse(反向)
11
  // 导航条, 布局风格, defalut(默认) / inverse(反向)
12
  navbarLayoutType: 'default',
12
  navbarLayoutType: 'default',
13
  // 侧边栏, 布局皮肤, light(浅色) / dark(黑色)
13
  // 侧边栏, 布局皮肤, light(浅色) / dark(黑色)
14
  sidebarLayoutSkin: 'light',
14
  sidebarLayoutSkin: 'dark',
15
  // 侧边栏, 水平折叠收起状态
15
  // 侧边栏, 水平折叠收起状态
16
  sidebarCollapse: false,
16
  sidebarCollapse: false,
17
  // 页面文档可视高度(随窗口改变大小)
17
  // 页面文档可视高度(随窗口改变大小)
18
  documentClientHeight: 0,
18
  documentClientHeight: 0,
19
  // 菜单导航
19
  // 菜单导航
20
  menuNavList: [],
20
  menuNavList: [],
21
  menuNavActiveName: '1-1',
21
  // 内容区域tabs标签页
22
  // 内容区域tabs标签页
22
  contentTabs: [],
23
  contentTabs: [],
23
  contentTabsActiveName: ''
24
  contentTabsActiveName: ''

+ 1 - 0
src/store/mutation-types.js

4
export const SWITCH_SIDEBAR_COLLAPSE = 'SWITCH_SIDEBAR_COLLAPSE'
4
export const SWITCH_SIDEBAR_COLLAPSE = 'SWITCH_SIDEBAR_COLLAPSE'
5
export const UPDATE_DOCUMENT_CLIENT_HEIGHT = 'UPDATE_DOCUMENT_CLIENT_HEIGHT'
5
export const UPDATE_DOCUMENT_CLIENT_HEIGHT = 'UPDATE_DOCUMENT_CLIENT_HEIGHT'
6
export const UPDATE_MENU_NAV_LIST = 'UPDATE_MENU_NAV_LIST'
6
export const UPDATE_MENU_NAV_LIST = 'UPDATE_MENU_NAV_LIST'
7
export const UPDATE_MENU_NAV_ACTIVE_NAME = 'UPDATE_MENU_NAV_ACTIVE_NAME'
7
export const ADD_CONTENT_TAB = 'ADD_CONTENT_TAB'
8
export const ADD_CONTENT_TAB = 'ADD_CONTENT_TAB'
8
export const UPDATE_CONTENT_TABS = 'UPDATE_CONTENT_TABS'
9
export const UPDATE_CONTENT_TABS = 'UPDATE_CONTENT_TABS'
9
export const DELETE_CONTENT_TABS = 'DELETE_CONTENT_TABS'
10
export const DELETE_CONTENT_TABS = 'DELETE_CONTENT_TABS'

+ 4 - 0
src/store/mutations.js

19
    state.menuNavList = list
19
    state.menuNavList = list
20
  },
20
  },
21
21
22
  [types.UPDATE_MENU_NAV_ACTIVE_NAME] (state, { name }) {
23
    state.menuNavActiveName = name
24
  },
25
22
  [types.ADD_CONTENT_TAB] (state, tab) {
26
  [types.ADD_CONTENT_TAB] (state, tab) {
23
    state.contentTabs.push(tab)
27
    state.contentTabs.push(tab)
24
  },
28
  },

+ 40 - 5
src/views/layout/content-tabs.vue

1
<template>
1
<template>
2
  <el-tabs
2
  <el-tabs
3
    v-model="tabActiveName"
3
    v-model="tabActiveName"
4
    :closable="$store.state.contentTabs.length > 1"
4
    :closable="true"
5
    @tab-click="selectedTabHandle"
5
    @tab-click="selectedTabHandle"
6
    @tab-remove="removeTabHandle">
6
    @tab-remove="removeTabHandle">
7
    <el-tab-pane
7
    <el-tab-pane
20
        </keep-alive>
20
        </keep-alive>
21
      </el-card>
21
      </el-card>
22
    </el-tab-pane>
22
    </el-tab-pane>
23
    
24
    <!-- tabs tools -->
25
    <el-dropdown class="site-tabs__tools" @command="toolsCommandHandle" :show-timeout="0">
26
      <i class="el-icon-arrow-down el-icon--right"></i>
27
      <el-dropdown-menu slot="dropdown">
28
        <el-dropdown-item command="closeCurrent">关闭当前标签页</el-dropdown-item>
29
        <el-dropdown-item command="closeOther">关闭其它标签页</el-dropdown-item>
30
        <el-dropdown-item command="closeAll">关闭全部标签页</el-dropdown-item>
31
        <el-dropdown-item command="refreshCurrent">刷新当前标签页</el-dropdown-item>
32
      </el-dropdown-menu>
33
    </el-dropdown>
23
  </el-tabs>
34
  </el-tabs>
24
</template>
35
</template>
25
36
36
        get () {
47
        get () {
37
          return this.$store.state.contentTabsActiveName
48
          return this.$store.state.contentTabsActiveName
38
        },
49
        },
39
        set (val) {
40
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: val })
50
        set (name) {
51
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name })
52
        }
53
      }
54
    },
55
    watch: {
56
      '$store.state.contentTabs' (tabs) {
57
        if (tabs.length <= 0) {
58
          this.UPDATE_MENU_NAV_ACTIVE_NAME({ name: '' })
59
          this.$router.push({ name: 'home' })
41
        }
60
        }
42
      }
61
      }
43
    },
62
    },
70
      removeTabHandle (tabName) {
89
      removeTabHandle (tabName) {
71
        var newTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
90
        var newTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
72
        // 当前选中tab被删除
91
        // 当前选中tab被删除
73
        if (tabName === this.tabActiveName) {
92
        if (newTabs.length >= 1 && tabName === this.tabActiveName) {
74
          this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
93
          this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
75
            this.tabActiveName = this.$route.name
94
            this.tabActiveName = this.$route.name
76
          })
95
          })
77
        }
96
        }
78
        this.UPDATE_CONTENT_TABS(newTabs)
97
        this.UPDATE_CONTENT_TABS(newTabs)
79
      },
98
      },
80
      ...mapMutations(['UPDATE_CONTENT_TABS', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
99
      // 工具操作
100
      toolsCommandHandle (command) {
101
        if (command === 'closeCurrent') {
102
          this.removeTabHandle(this.tabActiveName)
103
        } else if (command === 'closeOther') {
104
          this.UPDATE_CONTENT_TABS(this.$store.state.contentTabs.filter(item => item.name === this.tabActiveName))
105
        } else if (command === 'closeAll') {
106
          this.DELETE_CONTENT_TABS()
107
        } else if (command === 'refreshCurrent') {
108
          var tempTabName = this.tabActiveName
109
          this.removeTabHandle(tempTabName)
110
          this.$nextTick(() => {
111
            this.$router.push({ name: tempTabName })
112
          })
113
        }
114
      },
115
      ...mapMutations(['UPDATE_MENU_NAV_ACTIVE_NAME', 'UPDATE_CONTENT_TABS', 'UPDATE_CONTENT_TABS_ACTIVE_NAME', 'DELETE_CONTENT_TABS'])
81
    }
116
    }
82
  }
117
  }
83
</script>
118
</script>

+ 1 - 1
src/views/layout/index.vue

80
        API.user.info().then(({data}) => {
80
        API.user.info().then(({data}) => {
81
          if (data && data.code === 0) {
81
          if (data && data.code === 0) {
82
            this.loading = false
82
            this.loading = false
83
            this.DELETE_CONTENT_TABS([])
83
            this.DELETE_CONTENT_TABS()
84
            this.UPDATE_USER_ID({ id: data.user.userId })
84
            this.UPDATE_USER_ID({ id: data.user.userId })
85
            this.UPDATE_USER_NAME({ name: data.user.username })
85
            this.UPDATE_USER_NAME({ name: data.user.username })
86
          }
86
          }

+ 3 - 3
src/views/layout/navbar.vue

36
          <el-menu-item index="2-3"><a href="//git.oschina.net/renrenio/renren-generator" target="_blank">代码生成器</a></el-menu-item>
36
          <el-menu-item index="2-3"><a href="//git.oschina.net/renrenio/renren-generator" target="_blank">代码生成器</a></el-menu-item>
37
        </el-submenu>
37
        </el-submenu>
38
        <el-menu-item class="site-navbar__avatar" index="3">
38
        <el-menu-item class="site-navbar__avatar" index="3">
39
          <el-dropdown placement="bottom" :hide-on-click="false">
39
          <el-dropdown :show-timeout="0" placement="bottom">
40
            <span class="el-dropdown-link">
40
            <span class="el-dropdown-link">
41
              <img src="~@/assets/img/avatar.png" :alt="$store.state.user.name">
41
              <img src="~@/assets/img/avatar.png" :alt="$store.state.user.name">
42
              {{ $store.state.user.name }}
42
              {{ $store.state.user.name }}
96
        }).then(() => {
96
        }).then(() => {
97
          API.common.logout().then(({data}) => {
97
          API.common.logout().then(({data}) => {
98
            if (data && data.code === 0) {
98
            if (data && data.code === 0) {
99
              this.DELETE_CONTENT_TABS([])
99
              this.DELETE_CONTENT_TABS()
100
              this.$cookie.delete('token')
100
              this.$cookie.delete('token')
101
              this.$router.replace({ name: 'login' })
101
              this.$router.replace({ name: 'login' })
102
            }
102
            }
103
          })
103
          })
104
        })
104
        }).catch(() => {})
105
      },
105
      },
106
      ...mapMutations(['SWITCH_SIDEBAR_COLLAPSE', 'DELETE_CONTENT_TABS'])
106
      ...mapMutations(['SWITCH_SIDEBAR_COLLAPSE', 'DELETE_CONTENT_TABS'])
107
    }
107
    }

+ 12 - 4
src/views/layout/sidebar.vue

2
  <aside class="site-sidebar" :class="sidebarClasses">
2
  <aside class="site-sidebar" :class="sidebarClasses">
3
    <div class="site-sidebar__inner">
3
    <div class="site-sidebar__inner">
4
      <el-menu
4
      <el-menu
5
        :default-active="menuNavActive"
5
        :default-active="menuNavActiveName"
6
        :collapse="$store.state.sidebarCollapse"
6
        :collapse="$store.state.sidebarCollapse"
7
        :collapseTransition="false"
7
        :collapseTransition="false"
8
        class="site-sidebar__menu">
8
        class="site-sidebar__menu">
29
  export default {
29
  export default {
30
    data () {
30
    data () {
31
      return {
31
      return {
32
        menuNavActive: '1-1'
33
      }
32
      }
34
    },
33
    },
35
    components: {
34
    components: {
36
      SubMenuNav
35
      SubMenuNav
37
    },
36
    },
38
    computed: {
37
    computed: {
38
      menuNavActiveName: {
39
        get () {
40
          let name = this.$store.state.menuNavActiveName
41
          return /\S/.test(name) ? name : '1-1'
42
        },
43
        set (name) {
44
          this.UPDATE_MENU_NAV_ACTIVE_NAME({ name })
45
        }
46
      },
39
      sidebarClasses () {
47
      sidebarClasses () {
40
        let skin = this.$store.state.sidebarLayoutSkin
48
        let skin = this.$store.state.sidebarLayoutSkin
41
        return [
49
        return [
84
              return console.error('未能找到可用tab标签页!')
92
              return console.error('未能找到可用tab标签页!')
85
            }
93
            }
86
          }
94
          }
87
          this.menuNavActive = tab.id + ''
95
          this.menuNavActiveName = tab.id + ''
88
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: route.name })
96
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: route.name })
89
        }
97
        }
90
      },
98
      },
100
        }
108
        }
101
        return temp.length >= 1 ? this.getMenuNavByRouteName(name, temp) : []
109
        return temp.length >= 1 ? this.getMenuNavByRouteName(name, temp) : []
102
      },
110
      },
103
      ...mapMutations(['UPDATE_MENU_NAV_LIST', 'ADD_CONTENT_TAB', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
111
      ...mapMutations(['UPDATE_MENU_NAV_LIST', 'UPDATE_MENU_NAV_ACTIVE_NAME', 'ADD_CONTENT_TAB', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
104
    }
112
    }
105
  }
113
  }
106
</script>
114
</script>

+ 1 - 1
src/views/layout/update-password.vue

82
                  onClose: () => {
82
                  onClose: () => {
83
                    this.visible = false
83
                    this.visible = false
84
                    this.$nextTick(() => {
84
                    this.$nextTick(() => {
85
                      this.DELETE_CONTENT_TABS([])
85
                      this.DELETE_CONTENT_TABS()
86
                      this.$cookie.delete('token')
86
                      this.$cookie.delete('token')
87
                      this.$router.replace({ name: 'login' })
87
                      this.$router.replace({ name: 'login' })
88
                    })
88
                    })

+ 1 - 1
static/config/index-uat.js

4
;(function () {
4
;(function () {
5
  window.SITE_CONFIG = {}
5
  window.SITE_CONFIG = {}
6
  // api请求地址
6
  // api请求地址
7
  window.SITE_CONFIG.baseUrl = '//demo.renren.io/renren-fast/'
7
  window.SITE_CONFIG.baseUrl = '//dev.demo.renren.io/renren-fast/'
8
8
9
  // 嵌套iframe地址
9
  // 嵌套iframe地址
10
  window.SITE_CONFIG.nestIframeUrl = '//demo.renren.io/renren-fast/'
10
  window.SITE_CONFIG.nestIframeUrl = '//demo.renren.io/renren-fast/'