feat(用户头像): 实现动态头像功能并完善用户信息同步

This commit is contained in:
yangzhe 2025-12-08 10:48:26 +08:00
parent ac24af1cf9
commit f8fd5988e6
4 changed files with 84 additions and 17 deletions

View File

@ -125,10 +125,7 @@
<view class="drawer-footer"> <view class="drawer-footer">
<view class="user-info"> <view class="user-info">
<image <image class="user-avatar" :src="headSculptureUrl"></image>
class="user-avatar"
src="/static/common/images/avatar.png"
></image>
<text class="user-name">{{ userName || "晓德塔," }}</text> <text class="user-name">{{ userName || "晓德塔," }}</text>
</view> </view>
<view class="settings" @click="handleSettingsClick"> <view class="settings" @click="handleSettingsClick">
@ -173,6 +170,7 @@ export default {
}, },
data() { data() {
return { return {
baseUrl: "",
showPopup: false, showPopup: false,
currentActiveGroup: -1, currentActiveGroup: -1,
currentActiveIndex: -1, currentActiveIndex: -1,
@ -193,6 +191,17 @@ export default {
// deleteTargetItem: null, // deleteTargetItem: null,
}; };
}, },
computed: {
headSculptureUrl() {
if (this.vuex_user.HeadSculptureUrl) {
return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl;
}
return "/static/common/images/avatar.png";
},
},
watch: { watch: {
show: { show: {
handler(newVal) { handler(newVal) {
@ -210,6 +219,7 @@ export default {
} }
// //
if (val) { if (val) {
this.baseUrl = this.$u.http.config.baseUrl;
this.activePopoverId = null; this.activePopoverId = null;
} }
}, },

View File

@ -148,7 +148,7 @@
</view> </view>
<image <image
class="user-avatar" class="user-avatar"
src="/static/common/images/avatar.png" :src="headSculptureUrl"
mode="scaleToFill" mode="scaleToFill"
/> />
</view> </view>
@ -296,6 +296,7 @@ export default {
}, },
data() { data() {
return { return {
baseUrl: "",
isChat: false, isChat: false,
currentConversationId: "", // ID currentConversationId: "", // ID
currentDMid: "", // DMId currentDMid: "", // DMId
@ -424,6 +425,17 @@ export default {
messageValue: "", // messageValue: "", //
}; };
}, },
computed: {
headSculptureUrl() {
if (this.vuex_user.HeadSculptureUrl) {
return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl;
}
return "/static/common/images/avatar.png";
},
},
watch: { watch: {
// //
messageGroups: { messageGroups: {
@ -448,6 +460,7 @@ export default {
}, },
}, },
onLoad() { onLoad() {
this.baseUrl = this.$u.http.config.baseUrl;
this.hotQARefresh(); // this.hotQARefresh(); //
}, },

View File

@ -233,13 +233,16 @@ export default {
this.$u.api.GetUserApi({ Id: this.vuex_user.Id }).then((res) => { this.$u.api.GetUserApi({ Id: this.vuex_user.Id }).then((res) => {
const data = res.data[0]; const data = res.data[0];
this.userInfo.name = data.name || ""; this.userInfo.name = data.name || "";
this.userInfo.gender = data.sex || ""; this.userInfo.gender = data.sex;
this.userInfo.region = data.Region || ""; this.userInfo.genderText =
data.sex === 0 ? "男" : data.sex === 1 ? "女" : "-";
this.userInfo.region = data.shen || "";
this.userInfo.regionText = data.shen || "";
if (data.headSculptureUrl) { if (data.headSculptureUrl) {
this.imageUrl = data.headSculptureUrl; this.imageUrl = data.headSculptureUrl;
this.imageValue = [ this.imageValue = [
{ {
url: data.headSculptureUrl, url: this.baseUrl + "/" + data.headSculptureUrl,
extname: "png", extname: "png",
name: "", name: "",
}, },
@ -254,6 +257,15 @@ export default {
}, },
]; ];
} }
const vuex_user = {
...this.vuex_user,
Name: data.name,
Sex: data.sex,
Shen: data.shen,
HeadSculptureUrl: data.headSculptureUrl,
};
this.$u.vuex("vuex_user", vuex_user);
}); });
}, },
// //
@ -285,6 +297,7 @@ export default {
title: "保存成功", title: "保存成功",
type: "success", type: "success",
}); });
this.getUserInfo(); //
} else { } else {
this.$refs.uToast.show({ this.$refs.uToast.show({
title: res.error || "保存失败", title: res.error || "保存失败",

View File

@ -461,16 +461,27 @@ export default {
this.$u.vuex("vuex_user", userInfo); this.$u.vuex("vuex_user", userInfo);
this.$u.vuex("vuex_userType", userType); // 0: 1: this.$u.vuex("vuex_userType", userType); // 0: 1:
// 退 //
// uni.setStorageSync("userType", userType); const redirect = () => {
//
const url = this.isTeacher const url = this.isTeacher
? "/pages/consultation/index" ? "/pages/consultation/index"
: "/pages/home/index/index"; : "/pages/home/index/index";
uni.reLaunch({ uni.reLaunch({
url: url, url: url,
}); });
};
this.getUserInfo()
.then(() => {
// 退
// uni.setStorageSync("userType", userType);
redirect();
})
.catch((err) => {
console.error("获取用户信息失败", err);
// 使
redirect();
});
}); });
}, },
@ -522,6 +533,23 @@ export default {
// //
this.loginParams.phone = value; this.loginParams.phone = value;
}, },
//
getUserInfo() {
// Promise 便
return this.$u.api.GetUserApi({ Id: this.vuex_user.Id }).then((res) => {
const data = res.data[0];
const vuex_user = {
...this.vuex_user,
Name: data.name,
Sex: data.sex,
Shen: data.shen,
HeadSculptureUrl: data.headSculptureUrl,
};
this.$u.vuex("vuex_user", vuex_user);
return vuex_user;
});
},
}, },
}; };
</script> </script>
@ -782,3 +810,6 @@ export default {
} }
} }
</style> </style>