feat(用户头像): 实现动态头像功能并完善用户信息同步
This commit is contained in:
parent
ac24af1cf9
commit
f8fd5988e6
|
|
@ -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;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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(); // 获取热门聊天
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 || "保存失败",
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
? "/pages/consultation/index"
|
||||||
|
: "/pages/home/index/index";
|
||||||
|
uni.reLaunch({
|
||||||
|
url: url,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 跳转至首页
|
this.getUserInfo()
|
||||||
const url = this.isTeacher
|
.then(() => {
|
||||||
? "/pages/consultation/index"
|
// 保存用户类型到本地存储,用于退出登录时重定向
|
||||||
: "/pages/home/index/index";
|
// uni.setStorageSync("userType", userType);
|
||||||
uni.reLaunch({
|
redirect();
|
||||||
url: url,
|
})
|
||||||
});
|
.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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue