fix:修复头像没有默认值的bug

This commit is contained in:
Xwen
2023-12-14 23:47:39 +08:00
parent 212606f638
commit 7d9e6f3a23
3 changed files with 4 additions and 7 deletions

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -50,14 +50,14 @@ const userInfo = reactive({
role: [],
id: "",
});
const iconUrl = ref("/src/assets/logo.ico");
const iconUrl = ref("../../src/assets/common/icons/logo.ico");
const iconUrlHandler = () => {
if (
userInfo.icon == null ||
userInfo.icon == undefined ||
userInfo.icon == ""
) {
return "/src/assets/logo.ico";
return "../../src/assets/common/icons/logo.ico";
}
return `${import.meta.env.VITE_APP_BASEAPI}/file/${userInfo.icon}`;
};
@@ -88,7 +88,6 @@ const Init = () => {
userInfo.role = props.userInfo.role;
userInfo.id = props.userInfo.id;
iconUrl.value = iconUrlHandler(userInfo.icon);
console.log("使用传入值:", iconUrl.value);
}
//使用当前登录用户
@@ -97,8 +96,7 @@ const Init = () => {
userInfo.nick = userStore.name;
userInfo.role = userStore.role;
userInfo.id = userStore.id;
iconUrl.value = userInfo.icon;
console.log("当前登陆:", iconUrl.value);
iconUrl.value = iconUrlHandler(userInfo.icon);
}
};
</script>

View File

@@ -45,9 +45,8 @@ const useUserStore = defineStore("user", {
const user = res.user;
const avatar =
user.icon == "" || user.icon == null
? "/src/assets/logo.ico"
? "../../src/assets/common/icons/logo.ico"
: import.meta.env.VITE_APP_BASEAPI + "/file/" + user.icon;
console.log(avatar, "store的avatar");
if (res.roleCodes && res.roleCodes.length > 0) {
// 验证返回的roles是否是一个非空数组
this.roles = res.roleCodes;