fix:默认头像问题; #228

Merged
yangws merged 1 commits from yws_dev into main 2025-01-20 14:27:24 +08:00
2 changed files with 20 additions and 4 deletions

View File

@ -5,7 +5,7 @@
<el-popover ref="popoverRef" placement="right" trigger="hover" popper-class="popoverStyle" :tabindex="999" >
<template #reference>
<div class="user-info">
<el-image class="user-img" :src="userStore.user.avatar ==='/img/avatar-default.jpg' || userStore.user.avatar ==='/images/img-avatar.png' ? defaultUserImg : dev_api + userStore.user.avatar" />
<el-image class="user-img" :src="img" />
<span>{{ userStore.user.nickName }}</span>
</div>
</template>
@ -75,6 +75,9 @@ const activeId = ref('/home')
const version = ref(pkc.version)
const popoverRef = ref('')
//
const img = ref('')
const defaultImg = ['/img/avatar-default.jpg','/images/img-avatar.png','/src/assets/images/img-avatar.png']
//
const isStadium = () => {
@ -224,6 +227,11 @@ const logout = () => {
onMounted(() => {
userStore.getDeptInfo()
// getregisterinfo()
if(defaultImg.includes(userStore.user.avatar)){
img.value = defaultUserImg
}else{
img.value = dev_api.value + userStore.user.avatar
}
})
</script>

View File

@ -19,7 +19,7 @@
</template>
<script setup>
import {ref, reactive} from 'vue'
import {ref, reactive, onMounted} from 'vue'
import { uploadAvatar } from '@/api/system/user'
import useUserStore from '@/store/modules/user'
import { ElMessage } from 'element-plus'
@ -31,10 +31,11 @@ const userStore = useUserStore()
const open = ref(false)
const visible = ref(false)
const dev_api = ref(import.meta.env.VITE_APP_BASE_API)
const defaultImg = ['/img/avatar-default.jpg','/images/img-avatar.png','/src/assets/images/img-avatar.png']
//
const options = reactive({
img: userStore.user.avatar ==='/img/avatar-default.jpg' || userStore.user.avatar ==='/images/img-avatar.png' ? defaultUserImg : dev_api.value + userStore.user.avatar, //
img: '', //
autoCrop: true, //
autoCropWidth: 400, //
autoCropHeight: 400, //
@ -70,12 +71,19 @@ function uploadImg(data) {
/** 关闭窗口 */
function closeDialog() {
options.img = userStore.user.avatar ==='/img/avatar-default.jpg' || userStore.user.avatar ==='/images/img-avatar.png' ? defaultUserImg : dev_api.value + userStore.user.avatar
// options.img = userStore.user.avatar ==='/img/avatar-default.jpg' || userStore.user.avatar ==='/images/img-avatar.png' ? defaultUserImg : dev_api.value + userStore.user.avatar
options.visible = false
}
const cancle = () => {
open.value = false
}
onMounted(() => {
if(defaultImg.includes(userStore.user.avatar)){
options.img = defaultUserImg
}else{
options.img = dev_api.value + userStore.user.avatar
}
})
</script>
<style lang='scss' scoped>