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

View File

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

View File

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

View File

@ -461,16 +461,27 @@ export default {
this.$u.vuex("vuex_user", userInfo);
this.$u.vuex("vuex_userType", userType); // 0: 1:
// 退
// uni.setStorageSync("userType", userType);
//
//
const redirect = () => {
const url = this.isTeacher
? "/pages/consultation/index"
: "/pages/home/index/index";
uni.reLaunch({
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;
},
//
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>
@ -782,3 +810,6 @@ export default {
}
}
</style>