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,6 +7,7 @@ function createFakeUserList() { | ||
7 | userId: '1', | 7 | userId: '1', |
8 | username: 'vben', | 8 | username: 'vben', |
9 | realName: 'Vben Admin', | 9 | realName: 'Vben Admin', |
10 | + avatar: 'http://q1.qlogo.cn/g?b=qq&nk=190848757&s=640', | ||
10 | desc: 'manager', | 11 | desc: 'manager', |
11 | password: '123456', | 12 | password: '123456', |
12 | token: 'fakeToken1', | 13 | token: 'fakeToken1', |
@@ -22,6 +23,7 @@ function createFakeUserList() { | @@ -22,6 +23,7 @@ function createFakeUserList() { | ||
22 | username: 'test', | 23 | username: 'test', |
23 | password: '123456', | 24 | password: '123456', |
24 | realName: 'test user', | 25 | realName: 'test user', |
26 | + avatar: 'http://q1.qlogo.cn/g?b=qq&nk=339449197&s=640', | ||
25 | desc: 'tester', | 27 | desc: 'tester', |
26 | token: 'fakeToken2', | 28 | token: 'fakeToken2', |
27 | roles: [ | 29 | roles: [ |
src/api/sys/model/userModel.ts
@@ -38,6 +38,8 @@ export interface GetUserInfoByUserIdModel { | @@ -38,6 +38,8 @@ export interface GetUserInfoByUserIdModel { | ||
38 | username: string; | 38 | username: string; |
39 | // 真实名字 | 39 | // 真实名字 |
40 | realName: string; | 40 | realName: string; |
41 | + // 头像 | ||
42 | + avatar: string; | ||
41 | // 介绍 | 43 | // 介绍 |
42 | desc?: string; | 44 | desc?: string; |
43 | } | 45 | } |
src/layouts/default/header/components/lock/LockModal.vue
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | > | 8 | > |
9 | <div :class="`${prefixCls}__entry`"> | 9 | <div :class="`${prefixCls}__entry`"> |
10 | <div :class="`${prefixCls}__header`"> | 10 | <div :class="`${prefixCls}__header`"> |
11 | - <img :src="headerImg" :class="`${prefixCls}__header-img`" /> | 11 | + <img :src="avatar" :class="`${prefixCls}__header-img`" /> |
12 | <p :class="`${prefixCls}__header-name`"> | 12 | <p :class="`${prefixCls}__header-name`"> |
13 | {{ getRealName }} | 13 | {{ getRealName }} |
14 | </p> | 14 | </p> |
@@ -71,6 +71,11 @@ | @@ -71,6 +71,11 @@ | ||
71 | await resetFields(); | 71 | await resetFields(); |
72 | } | 72 | } |
73 | 73 | ||
74 | + const avatar = computed(() => { | ||
75 | + const { avatar } = userStore.getUserInfo; | ||
76 | + return avatar || headerImg; | ||
77 | + }); | ||
78 | + | ||
74 | return { | 79 | return { |
75 | t, | 80 | t, |
76 | prefixCls, | 81 | prefixCls, |
@@ -78,7 +83,7 @@ | @@ -78,7 +83,7 @@ | ||
78 | register, | 83 | register, |
79 | registerForm, | 84 | registerForm, |
80 | handleLock, | 85 | handleLock, |
81 | - headerImg, | 86 | + avatar, |
82 | }; | 87 | }; |
83 | }, | 88 | }, |
84 | }); | 89 | }); |
src/layouts/default/header/components/user-dropdown/index.vue
1 | <template> | 1 | <template> |
2 | <Dropdown placement="bottomLeft" :overlayClassName="`${prefixCls}-dropdown-overlay`"> | 2 | <Dropdown placement="bottomLeft" :overlayClassName="`${prefixCls}-dropdown-overlay`"> |
3 | <span :class="[prefixCls, `${prefixCls}--${theme}`]" class="flex"> | 3 | <span :class="[prefixCls, `${prefixCls}--${theme}`]" class="flex"> |
4 | - <img :class="`${prefixCls}__header`" :src="headerImg" /> | 4 | + <img :class="`${prefixCls}__header`" :src="getUserInfo.avatar" /> |
5 | <span :class="`${prefixCls}__info hidden md:block`"> | 5 | <span :class="`${prefixCls}__info hidden md:block`"> |
6 | <span :class="`${prefixCls}__name `" class="truncate"> | 6 | <span :class="`${prefixCls}__name `" class="truncate"> |
7 | {{ getUserInfo.realName }} | 7 | {{ getUserInfo.realName }} |
@@ -75,8 +75,8 @@ | @@ -75,8 +75,8 @@ | ||
75 | const userStore = useUserStore(); | 75 | const userStore = useUserStore(); |
76 | 76 | ||
77 | const getUserInfo = computed(() => { | 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 | const [register, { openModal }] = useModal(); | 82 | const [register, { openModal }] = useModal(); |
@@ -115,7 +115,6 @@ | @@ -115,7 +115,6 @@ | ||
115 | getUserInfo, | 115 | getUserInfo, |
116 | handleMenuClick, | 116 | handleMenuClick, |
117 | getShowDoc, | 117 | getShowDoc, |
118 | - headerImg, | ||
119 | register, | 118 | register, |
120 | getUseLockPage, | 119 | getUseLockPage, |
121 | }; | 120 | }; |
src/views/dashboard/workbench/components/WorkbenchHeader.vue
1 | <template> | 1 | <template> |
2 | <div class="lg:flex"> | 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 | <div class="md:ml-6 flex flex-col justify-center md:mt-0 mt-2"> | 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 | <span class="text-secondary"> 今日晴,20℃ - 32℃! </span> | 6 | <span class="text-secondary"> 今日晴,20℃ - 32℃! </span> |
7 | </div> | 7 | </div> |
8 | <div class="flex flex-1 justify-end md:mt-0 mt-4"> | 8 | <div class="flex flex-1 justify-end md:mt-0 mt-4"> |
@@ -23,15 +23,18 @@ | @@ -23,15 +23,18 @@ | ||
23 | </div> | 23 | </div> |
24 | </template> | 24 | </template> |
25 | <script lang="ts"> | 25 | <script lang="ts"> |
26 | - import { defineComponent } from 'vue'; | 26 | + import { computed, defineComponent } from 'vue'; |
27 | 27 | ||
28 | import { Avatar } from 'ant-design-vue'; | 28 | import { Avatar } from 'ant-design-vue'; |
29 | + import { useUserStore } from '/@/store/modules/user'; | ||
29 | 30 | ||
30 | import headerImg from '/@/assets/images/header.jpg'; | 31 | import headerImg from '/@/assets/images/header.jpg'; |
31 | export default defineComponent({ | 32 | export default defineComponent({ |
32 | components: { Avatar }, | 33 | components: { Avatar }, |
33 | setup() { | 34 | setup() { |
34 | - return { headerImg }; | 35 | + const userStore = useUserStore(); |
36 | + const userinfo = computed(() => userStore.getUserInfo); | ||
37 | + return { userinfo, headerImg }; | ||
35 | }, | 38 | }, |
36 | }); | 39 | }); |
37 | </script> | 40 | </script> |
src/views/demo/page/account/center/index.vue
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <a-row> | 5 | <a-row> |
6 | <a-col :span="8"> | 6 | <a-col :span="8"> |
7 | <div :class="`${prefixCls}-top__avatar`"> | 7 | <div :class="`${prefixCls}-top__avatar`"> |
8 | - <img width="70" :src="headerImg" /> | 8 | + <img width="70" :src="avatar" /> |
9 | <span>Vben</span> | 9 | <span>Vben</span> |
10 | <div>海纳百川,有容乃大</div> | 10 | <div>海纳百川,有容乃大</div> |
11 | </div> | 11 | </div> |
@@ -54,7 +54,7 @@ | @@ -54,7 +54,7 @@ | ||
54 | 54 | ||
55 | <script lang="ts"> | 55 | <script lang="ts"> |
56 | import { Tag, Tabs, Row, Col } from 'ant-design-vue'; | 56 | import { Tag, Tabs, Row, Col } from 'ant-design-vue'; |
57 | - import { defineComponent } from 'vue'; | 57 | + import { defineComponent, computed } from 'vue'; |
58 | import { CollapseContainer } from '/@/components/Container/index'; | 58 | import { CollapseContainer } from '/@/components/Container/index'; |
59 | import Icon from '/@/components/Icon/index'; | 59 | import Icon from '/@/components/Icon/index'; |
60 | import Article from './Article.vue'; | 60 | import Article from './Article.vue'; |
@@ -63,6 +63,7 @@ | @@ -63,6 +63,7 @@ | ||
63 | 63 | ||
64 | import headerImg from '/@/assets/images/header.jpg'; | 64 | import headerImg from '/@/assets/images/header.jpg'; |
65 | import { tags, teams, details, achieveList } from './data'; | 65 | import { tags, teams, details, achieveList } from './data'; |
66 | + import { useUserStore } from '/@/store/modules/user'; | ||
66 | 67 | ||
67 | export default defineComponent({ | 68 | export default defineComponent({ |
68 | components: { | 69 | components: { |
@@ -78,9 +79,11 @@ | @@ -78,9 +79,11 @@ | ||
78 | [Col.name]: Col, | 79 | [Col.name]: Col, |
79 | }, | 80 | }, |
80 | setup() { | 81 | setup() { |
82 | + const userStore = useUserStore(); | ||
83 | + const avatar = computed(() => userStore.getUserInfo.avatar || headerImg); | ||
81 | return { | 84 | return { |
82 | prefixCls: 'account-center', | 85 | prefixCls: 'account-center', |
83 | - headerImg, | 86 | + avatar, |
84 | tags, | 87 | tags, |
85 | teams, | 88 | teams, |
86 | details, | 89 | details, |
src/views/demo/page/account/setting/BaseSetting.vue
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | <a-col :span="10"> | 7 | <a-col :span="10"> |
8 | <div class="change-avatar"> | 8 | <div class="change-avatar"> |
9 | <div class="mb-2"> 头像 </div> | 9 | <div class="mb-2"> 头像 </div> |
10 | - <img width="140" :src="headerImg" /> | 10 | + <img width="140" :src="avatar" /> |
11 | <Upload :showUploadList="false"> | 11 | <Upload :showUploadList="false"> |
12 | <Button class="ml-5"> <Icon icon="feather:upload" />更换头像 </Button> | 12 | <Button class="ml-5"> <Icon icon="feather:upload" />更换头像 </Button> |
13 | </Upload> | 13 | </Upload> |
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | </template> | 19 | </template> |
20 | <script lang="ts"> | 20 | <script lang="ts"> |
21 | import { Button, Upload, Row, Col } from 'ant-design-vue'; | 21 | import { Button, Upload, Row, Col } from 'ant-design-vue'; |
22 | - import { defineComponent, onMounted } from 'vue'; | 22 | + import { computed, defineComponent, onMounted } from 'vue'; |
23 | import { BasicForm, useForm } from '/@/components/Form/index'; | 23 | import { BasicForm, useForm } from '/@/components/Form/index'; |
24 | import { CollapseContainer } from '/@/components/Container/index'; | 24 | import { CollapseContainer } from '/@/components/Container/index'; |
25 | import Icon from '/@/components/Icon/index'; | 25 | import Icon from '/@/components/Icon/index'; |
@@ -29,6 +29,7 @@ | @@ -29,6 +29,7 @@ | ||
29 | import headerImg from '/@/assets/images/header.jpg'; | 29 | import headerImg from '/@/assets/images/header.jpg'; |
30 | import { accountInfoApi } from '/@/api/demo/account'; | 30 | import { accountInfoApi } from '/@/api/demo/account'; |
31 | import { baseSetschemas } from './data'; | 31 | import { baseSetschemas } from './data'; |
32 | + import { useUserStore } from '/@/store/modules/user'; | ||
32 | 33 | ||
33 | export default defineComponent({ | 34 | export default defineComponent({ |
34 | components: { | 35 | components: { |
@@ -42,6 +43,7 @@ | @@ -42,6 +43,7 @@ | ||
42 | }, | 43 | }, |
43 | setup() { | 44 | setup() { |
44 | const { createMessage } = useMessage(); | 45 | const { createMessage } = useMessage(); |
46 | + const userStore = useUserStore(); | ||
45 | 47 | ||
46 | const [register, { setFieldsValue }] = useForm({ | 48 | const [register, { setFieldsValue }] = useForm({ |
47 | labelWidth: 120, | 49 | labelWidth: 120, |
@@ -54,8 +56,13 @@ | @@ -54,8 +56,13 @@ | ||
54 | setFieldsValue(data); | 56 | setFieldsValue(data); |
55 | }); | 57 | }); |
56 | 58 | ||
59 | + const avatar = computed(() => { | ||
60 | + const { avatar } = userStore.getUserInfo; | ||
61 | + return avatar || headerImg; | ||
62 | + }); | ||
63 | + | ||
57 | return { | 64 | return { |
58 | - headerImg, | 65 | + avatar, |
59 | register, | 66 | register, |
60 | handleSubmit: () => { | 67 | handleSubmit: () => { |
61 | createMessage.success('更新成功!'); | 68 | createMessage.success('更新成功!'); |
src/views/sys/lock/LockPage.vue
@@ -5,7 +5,23 @@ | @@ -5,7 +5,23 @@ | ||
5 | > | 5 | > |
6 | <div | 6 | <div |
7 | :class="`${prefixCls}__unlock`" | 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 | @click="handleShowForm(false)" | 25 | @click="handleShowForm(false)" |
10 | v-show="showDate" | 26 | v-show="showDate" |
11 | > | 27 | > |
@@ -28,9 +44,9 @@ | @@ -28,9 +44,9 @@ | ||
28 | <div :class="`${prefixCls}-entry`" v-show="!showDate"> | 44 | <div :class="`${prefixCls}-entry`" v-show="!showDate"> |
29 | <div :class="`${prefixCls}-entry-content`"> | 45 | <div :class="`${prefixCls}-entry-content`"> |
30 | <div :class="`${prefixCls}-entry__header enter-x`"> | 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 | <p :class="`${prefixCls}-entry__header-name`"> | 48 | <p :class="`${prefixCls}-entry__header-name`"> |
33 | - {{ realName }} | 49 | + {{ userinfo.realName }} |
34 | </p> | 50 | </p> |
35 | </div> | 51 | </div> |
36 | <InputPassword | 52 | <InputPassword |
@@ -108,9 +124,8 @@ | @@ -108,9 +124,8 @@ | ||
108 | 124 | ||
109 | const { t } = useI18n(); | 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,7 +156,7 @@ | ||
141 | 156 | ||
142 | return { | 157 | return { |
143 | goLogin, | 158 | goLogin, |
144 | - realName, | 159 | + userinfo, |
145 | unLock, | 160 | unLock, |
146 | errMsg, | 161 | errMsg, |
147 | loading, | 162 | loading, |
types/store.ts
@@ -33,6 +33,7 @@ export interface UserInfo { | @@ -33,6 +33,7 @@ export interface UserInfo { | ||
33 | userId: string | number; | 33 | userId: string | number; |
34 | username: string; | 34 | username: string; |
35 | realName: string; | 35 | realName: string; |
36 | + avatar: string; | ||
36 | desc?: string; | 37 | desc?: string; |
37 | } | 38 | } |
38 | 39 |