Explorar el Código

优化导航栏显示昵称&设置

RuoYi hace 11 meses
padre
commit
3915c77391

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 0
ruoyi-ui/src/assets/icons/svg/more-up.svg


+ 0 - 106
ruoyi-ui/src/components/RightPanel/index.vue

@@ -1,106 +0,0 @@
1
-<template>
2
-  <div ref="rightPanel" class="rightPanel-container">
3
-    <div class="rightPanel-background" />
4
-    <div class="rightPanel">
5
-      <div class="rightPanel-items">
6
-        <slot />
7
-      </div>
8
-    </div>
9
-  </div>
10
-</template>
11
-
12
-<script>
13
-export default {
14
-  name: 'RightPanel',
15
-  props: {
16
-    clickNotClose: {
17
-      default: false,
18
-      type: Boolean
19
-    }
20
-  },
21
-  computed: {
22
-    show: {
23
-      get() {
24
-        return this.$store.state.settings.showSettings
25
-      },
26
-      set(val) {
27
-        this.$store.dispatch('settings/changeSetting', {
28
-          key: 'showSettings',
29
-          value: val
30
-        })
31
-      }
32
-    }
33
-  },
34
-  watch: {
35
-    show(value) {
36
-      if (value && !this.clickNotClose) {
37
-        this.addEventClick()
38
-      }
39
-    }
40
-  },
41
-  mounted() {
42
-    this.addEventClick()
43
-  },
44
-  beforeDestroy() {
45
-    const elx = this.$refs.rightPanel
46
-    elx.remove()
47
-  },
48
-  methods: {
49
-    addEventClick() {
50
-      window.addEventListener('click', this.closeSidebar)
51
-    },
52
-    closeSidebar(evt) {
53
-      const parent = evt.target.closest('.el-drawer__body')
54
-      if (!parent) {
55
-        this.show = false
56
-        window.removeEventListener('click', this.closeSidebar)
57
-      }
58
-    }
59
-  }
60
-}
61
-</script>
62
-
63
-<style lang="scss" scoped>
64
-.rightPanel-background {
65
-  position: fixed;
66
-  top: 0;
67
-  left: 0;
68
-  opacity: 0;
69
-  transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
70
-  background: rgba(0, 0, 0, .2);
71
-  z-index: -1;
72
-}
73
-
74
-.rightPanel {
75
-  width: 100%;
76
-  max-width: 260px;
77
-  height: 100vh;
78
-  position: fixed;
79
-  top: 0;
80
-  right: 0;
81
-  box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
82
-  transition: all .25s cubic-bezier(.7, .3, .1, 1);
83
-  transform: translate(100%);
84
-  background: #fff;
85
-  z-index: 40000;
86
-}
87
-
88
-.handle-button {
89
-  width: 48px;
90
-  height: 48px;
91
-  position: absolute;
92
-  left: -48px;
93
-  text-align: center;
94
-  font-size: 24px;
95
-  border-radius: 6px 0 0 6px !important;
96
-  z-index: 0;
97
-  pointer-events: auto;
98
-  cursor: pointer;
99
-  color: #fff;
100
-  line-height: 48px;
101
-  i {
102
-    font-size: 24px;
103
-    line-height: 48px;
104
-  }
105
-}
106
-</style>

+ 25 - 17
ruoyi-ui/src/layout/components/Navbar.vue

@@ -25,23 +25,24 @@
25 25
 
26 26
       </template>
27 27
 
28
-      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
28
+      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="hover">
29 29
         <div class="avatar-wrapper">
30 30
           <img :src="avatar" class="user-avatar">
31
-          <i class="el-icon-caret-bottom" />
31
+          <span class="user-nickname"> {{ nickName }} </span>
32 32
         </div>
33 33
         <el-dropdown-menu slot="dropdown">
34 34
           <router-link to="/user/profile">
35 35
             <el-dropdown-item>个人中心</el-dropdown-item>
36 36
           </router-link>
37
-          <el-dropdown-item @click.native="setting = true">
38
-            <span>布局设置</span>
39
-          </el-dropdown-item>
40 37
           <el-dropdown-item divided @click.native="logout">
