diff --git a/components/ChatHistory.vue b/components/ChatHistory.vue index c52da2f..5ec355f 100644 --- a/components/ChatHistory.vue +++ b/components/ChatHistory.vue @@ -125,10 +125,7 @@ - + {{ userName || "晓德塔," }} @@ -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; } }, diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index fbdc72c..c32cd18 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -148,7 +148,7 @@ @@ -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(); // 获取热门聊天 }, diff --git a/pages/home/userSetting/index.vue b/pages/home/userSetting/index.vue index e7312a7..289711a 100644 --- a/pages/home/userSetting/index.vue +++ b/pages/home/userSetting/index.vue @@ -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 || "保存失败", diff --git a/pages/login/login/index.vue b/pages/login/login/index.vue index ba8acee..9680651 100644 --- a/pages/login/login/index.vue +++ b/pages/login/login/index.vue @@ -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; + }); + }, }, }; @@ -782,3 +810,6 @@ export default { } } + + +