Skip to content

Commit 04422ff

Browse files
committed
perf: 优化导航栏显示昵称&设置
1 parent 60f9518 commit 04422ff

File tree

8 files changed

+52
-139
lines changed

8 files changed

+52
-139
lines changed
Lines changed: 1 addition & 0 deletions
Loading

ruoyi-fastapi-frontend/src/components/RightPanel/index.vue

Lines changed: 0 additions & 106 deletions
This file was deleted.

ruoyi-fastapi-frontend/src/layout/components/Navbar.vue

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
</template>
2727

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">
2929
<div class="avatar-wrapper">
3030
<img :src="avatar" class="user-avatar">
31-
<i class="el-icon-caret-bottom" />
31+
<span class="user-nickname"> {{ nickName }} </span>
3232
</div>
3333
<el-dropdown-menu slot="dropdown">
3434
<router-link to="/user/profile">
3535
<el-dropdown-item>个人中心</el-dropdown-item>
3636
</router-link>
37-
<el-dropdown-item @click.native="setting = true">
37+
<el-dropdown-item @click.native="setLayout" v-if="setting">
3838
<span>布局设置</span>
3939
</el-dropdown-item>
4040
<el-dropdown-item divided @click.native="logout">
@@ -58,6 +58,7 @@ import RuoYiGit from '@/components/RuoYi/Git'
5858
import RuoYiDoc from '@/components/RuoYi/Doc'
5959
6060
export default {
61+
emits: ['setLayout'],
6162
components: {
6263
Breadcrumb,
6364
TopNav,
@@ -72,17 +73,12 @@ export default {
7273
...mapGetters([
7374
'sidebar',
7475
'avatar',
75-
'device'
76+
'device',
77+
'nickName'
7678
]),
7779
setting: {
7880
get() {
7981
return this.$store.state.settings.showSettings
80-
},
81-
set(val) {
82-
this.$store.dispatch('settings/changeSetting', {
83-
key: 'showSettings',
84-
value: val
85-
})
8682
}
8783
},
8884
topNav: {
@@ -95,6 +91,9 @@ export default {
9591
toggleSideBar() {
9692
this.$store.dispatch('app/toggleSideBar')
9793
},
94+
setLayout(event) {
95+
this.$emit('setLayout')
96+
},
9897
logout() {
9998
this.$confirm('确定注销并退出系统吗?', '提示', {
10099
confirmButtonText: '确定',
@@ -173,17 +172,27 @@ export default {
173172
}
174173
175174
.avatar-container {
176-
margin-right: 30px;
175+
margin-right: 0px;
176+
padding-right: 0px;
177177
178178
.avatar-wrapper {
179-
// margin-top: 5px;
179+
// margin-top: 10px;
180+
right: 8px;
180181
position: relative;
181182
182183
.user-avatar {
183184
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+
left: 2px;
194+
font-size: 14px;
195+
font-weight: bold;
187196
}
188197
189198
.el-icon-caret-bottom {

ruoyi-fastapi-frontend/src/layout/components/Settings/index.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<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">
33
<div class="drawer-container">
44
<div>
55
<div class="setting-drawer-content">
@@ -78,18 +78,15 @@ import ThemePicker from '@/components/ThemePicker'
7878
7979
export default {
8080
components: { ThemePicker },
81+
expose: ['openSetting'],
8182
data() {
8283
return {
8384
theme: this.$store.state.settings.theme,
84-
sideTheme: this.$store.state.settings.sideTheme
85+
sideTheme: this.$store.state.settings.sideTheme,
86+
showSettings: false
8587
};
8688
},
8789
computed: {
88-
visible: {
89-
get() {
90-
return this.$store.state.settings.showSettings
91-
}
92-
},
9390
fixedHeader: {
9491
get() {
9592
return this.$store.state.settings.fixedHeader
@@ -166,6 +163,12 @@ export default {
166163
})
167164
this.sideTheme = val;
168165
},
166+
openSetting() {
167+
this.showSettings = true
168+
},
169+
closeSetting(){
170+
this.showSettings = false
171+
},
169172
saveSetting() {
170173
this.$modal.loading("正在保存到本地,请稍候...");
171174
this.$cache.local.set(

ruoyi-fastapi-frontend/src/layout/index.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
<sidebar v-if="!sidebar.hide" class="sidebar-container"/>
55
<div :class="{hasTagsView:needTagsView,sidebarHide:sidebar.hide}" class="main-container">
66
<div :class="{'fixed-header':fixedHeader}">
7-
<navbar/>
7+
<navbar @setLayout="setLayout"/>
88
<tags-view v-if="needTagsView"/>
99
</div>
1010
<app-main/>
11-
<right-panel>
12-
<settings/>
13-
</right-panel>
11+
<settings ref="settingRef"/>
1412
</div>
1513
</div>
1614
</template>
1715

1816
<script>
19-
import RightPanel from '@/components/RightPanel'
2017
import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
2118
import ResizeMixin from './mixin/ResizeHandler'
2219
import { mapState } from 'vuex'
@@ -27,7 +24,6 @@ export default {
2724
components: {
2825
AppMain,
2926
Navbar,
30-
RightPanel,
3127
Settings,
3228
Sidebar,
3329
TagsView
@@ -57,6 +53,9 @@ export default {
5753
methods: {
5854
handleClickOutside() {
5955
this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
56+
},
57+
setLayout() {
58+
this.$refs.settingRef.openSetting()
6059
}
6160
}
6261
}

ruoyi-fastapi-frontend/src/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
* 网页标题
44
*/
55
title: process.env.VUE_APP_TITLE,
6-
6+
77
/**
88
* 侧边栏主题 深色主题theme-dark,浅色主题theme-light
99
*/
@@ -12,7 +12,7 @@ module.exports = {
1212
/**
1313
* 是否系统布局配置
1414
*/
15-
showSettings: false,
15+
showSettings: true,
1616

1717
/**
1818
* 是否显示顶部导航

ruoyi-fastapi-frontend/src/store/getters.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const getters = {
77
cachedViews: state => state.tagsView.cachedViews,
88
token: state => state.user.token,
99
avatar: state => state.user.avatar,
10+
id: state => state.user.id,
1011
name: state => state.user.name,
1112
introduction: state => state.user.introduction,
13+
nickName: state => state.user.nickName,
1214
roles: state => state.user.roles,
1315
permissions: state => state.user.permissions,
1416
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
1820
}
1921
export default getters

ruoyi-fastapi-frontend/src/store/modules/user.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const user = {
88
token: getToken(),
99
id: '',
1010
name: '',
11+
nickName: '',
1112
avatar: '',
1213
roles: [],
1314
permissions: []
@@ -23,6 +24,9 @@ const user = {
2324
SET_NAME: (state, name) => {
2425
state.name = name
2526
},
27+
SET_NICK_NAME: (state, nickName) =>{
28+
state.nickName = nickName
29+
},
2630
SET_AVATAR: (state, avatar) => {
2731
state.avatar = avatar
2832
},
@@ -69,6 +73,7 @@ const user = {
6973
}
7074
commit('SET_ID', user.userId)
7175
commit('SET_NAME', user.userName)
76+
commit('SET_NICK_NAME', user.nickName)
7277
commit('SET_AVATAR', avatar)
7378
resolve(res)
7479
}).catch(error => {

0 commit comments

Comments
 (0)