feat(用户头像): 实现动态头像功能并完善用户信息同步
This commit is contained in:
parent
ac24af1cf9
commit
f8fd5988e6
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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(); // 获取热门聊天
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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 || "保存失败",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
// 跳转至首页
|
||||
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>
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue