Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(avatar): show current user's avatar #640

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mock/sys/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function createFakeUserList() {
userId: '1',
username: 'vben',
realName: 'Vben Admin',
avatar: 'http://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
desc: 'manager',
password: '123456',
token: 'fakeToken1',
Expand All @@ -22,6 +23,7 @@ function createFakeUserList() {
username: 'test',
password: '123456',
realName: 'test user',
avatar: 'http://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
desc: 'tester',
token: 'fakeToken2',
roles: [
Expand Down
2 changes: 2 additions & 0 deletions src/api/sys/model/userModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface GetUserInfoByUserIdModel {
username: string;
// 真实名字
realName: string;
// 头像
avatar: string;
// 介绍
desc?: string;
}
9 changes: 7 additions & 2 deletions src/layouts/default/header/components/lock/LockModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<div :class="`${prefixCls}__entry`">
<div :class="`${prefixCls}__header`">
<img :src="headerImg" :class="`${prefixCls}__header-img`" />
<img :src="avatar" :class="`${prefixCls}__header-img`" />
<p :class="`${prefixCls}__header-name`">
{{ getRealName }}
</p>
Expand Down Expand Up @@ -71,14 +71,19 @@
await resetFields();
}

const avatar = computed(() => {
const { avatar } = userStore.getUserInfo;
return avatar || headerImg;
});

return {
t,
prefixCls,
getRealName,
register,
registerForm,
handleLock,
headerImg,
avatar,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Dropdown placement="bottomLeft" :overlayClassName="`${prefixCls}-dropdown-overlay`">
<span :class="[prefixCls, `${prefixCls}--${theme}`]" class="flex">
<img :class="`${prefixCls}__header`" :src="headerImg" />
<img :class="`${prefixCls}__header`" :src="getUserInfo.avatar" />
<span :class="`${prefixCls}__info hidden md:block`">
<span :class="`${prefixCls}__name `" class="truncate">
{{ getUserInfo.realName }}
Expand Down Expand Up @@ -75,8 +75,8 @@
const userStore = useUserStore();

const getUserInfo = computed(() => {
const { realName = '', desc } = userStore.getUserInfo || {};
return { realName, desc };
const { realName = '', avatar, desc } = userStore.getUserInfo || {};
return { realName, avatar: avatar || headerImg, desc };
});

const [register, { openModal }] = useModal();
Expand Down Expand Up @@ -115,7 +115,6 @@
getUserInfo,
handleMenuClick,
getShowDoc,
headerImg,
register,
getUseLockPage,
};
Expand Down
11 changes: 7 additions & 4 deletions src/views/dashboard/workbench/components/WorkbenchHeader.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="lg:flex">
<Avatar :src="headerImg" :size="72" class="!mx-auto !block" />
<Avatar :src="userinfo.avatar || headerImg" :size="72" class="!mx-auto !block" />
<div class="md:ml-6 flex flex-col justify-center md:mt-0 mt-2">
<h1 class="md:text-lg text-md">早安, Vben, 开始您一天的工作吧!</h1>
<h1 class="md:text-lg text-md">早安, {{ userinfo.realName }}, 开始您一天的工作吧!</h1>
<span class="text-secondary"> 今日晴,20℃ - 32℃! </span>
</div>
<div class="flex flex-1 justify-end md:mt-0 mt-4">
Expand All @@ -23,15 +23,18 @@
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { computed, defineComponent } from 'vue';

import { Avatar } from 'ant-design-vue';
import { useUserStore } from '/@/store/modules/user';

import headerImg from '/@/assets/images/header.jpg';
export default defineComponent({
components: { Avatar },
setup() {
return { headerImg };
const userStore = useUserStore();
const userinfo = computed(() => userStore.getUserInfo);
return { userinfo, headerImg };
},
});
</script>
9 changes: 6 additions & 3 deletions src/views/demo/page/account/center/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a-row>
<a-col :span="8">
<div :class="`${prefixCls}-top__avatar`">
<img width="70" :src="headerImg" />
<img width="70" :src="avatar" />
<span>Vben</span>
<div>海纳百川,有容乃大</div>
</div>
Expand Down Expand Up @@ -54,7 +54,7 @@

<script lang="ts">
import { Tag, Tabs, Row, Col } from 'ant-design-vue';
import { defineComponent } from 'vue';
import { defineComponent, computed } from 'vue';
import { CollapseContainer } from '/@/components/Container/index';
import Icon from '/@/components/Icon/index';
import Article from './Article.vue';
Expand All @@ -63,6 +63,7 @@

import headerImg from '/@/assets/images/header.jpg';
import { tags, teams, details, achieveList } from './data';
import { useUserStore } from '/@/store/modules/user';

export default defineComponent({
components: {
Expand All @@ -78,9 +79,11 @@
[Col.name]: Col,
},
setup() {
const userStore = useUserStore();
const avatar = computed(() => userStore.getUserInfo.avatar || headerImg);
return {
prefixCls: 'account-center',
headerImg,
avatar,
tags,
teams,
details,
Expand Down
13 changes: 10 additions & 3 deletions src/views/demo/page/account/setting/BaseSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a-col :span="10">
<div class="change-avatar">
<div class="mb-2"> 头像 </div>
<img width="140" :src="headerImg" />
<img width="140" :src="avatar" />
<Upload :showUploadList="false">
<Button class="ml-5"> <Icon icon="feather:upload" />更换头像 </Button>
</Upload>
Expand All @@ -19,7 +19,7 @@
</template>
<script lang="ts">
import { Button, Upload, Row, Col } from 'ant-design-vue';
import { defineComponent, onMounted } from 'vue';
import { computed, defineComponent, onMounted } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { CollapseContainer } from '/@/components/Container/index';
import Icon from '/@/components/Icon/index';
Expand All @@ -29,6 +29,7 @@
import headerImg from '/@/assets/images/header.jpg';
import { accountInfoApi } from '/@/api/demo/account';
import { baseSetschemas } from './data';
import { useUserStore } from '/@/store/modules/user';

export default defineComponent({
components: {
Expand All @@ -42,6 +43,7 @@
},
setup() {
const { createMessage } = useMessage();
const userStore = useUserStore();

const [register, { setFieldsValue }] = useForm({
labelWidth: 120,
Expand All @@ -54,8 +56,13 @@
setFieldsValue(data);
});

const avatar = computed(() => {
const { avatar } = userStore.getUserInfo;
return avatar || headerImg;
});

return {
headerImg,
avatar,
register,
handleSubmit: () => {
createMessage.success('更新成功!');
Expand Down
29 changes: 22 additions & 7 deletions src/views/sys/lock/LockPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
>
<div
:class="`${prefixCls}__unlock`"
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"
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
"
@click="handleShowForm(false)"
v-show="showDate"
>
Expand All @@ -28,9 +44,9 @@
<div :class="`${prefixCls}-entry`" v-show="!showDate">
<div :class="`${prefixCls}-entry-content`">
<div :class="`${prefixCls}-entry__header enter-x`">
<img :src="headerImg" :class="`${prefixCls}-entry__header-img`" />
<img :src="userinfo.avatar || headerImg" :class="`${prefixCls}-entry__header-img`" />
<p :class="`${prefixCls}-entry__header-name`">
{{ realName }}
{{ userinfo.realName }}
</p>
</div>
<InputPassword
Expand Down Expand Up @@ -108,9 +124,8 @@

const { t } = useI18n();

const realName = computed(() => {
const { realName } = userStore.getUserInfo || {};
return realName;
const userinfo = computed(() => {
return userStore.getUserInfo || {};
});

/**
Expand Down Expand Up @@ -141,7 +156,7 @@

return {
goLogin,
realName,
userinfo,
unLock,
errMsg,
loading,
Expand Down
1 change: 1 addition & 0 deletions types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface UserInfo {
userId: string | number;
username: string;
realName: string;
avatar: string;
desc?: string;
}

Expand Down