Commit 7519a00ada89966f9caf93d315830dd628253d73
Committed by
GitHub
1 parent
d8ff30d9
fix(avatar): show current user's avatar (#640)
在显示头像的地方正确显示当前登录用户的头像,已补充mock接口返回的avatar字段。
Showing
9 changed files
with
60 additions
and
23 deletions
mock/sys/user.ts
... | ... | @@ -7,6 +7,7 @@ function createFakeUserList() { |
7 | 7 | userId: '1', |
8 | 8 | username: 'vben', |
9 | 9 | realName: 'Vben Admin', |
10 | + avatar: 'http://q1.qlogo.cn/g?b=qq&nk=190848757&s=640', | |
10 | 11 | desc: 'manager', |
11 | 12 | password: '123456', |
12 | 13 | token: 'fakeToken1', |
... | ... | @@ -22,6 +23,7 @@ function createFakeUserList() { |
22 | 23 | username: 'test', |
23 | 24 | password: '123456', |
24 | 25 | realName: 'test user', |
26 | + avatar: 'http://q1.qlogo.cn/g?b=qq&nk=339449197&s=640', | |
25 | 27 | desc: 'tester', |
26 | 28 | token: 'fakeToken2', |
27 | 29 | roles: [ | ... | ... |
src/api/sys/model/userModel.ts
src/layouts/default/header/components/lock/LockModal.vue
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | > |
9 | 9 | <div :class="`${prefixCls}__entry`"> |
10 | 10 | <div :class="`${prefixCls}__header`"> |
11 | - <img :src="headerImg" :class="`${prefixCls}__header-img`" /> | |
11 | + <img :src="avatar" :class="`${prefixCls}__header-img`" /> | |
12 | 12 | <p :class="`${prefixCls}__header-name`"> |
13 | 13 | {{ getRealName }} |
14 | 14 | </p> |
... | ... | @@ -71,6 +71,11 @@ |
71 | 71 | await resetFields(); |
72 | 72 | } |
73 | 73 | |
74 | + const avatar = computed(() => { | |
75 | + const { avatar } = userStore.getUserInfo; | |
76 | + return avatar || headerImg; | |
77 | + }); | |
78 | + | |
74 | 79 | return { |
75 | 80 | t, |
76 | 81 | prefixCls, |
... | ... | @@ -78,7 +83,7 @@ |
78 | 83 | register, |
79 | 84 | registerForm, |
80 | 85 | handleLock, |
81 | - headerImg, | |
86 | + avatar, | |
82 | 87 | }; |
83 | 88 | }, |
84 | 89 | }); | ... | ... |
src/layouts/default/header/components/user-dropdown/index.vue
1 | 1 | <template> |
2 | 2 | <Dropdown placement="bottomLeft" :overlayClassName="`${prefixCls}-dropdown-overlay`"> |
3 | 3 | <span :class="[prefixCls, `${prefixCls}--${theme}`]" class="flex"> |
4 | - <img :class="`${prefixCls}__header`" :src="headerImg" /> | |
4 | + <img :class="`${prefixCls}__header`" :src="getUserInfo.avatar" /> | |
5 | 5 | <span :class="`${prefixCls}__info hidden md:block`"> |
6 | 6 | <span :class="`${prefixCls}__name `" class="truncate"> |
7 | 7 | {{ getUserInfo.realName }} |
... | ... | @@ -75,8 +75,8 @@ |
75 | 75 | const userStore = useUserStore(); |
76 | 76 | |
77 | 77 | const getUserInfo = computed(() => { |
78 | - const { realName = '', desc } = userStore.getUserInfo || {}; | |
79 | - return { realName, desc }; | |
78 | + const { realName = '', avatar, desc } = userStore.getUserInfo || {}; | |
79 | + return { realName, avatar: avatar || headerImg, desc }; | |
80 | 80 | }); |
81 | 81 | |
82 | 82 | const [register, { openModal }] = useModal(); |
... | ... | @@ -115,7 +115,6 @@ |
115 | 115 | getUserInfo, |
116 | 116 | handleMenuClick, |
117 | 117 | getShowDoc, |
118 | - headerImg, | |
119 | 118 | register, |
120 | 119 | getUseLockPage, |
121 | 120 | }; | ... | ... |
src/views/dashboard/workbench/components/WorkbenchHeader.vue
1 | 1 | <template> |
2 | 2 | <div class="lg:flex"> |
3 | - <Avatar :src="headerImg" :size="72" class="!mx-auto !block" /> | |
3 | + <Avatar :src="userinfo.avatar || headerImg" :size="72" class="!mx-auto !block" /> | |
4 | 4 | <div class="md:ml-6 flex flex-col justify-center md:mt-0 mt-2"> |
5 | - <h1 class="md:text-lg text-md">早安, Vben, 开始您一天的工作吧!</h1> | |
5 | + <h1 class="md:text-lg text-md">早安, {{ userinfo.realName }}, 开始您一天的工作吧!</h1> | |
6 | 6 | <span class="text-secondary"> 今日晴,20℃ - 32℃! </span> |
7 | 7 | </div> |
8 | 8 | <div class="flex flex-1 justify-end md:mt-0 mt-4"> |
... | ... | @@ -23,15 +23,18 @@ |
23 | 23 | </div> |
24 | 24 | </template> |
25 | 25 | <script lang="ts"> |
26 | - import { defineComponent } from 'vue'; | |
26 | + import { computed, defineComponent } from 'vue'; | |
27 | 27 | |
28 | 28 | import { Avatar } from 'ant-design-vue'; |
29 | + import { useUserStore } from '/@/store/modules/user'; | |
29 | 30 | |
30 | 31 | import headerImg from '/@/assets/images/header.jpg'; |
31 | 32 | export default defineComponent({ |
32 | 33 | components: { Avatar }, |
33 | 34 | setup() { |
34 | - return { headerImg }; | |
35 | + const userStore = useUserStore(); | |
36 | + const userinfo = computed(() => userStore.getUserInfo); | |
37 | + return { userinfo, headerImg }; | |
35 | 38 | }, |
36 | 39 | }); |
37 | 40 | </script> | ... | ... |
src/views/demo/page/account/center/index.vue
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <a-row> |
6 | 6 | <a-col :span="8"> |
7 | 7 | <div :class="`${prefixCls}-top__avatar`"> |
8 | - <img width="70" :src="headerImg" /> | |
8 | + <img width="70" :src="avatar" /> | |
9 | 9 | <span>Vben</span> |
10 | 10 | <div>海纳百川,有容乃大</div> |
11 | 11 | </div> |
... | ... | @@ -54,7 +54,7 @@ |
54 | 54 | |
55 | 55 | <script lang="ts"> |
56 | 56 | import { Tag, Tabs, Row, Col } from 'ant-design-vue'; |
57 | - import { defineComponent } from 'vue'; | |
57 | + import { defineComponent, computed } from 'vue'; | |
58 | 58 | import { CollapseContainer } from '/@/components/Container/index'; |
59 | 59 | import Icon from '/@/components/Icon/index'; |
60 | 60 | import Article from './Article.vue'; |
... | ... | @@ -63,6 +63,7 @@ |
63 | 63 | |
64 | 64 | import headerImg from '/@/assets/images/header.jpg'; |
65 | 65 | import { tags, teams, details, achieveList } from './data'; |
66 | + import { useUserStore } from '/@/store/modules/user'; | |
66 | 67 | |
67 | 68 | export default defineComponent({ |
68 | 69 | components: { |
... | ... | @@ -78,9 +79,11 @@ |
78 | 79 | [Col.name]: Col, |
79 | 80 | }, |
80 | 81 | setup() { |
82 | + const userStore = useUserStore(); | |
83 | + const avatar = computed(() => userStore.getUserInfo.avatar || headerImg); | |
81 | 84 | return { |
82 | 85 | prefixCls: 'account-center', |
83 | - headerImg, | |
86 | + avatar, | |
84 | 87 | tags, |
85 | 88 | teams, |
86 | 89 | details, | ... | ... |
src/views/demo/page/account/setting/BaseSetting.vue
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | <a-col :span="10"> |
8 | 8 | <div class="change-avatar"> |
9 | 9 | <div class="mb-2"> 头像 </div> |
10 | - <img width="140" :src="headerImg" /> | |
10 | + <img width="140" :src="avatar" /> | |
11 | 11 | <Upload :showUploadList="false"> |
12 | 12 | <Button class="ml-5"> <Icon icon="feather:upload" />更换头像 </Button> |
13 | 13 | </Upload> |
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | </template> |
20 | 20 | <script lang="ts"> |
21 | 21 | import { Button, Upload, Row, Col } from 'ant-design-vue'; |
22 | - import { defineComponent, onMounted } from 'vue'; | |
22 | + import { computed, defineComponent, onMounted } from 'vue'; | |
23 | 23 | import { BasicForm, useForm } from '/@/components/Form/index'; |
24 | 24 | import { CollapseContainer } from '/@/components/Container/index'; |
25 | 25 | import Icon from '/@/components/Icon/index'; |
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | import headerImg from '/@/assets/images/header.jpg'; |
30 | 30 | import { accountInfoApi } from '/@/api/demo/account'; |
31 | 31 | import { baseSetschemas } from './data'; |
32 | + import { useUserStore } from '/@/store/modules/user'; | |
32 | 33 | |
33 | 34 | export default defineComponent({ |
34 | 35 | components: { |
... | ... | @@ -42,6 +43,7 @@ |
42 | 43 | }, |
43 | 44 | setup() { |
44 | 45 | const { createMessage } = useMessage(); |
46 | + const userStore = useUserStore(); | |
45 | 47 | |
46 | 48 | const [register, { setFieldsValue }] = useForm({ |
47 | 49 | labelWidth: 120, |
... | ... | @@ -54,8 +56,13 @@ |
54 | 56 | setFieldsValue(data); |
55 | 57 | }); |
56 | 58 | |
59 | + const avatar = computed(() => { | |
60 | + const { avatar } = userStore.getUserInfo; | |
61 | + return avatar || headerImg; | |
62 | + }); | |
63 | + | |
57 | 64 | return { |
58 | - headerImg, | |
65 | + avatar, | |
59 | 66 | register, |
60 | 67 | handleSubmit: () => { |
61 | 68 | createMessage.success('更新成功!'); | ... | ... |
src/views/sys/lock/LockPage.vue
... | ... | @@ -5,7 +5,23 @@ |
5 | 5 | > |
6 | 6 | <div |
7 | 7 | :class="`${prefixCls}__unlock`" |
8 | - class="absolute top-0 left-1/2 flex pt-5 h-16 items-center justify-center sm:text-md xl:text-xl text-white flex-col cursor-pointer transform translate-x-1/2" | |
8 | + class=" | |
9 | + absolute | |
10 | + top-0 | |
11 | + left-1/2 | |
12 | + flex | |
13 | + pt-5 | |
14 | + h-16 | |
15 | + items-center | |
16 | + justify-center | |
17 | + sm:text-md | |
18 | + xl:text-xl | |
19 | + text-white | |
20 | + flex-col | |
21 | + cursor-pointer | |
22 | + transform | |
23 | + translate-x-1/2 | |
24 | + " | |
9 | 25 | @click="handleShowForm(false)" |
10 | 26 | v-show="showDate" |
11 | 27 | > |
... | ... | @@ -28,9 +44,9 @@ |
28 | 44 | <div :class="`${prefixCls}-entry`" v-show="!showDate"> |
29 | 45 | <div :class="`${prefixCls}-entry-content`"> |
30 | 46 | <div :class="`${prefixCls}-entry__header enter-x`"> |
31 | - <img :src="headerImg" :class="`${prefixCls}-entry__header-img`" /> | |
47 | + <img :src="userinfo.avatar || headerImg" :class="`${prefixCls}-entry__header-img`" /> | |
32 | 48 | <p :class="`${prefixCls}-entry__header-name`"> |
33 | - {{ realName }} | |
49 | + {{ userinfo.realName }} | |
34 | 50 | </p> |
35 | 51 | </div> |
36 | 52 | <InputPassword |
... | ... | @@ -108,9 +124,8 @@ |
108 | 124 | |
109 | 125 | const { t } = useI18n(); |
110 | 126 | |
111 | - const realName = computed(() => { | |
112 | - const { realName } = userStore.getUserInfo || {}; | |
113 | - return realName; | |
127 | + const userinfo = computed(() => { | |
128 | + return userStore.getUserInfo || {}; | |
114 | 129 | }); |
115 | 130 | |
116 | 131 | /** |
... | ... | @@ -141,7 +156,7 @@ |
141 | 156 | |
142 | 157 | return { |
143 | 158 | goLogin, |
144 | - realName, | |
159 | + userinfo, | |
145 | 160 | unLock, |
146 | 161 | errMsg, |
147 | 162 | loading, | ... | ... |