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

View File

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