2023-12-14 23:29:36 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="avatar">
|
|
|
|
|
|
<div class="avatar-left">
|
|
|
|
|
|
<el-avatar :size="props.size" :src="iconUrl" />
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="props.isSelf">
|
|
|
|
|
|
<div class="nick">{{ userInfo.nick }}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="!props.isSelf">
|
|
|
|
|
|
<div class="nick" :class="{ mt_1: props.time != 'undefined' }">
|
|
|
|
|
|
{{ userInfo.nick }}
|
2023-12-14 10:15:23 +08:00
|
|
|
|
</div>
|
2023-12-14 23:29:36 +08:00
|
|
|
|
<div class="remarks" v-if="props.time">{{ props.time }}</div>
|
|
|
|
|
|
<div class="remarks">
|
|
|
|
|
|
<slot name="bottom" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info" v-if="!props.isSelf">
|
|
|
|
|
|
<el-tag class="ml-2" type="warning">V8</el-tag>
|
|
|
|
|
|
<el-tag class="ml-2" type="danger">会员</el-tag>
|
|
|
|
|
|
</div>
|
2023-12-14 10:15:23 +08:00
|
|
|
|
</div>
|
2023-12-14 23:29:36 +08:00
|
|
|
|
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
v-if="props.showWatching"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
size="default"
|
|
|
|
|
|
icon="Plus"
|
|
|
|
|
|
>关注</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
</div>
|
2023-12-14 10:15:23 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
2023-12-14 23:29:36 +08:00
|
|
|
|
import useUserStore from "@/stores/user";
|
|
|
|
|
|
import { reactive, watch, onMounted, computed, ref } from "vue";
|
2023-12-14 10:15:23 +08:00
|
|
|
|
//userInfo
|
|
|
|
|
|
//{icon,name,role,id},根据判断userInfo是否等于未定义,来觉得是当前登录用户信息,还是其他人信息
|
2023-12-14 23:29:36 +08:00
|
|
|
|
const props = defineProps([
|
|
|
|
|
|
"size",
|
|
|
|
|
|
"showWatching",
|
|
|
|
|
|
"time",
|
|
|
|
|
|
"userInfo",
|
|
|
|
|
|
"isSelf",
|
|
|
|
|
|
]);
|
2023-12-14 10:15:23 +08:00
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
const userInfo = reactive({
|
2023-12-14 23:29:36 +08:00
|
|
|
|
icon: "",
|
|
|
|
|
|
nick: "",
|
|
|
|
|
|
role: [],
|
|
|
|
|
|
id: "",
|
2023-12-14 10:15:23 +08:00
|
|
|
|
});
|
2023-12-15 00:56:23 +08:00
|
|
|
|
const iconUrl = ref("/favicon.ico");
|
2023-12-14 10:15:23 +08:00
|
|
|
|
const iconUrlHandler = () => {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
if (
|
|
|
|
|
|
userInfo.icon == null ||
|
|
|
|
|
|
userInfo.icon == undefined ||
|
|
|
|
|
|
userInfo.icon == ""
|
|
|
|
|
|
) {
|
2023-12-15 00:56:23 +08:00
|
|
|
|
return "/favicon.ico";
|
2023-12-14 23:29:36 +08:00
|
|
|
|
}
|
2023-12-15 01:10:58 +08:00
|
|
|
|
return `${import.meta.env.VITE_APP_BASEAPI}${userInfo.icon}`;
|
2023-12-14 23:29:36 +08:00
|
|
|
|
};
|
2023-12-14 10:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
watch(userStore, (n) => {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
if (props.userInfo == undefined) {
|
|
|
|
|
|
userInfo.nick = n.name;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-12-14 10:15:23 +08:00
|
|
|
|
|
2023-12-14 23:29:36 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props,
|
|
|
|
|
|
(n) => {
|
2023-12-14 10:15:23 +08:00
|
|
|
|
Init();
|
2023-12-14 23:29:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
{ deep: true }
|
|
|
|
|
|
);
|
2023-12-14 10:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
Init();
|
|
|
|
|
|
});
|
2023-12-14 10:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
const Init = () => {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
//使用传入值
|
|
|
|
|
|
if (props.userInfo != undefined) {
|
|
|
|
|
|
userInfo.icon = props.userInfo.icon;
|
|
|
|
|
|
userInfo.nick = props.userInfo.nick;
|
|
|
|
|
|
userInfo.role = props.userInfo.role;
|
|
|
|
|
|
userInfo.id = props.userInfo.id;
|
|
|
|
|
|
iconUrl.value = iconUrlHandler(userInfo.icon);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//使用当前登录用户
|
|
|
|
|
|
else {
|
|
|
|
|
|
userInfo.icon = userStore.icon;
|
|
|
|
|
|
userInfo.nick = userStore.name;
|
|
|
|
|
|
userInfo.role = userStore.role;
|
|
|
|
|
|
userInfo.id = userStore.id;
|
2023-12-14 23:47:39 +08:00
|
|
|
|
iconUrl.value = iconUrlHandler(userInfo.icon);
|
2023-12-14 23:29:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-12-14 10:15:23 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.mt_1 {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
margin-top: 0.5rem;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.nick {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
font-weight: bold;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
margin-top: 0.6rem;
|
|
|
|
|
|
margin-left: 1rem;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info .el-tag {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
margin-right: 1rem;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-icon {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
color: white;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-left {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
align-items: center;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-avatar {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
margin-right: 1.2rem;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.remarks {
|
2023-12-14 23:29:36 +08:00
|
|
|
|
padding-top: 0.5rem;
|
|
|
|
|
|
color: #8c8c8c;
|
2023-12-14 10:15:23 +08:00
|
|
|
|
}
|
2023-12-14 23:29:36 +08:00
|
|
|
|
</style>
|