Przeglądaj źródła

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

daxiongYang 7 lat temu
rodzic
commit
17c05ea398

+ 18 - 0
CHANGELOG.md

@ -0,0 +1,18 @@
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,7 +258,6 @@ img {
258 258
259 259
  &--dark {
260 260
    background-color: $sidebar--background-color-dark;
261
262 261
    .site-sidebar__menu.el-menu {
263 262
      background-color: $sidebar--background-color-dark;
264 263
      .el-menu-item,
@ -280,7 +279,6 @@ img {
280 279
      }
281 280
    }
282 281
  }
283
284 282
  &__inner {
285 283
    position: relative;
286 284
    z-index: 1;
@ -319,6 +317,21 @@ img {
319 317
  &--tabs {
320 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 335
  > .el-tabs {
323 336
    .el-tabs__header {
324 337
      position: fixed;
@ -326,7 +339,7 @@ img {
326 339
      left: 230px;
327 340
      right: 0;
328 341
      z-index: 930;
329
      padding: 0 15px;
342
      padding: 0 55px 0 15px;
330 343
      box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
331 344
      background-color: #fff;
332 345
    }
@ -341,3 +354,7 @@ img {
341 354
    }
342 355
  }
343 356
}
357
358
359
/* Dropdown
360
------------------------------ */

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

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

+ 2 - 1
src/store/index.js

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

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

@ -4,6 +4,7 @@ export const SET_SIDEBAR_LAYOUT_SKIN = 'SET_SIDEBAR_LAYOUT_SKIN'
4 4
export const SWITCH_SIDEBAR_COLLAPSE = 'SWITCH_SIDEBAR_COLLAPSE'
5 5
export const UPDATE_DOCUMENT_CLIENT_HEIGHT = 'UPDATE_DOCUMENT_CLIENT_HEIGHT'
6 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 8
export const ADD_CONTENT_TAB = 'ADD_CONTENT_TAB'
8 9
export const UPDATE_CONTENT_TABS = 'UPDATE_CONTENT_TABS'
9 10
export const DELETE_CONTENT_TABS = 'DELETE_CONTENT_TABS'

+ 4 - 0
src/store/mutations.js

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

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

@ -1,7 +1,7 @@
1 1
<template>
2 2
  <el-tabs
3 3
    v-model="tabActiveName"
4
    :closable="$store.state.contentTabs.length > 1"
4
    :closable="true"
5 5
    @tab-click="selectedTabHandle"
6 6
    @tab-remove="removeTabHandle">
7 7
    <el-tab-pane
@ -20,6 +20,17 @@
20 20
        </keep-alive>
21 21
      </el-card>
22 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 34
  </el-tabs>
24 35
</template>
25 36
@ -36,8 +47,16 @@
36 47
        get () {
37 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,14 +89,30 @@
70 89
      removeTabHandle (tabName) {
71 90
        var newTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
72 91
        // 当前选中tab被删除
73
        if (tabName === this.tabActiveName) {
92
        if (newTabs.length >= 1 && tabName === this.tabActiveName) {
74 93
          this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
75 94
            this.tabActiveName = this.$route.name
76 95
          })
77 96
        }
78 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 118
</script>

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

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

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

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

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

@ -2,7 +2,7 @@
2 2
  <aside class="site-sidebar" :class="sidebarClasses">
3 3
    <div class="site-sidebar__inner">
4 4
      <el-menu
5
        :default-active="menuNavActive"
5
        :default-active="menuNavActiveName"
6 6
        :collapse="$store.state.sidebarCollapse"
7 7
        :collapseTransition="false"
8 8
        class="site-sidebar__menu">
@ -29,13 +29,21 @@
29 29
  export default {
30 30
    data () {
31 31
      return {
32
        menuNavActive: '1-1'
33 32
      }
34 33
    },
35 34
    components: {
36 35
      SubMenuNav
37 36
    },
38 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 47
      sidebarClasses () {
40 48
        let skin = this.$store.state.sidebarLayoutSkin
41 49
        return [
@ -84,7 +92,7 @@
84 92
              return console.error('未能找到可用tab标签页!')
85 93
            }
86 94
          }
87
          this.menuNavActive = tab.id + ''
95
          this.menuNavActiveName = tab.id + ''
88 96
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: route.name })
89 97
        }
90 98
      },
@ -100,7 +108,7 @@
100 108
        }
101 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 114
</script>

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

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

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

@ -4,7 +4,7 @@
4 4
;(function () {
5 5
  window.SITE_CONFIG = {}
6 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 9
  // 嵌套iframe地址
10 10
  window.SITE_CONFIG.nestIframeUrl = '//demo.renren.io/renren-fast/'