41 38
             <span>退出登录</span>
42 39
           </el-dropdown-item>
43 40
         </el-dropdown-menu>
44 41
       </el-dropdown>
42
+
43
+      <div class="right-menu-item hover-effect setting" @click="setLayout" v-if="setting">
44
+        <svg-icon icon-class="more-up" />
45
+      </div>
45 46
     </div>
46 47
   </div>
47 48
 </template>
@@ -58,6 +59,7 @@ import RuoYiGit from '@/components/RuoYi/Git'
58 59
 import RuoYiDoc from '@/components/RuoYi/Doc'
59 60
 
60 61
 export default {
62
+  emits: ['setLayout'],
61 63
   components: {
62 64
     Breadcrumb,
63 65
     TopNav,
@@ -72,17 +74,12 @@ export default {
72 74
     ...mapGetters([
73 75
       'sidebar',
74 76
       'avatar',
75
-      'device'
77
+      'device',
78
+      'nickName'
76 79
     ]),
77 80
     setting: {
78 81
       get() {
79 82
         return this.$store.state.settings.showSettings
80
-      },
81
-      set(val) {
82
-        this.$store.dispatch('settings/changeSetting', {
83
-          key: 'showSettings',
84
-          value: val
85
-        })
86 83
       }
87 84
     },
88 85
     topNav: {
@@ -95,6 +92,9 @@ export default {
95 92
     toggleSideBar() {
96 93
       this.$store.dispatch('app/toggleSideBar')
97 94
     },
95
+    setLayout(event) {
96
+      this.$emit('setLayout')
97
+    },
98 98
     logout() {
99 99
       this.$confirm('确定注销并退出系统吗?', '提示', {
100 100
         confirmButtonText: '确定',
@@ -173,17 +173,25 @@ export default {
173 173
     }
174 174
 
175 175
     .avatar-container {
176
-      margin-right: 30px;
176
+      margin-right: 0px;
177
+      padding-right: 0px;
177 178
 
178 179
       .avatar-wrapper {
179
-        margin-top: 5px;
180
+        margin-top: 10px;
180 181
         position: relative;
181 182
 
182 183
         .user-avatar {
183 184
           cursor: pointer;
184
-          width: 40px;
185
-          height: 40px;
186
-          border-radius: 10px;
185
+          width: 30px;
186
+          height: 30px;
187
+          border-radius: 50%;
188
+        }
189
+
190
+        .user-nickname{
191
+          position: relative;
192
+          bottom: 10px;
193
+          font-size: 14px;
194
+          font-weight: bold;
187 195
         }
188 196
 
189 197
         .el-icon-caret-bottom {

+ 10 - 7
ruoyi-ui/src/layout/components/Settings/index.vue

@@ -1,5 +1,5 @@
1 1
 <template>
2
-  <el-drawer size="280px" :visible="visible" :with-header="false" :append-to-body="true" :show-close="false">
2
+  <el-drawer size="280px" :visible="showSettings" :with-header="false" :append-to-body="true" :before-close="closeSetting">
3 3
     <div class="drawer-container">
4 4
       <div>
5 5
         <div class="setting-drawer-content">
@@ -78,18 +78,15 @@ import ThemePicker from '@/components/ThemePicker'
78 78
 
79 79
 export default {
80 80
   components: { ThemePicker },
81
+  expose: ['openSetting'],
81 82
   data() {
82 83
     return {
83 84
       theme: this.$store.state.settings.theme,
84
-      sideTheme: this.$store.state.settings.sideTheme
85
+      sideTheme: this.$store.state.settings.sideTheme,
86
+      showSettings: false
85 87
     }
86 88
   },
87 89
   computed: {
88
-    visible: {
89
-      get() {
90
-        return this.$store.state.settings.showSettings
91
-      }
92
-    },
93 90
     fixedHeader: {
94 91
       get() {
95 92
         return this.$store.state.settings.fixedHeader
@@ -165,6 +162,12 @@ export default {
165 162
       })
166 163
       this.sideTheme = val
167 164
     },
165
+    openSetting() {
166
+      this.showSettings = true
167
+    },
168
+    closeSetting(){
169
+      this.showSettings = false
170
+    },
168 171
     saveSetting() {
169 172
       this.$modal.loading("正在保存到本地,请稍候...")
170 173
       this.$cache.local.set(

+ 5 - 6
ruoyi-ui/src/layout/index.vue

@@ -4,19 +4,16 @@
4 4
     <sidebar v-if="!sidebar.hide" class="sidebar-container"/>
5 5
     <div :class="{hasTagsView:needTagsView,sidebarHide:sidebar.hide}" class="main-container">
6 6
       <div :class="{'fixed-header':fixedHeader}">
7
-        <navbar/>
7
+        <navbar @setLayout="setLayout"/>
8 8
         <tags-view v-if="needTagsView"/>
9 9
       </div>
10 10
       <app-main/>
11
-      <right-panel>
12
-        <settings/>
13
-      </right-panel>
11
+      <settings ref="settingRef"/>
14 12
     </div>
15 13
   </div>
16 14
 </template>
17 15
 
18 16
 <script>
19
-import RightPanel from '@/components/RightPanel'
20 17
 import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
21 18
 import ResizeMixin from './mixin/ResizeHandler'
22 19
 import { mapState } from 'vuex'
@@ -27,7 +24,6 @@ export default {
27 24
   components: {
28 25
     AppMain,
29 26
     Navbar,
30
-    RightPanel,
31 27
     Settings,
32 28
     Sidebar,
33 29
     TagsView
@@ -57,6 +53,9 @@ export default {
57 53
   methods: {
58 54
     handleClickOutside() {
59 55
       this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
56
+    },
57
+    setLayout() {
58
+      this.$refs.settingRef.openSetting()
60 59
     }
61 60
   }
62 61
 }

+ 1 - 1
ruoyi-ui/src/settings.js

@@ -7,7 +7,7 @@ module.exports = {
7 7
   /**
8 8
    * 是否系统布局配置
9 9
    */
10
-  showSettings: false,
10
+  showSettings: true,
11 11
 
12 12
   /**
13 13
    * 是否显示顶部导航

+ 5 - 3
ruoyi-ui/src/store/getters.js

@@ -7,13 +7,15 @@ const getters = {
7 7
   cachedViews: state => state.tagsView.cachedViews,
8 8
   token: state => state.user.token,
9 9
   avatar: state => state.user.avatar,
10
+  id: state => state.user.id,
10 11
   name: state => state.user.name,
12
+  nickName: state => state.user.nickName,
11 13
   introduction: state => state.user.introduction,
12 14
   roles: state => state.user.roles,
13 15
   permissions: state => state.user.permissions,
14 16
   permission_routes: state => state.permission.routes,
15
-  topbarRouters:state => state.permission.topbarRouters,
16
-  defaultRoutes:state => state.permission.defaultRoutes,
17
-  sidebarRouters:state => state.permission.sidebarRouters
17
+  topbarRouters: state => state.permission.topbarRouters,
18
+  defaultRoutes: state => state.permission.defaultRoutes,
19
+  sidebarRouters: state => state.permission.sidebarRouters
18 20
 }
19 21
 export default getters

+ 5 - 0
ruoyi-ui/src/store/modules/user.js

@@ -8,6 +8,7 @@ const user = {
8 8
     token: getToken(),
9 9
     id: '',
10 10
     name: '',
11
+    nickName: '',
11 12
     avatar: '',
12 13
     roles: [],
13 14
     permissions: []
@@ -26,6 +27,9 @@ const user = {
26 27
     SET_NAME: (state, name) => {
27 28
       state.name = name
28 29
     },
30
+    SET_NICK_NAME: (state, nickName) =>{
31
+      state.nickName = nickName
32
+    },
29 33
     SET_AVATAR: (state, avatar) => {
30 34
       state.avatar = avatar
31 35
     },
@@ -72,6 +76,7 @@ const user = {
72 76
           }
73 77
           commit('SET_ID', user.userId)
74 78
           commit('SET_NAME', user.userName)
79
+          commit('SET_NICK_NAME', user.nickName)
75 80
           commit('SET_AVATAR', avatar)
76 81
           resolve(res)
77 82
         }).catch(error => {