diff --git a/common/utils.js b/common/utils.js index 6f5da6b..ddafdba 100644 --- a/common/utils.js +++ b/common/utils.js @@ -14,3 +14,36 @@ export const Debounce = (fn, wait) => { if (callNow) fn.apply(this, args) } } + +/** + * 处理头像/图片 URL + * @param {String} url 图片路径 + * @param {String} baseUrl 基础路径 + * @param {String} defaultUrl 默认图片路径 + */ +export const getHeadImgUrl = (url, baseUrl, defaultUrl = "/static/common/images/avatar_default2.png") => { + if (!url) return defaultUrl; + if (url.startsWith('http') || url.startsWith('https') || url.startsWith('blob:')) return url; + + // 统一处理反斜杠:将所有的 \ 替换为 / + let cleanUrl = url.replace(/\\/g, '/'); + + // 处理 baseUrl: 替换反斜杠并去除末尾斜杠 + let cleanBaseUrl = ''; + if (baseUrl) { + cleanBaseUrl = baseUrl.replace(/\\/g, '/').replace(/\/$/, ''); + } + + // 情况三:headSculptureUrl = "/UploadImages/tx.jpg" + if (cleanUrl.startsWith('/')) { + return cleanBaseUrl + cleanUrl; + } + + // 情况二:headSculptureUrl = "UploadImages/tx.jpg" + if (cleanUrl.includes('/')) { + return cleanBaseUrl + '/' + cleanUrl; + } + + // 情况一:headSculptureUrl = "tx.jpg" + return cleanBaseUrl + '/UploadImages/' + cleanUrl; +} diff --git a/main.js b/main.js index 33b03ad..38e3cf6 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import App from './App'; import "./static/common/css/font.css" import common from './static/common/js/common' +import { getHeadImgUrl } from '@/common/utils.js'; import jweixin from 'jweixin-module' import { HubConnectionBuilder, @@ -27,6 +28,13 @@ var tips = function(title, type, time) { // 导入公用js Vue.prototype.$tips = tips Vue.prototype.common = common +Vue.prototype.$getHeadImgUrl = function (url, defaultUrl) { + let baseUrl = ''; + if (this.$u && this.$u.http && this.$u.http.config && this.$u.http.config.baseUrl) { + baseUrl = this.$u.http.config.baseUrl; + } + return getHeadImgUrl(url, baseUrl, defaultUrl); +} // 导入微信sdk Vue.prototype.jweixin = jweixin // 引入全局uView diff --git a/pages/chat/index.vue b/pages/chat/index.vue index 87f762f..eaa9ae8 100644 --- a/pages/chat/index.vue +++ b/pages/chat/index.vue @@ -21,12 +21,44 @@ > -
+
-
+
+
{{vuex_userType}}
+
+
{{ vuex_msgUser.name }}
+
+ + 今日已回复{{ + vuex_msgUser.todayNumberOfReplies || 0 + }}人 +
+
+ + + + 江西新能源科技职业学院 +
+
+
+ +
{{ vuex_msgUser.name }}
{{vuex_msgUser.shen}}
- - - -
@@ -231,19 +247,11 @@ export default { }, receiverHeadSculptureUrl() { - if (this.vuex_msgUser.headSculptureUrl) { - return this.baseUrl + "/" + this.vuex_msgUser.headSculptureUrl; - } - - return "/static/common/images/avatar_default2.png"; + return this.$getHeadImgUrl(this.vuex_msgUser.headSculptureUrl); }, headSculptureUrl() { - if (this.vuex_user.HeadSculptureUrl) { - return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl; - } - - return "/static/common/images/avatar_default2.png"; + return this.$getHeadImgUrl(this.vuex_user.HeadSculptureUrl); }, }, @@ -469,11 +477,44 @@ export default { gap: 16rpx; flex: 1; - .teacher-name { - font-family: PingFang SC; - font-weight: bold; - font-size: 36rpx; - color: #333333; + .teacher-header { + display: flex; + align-items: center; + + .teacher-name { + font-family: PingFang SC; + font-weight: bold; + font-size: 36rpx; + color: #333333; + height: 52rpx; + line-height: 50rpx; + margin-right: 20rpx; + } + + + + .reply-tag { + display: flex; + align-items: center; + background-color: #eaedfc; + border-radius: 24rpx; + padding: 10rpx 24rpx; + // height: 48rpx; + box-sizing: border-box; + + .reply-icon { + width: 24rpx; + height: 24rpx; + margin-right: 8rpx; + } + + text { + font-size: 24rpx; + color: #4f6aff; + line-height: 1; + letter-spacing: 1rpx; + } + } } .teacher-name-row { display: flex; diff --git a/pages/home/admissions/index.vue b/pages/home/admissions/index.vue index 255eaf9..feea492 100644 --- a/pages/home/admissions/index.vue +++ b/pages/home/admissions/index.vue @@ -26,7 +26,7 @@ > diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index 8e9d3bf..e62da6b 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -193,10 +193,7 @@ {{ getTransferCardTip(message) }} @@ -321,7 +318,7 @@ class="tab-item" v-for="(tab, index) in floatingTabs" :key="index" - @click="handleFeatureClick({ title: tab.title })" + @click="handleFeatureClick({ title: tab.title, path: tab.path })" > {{ tab.title }} @@ -445,6 +442,7 @@ export default { { title: "招生在线", icon: "/static/common/images/icon_admissions2.png", + path: "/pages/home/admissions/index", }, { title: "转人工", @@ -506,23 +504,10 @@ export default { computed: { headSculptureUrl() { - if (this.vuex_user.HeadSculptureUrl) { - return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl; - } - - return "/static/common/images/avatar.png"; + return this.$getHeadImgUrl(this.vuex_user.HeadSculptureUrl); }, receiverHeadSculptureUrl() { - const url = - (this.vuex_msgUser && - (this.vuex_msgUser.headSculptureUrl || - this.vuex_msgUser.HeadSculptureUrl)) || - ""; - if (url) { - return this.baseUrl + "/" + url; - } - - return "/static/common/images/avatar_default2.png"; + return this.$getHeadImgUrl(this.vuex_msgUser.headSculptureUrl); }, aiMessageGroups() { return Array.isArray(this.vuex_aiMessageGroups) @@ -544,7 +529,8 @@ export default { isLiveAgentChat() { if (!this.vuex_isTransferChat) return false; const current = this.currentDMid || ""; - const active = this.vuex_msgUser && this.vuex_msgUser.dialogueManagementId; + const active = + this.vuex_msgUser && this.vuex_msgUser.dialogueManagementId; return !!(current && active && String(active) === String(current)); }, }, @@ -677,7 +663,6 @@ export default { this.resetChatState({ isChat: false }); return; } - if (item.title === "转人工") { this.handleTransferEntryClick(); return; @@ -746,7 +731,7 @@ export default { this.isTransferSubmitting = false; const nextList = this.aiMessageGroups.filter( - (m) => !(m && m.customType === "transferCard") + (m) => !(m && m.customType === "transferCard"), ); nextList.push(this.createLocalUserTextMessage("转人工")); @@ -767,14 +752,10 @@ export default { const cardId = this.activeTransferCardId; const findCardIndex = (list) => { if (cardId) { - const byId = list.findIndex( - (m) => m && m.id === cardId - ); + const byId = list.findIndex((m) => m && m.id === cardId); if (byId >= 0) return byId; } - return list.findIndex( - (m) => m && m.customType === "transferCard" - ); + return list.findIndex((m) => m && m.customType === "transferCard"); }; const updateTransferCard = (patch) => { const list = this.aiMessageGroups; @@ -792,7 +773,8 @@ export default { if (idx < 0) return; const current = list[idx] || {}; - if (this.isTransferSubmitting || current.transferStatus === "done") return; + if (this.isTransferSubmitting || current.transferStatus === "done") + return; updateTransferCard({ transferStatus: "idle", @@ -815,7 +797,8 @@ export default { .TransferToALiveAgentApi(params) .then((res) => { const succeed = res && res.succeed !== false; - const serverTip = (res && res.data && res.data.message) || (res && res.error) || ""; + const serverTip = + (res && res.data && res.data.message) || (res && res.error) || ""; if (!succeed) { updateTransferCard({ transferStatus: "idle", @@ -940,15 +923,11 @@ export default { this.currentDMid = data.dmid; // 从消息列表中移除加载状态消息 - const baseList = this.aiMessageGroups.filter( - (msg) => !msg.isLoading - ); + const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading); // 创建AI回复消息对象 const aiMessage = { - id: - data.conversationId || - Math.random().toString(36).substring(2, 15), + id: data.messageId || Math.random().toString(36).substring(2, 15), message: data.content, sendDate: "", isSend: true, @@ -966,9 +945,7 @@ export default { console.error("API请求失败:", error); // 从消息列表中移除加载状态消息 - const baseList = this.aiMessageGroups.filter( - (msg) => !msg.isLoading - ); + const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading); // 添加错误消息 const errorMessage = { @@ -983,10 +960,7 @@ export default { displayTime: "", }; - this.$store.commit( - "push_AiMsgList", - baseList.concat([errorMessage]) - ); + this.$store.commit("push_AiMsgList", baseList.concat([errorMessage])); }); }, @@ -1058,7 +1032,7 @@ export default { // 从消息列表中移除加载状态消息 const baseList = this.aiMessageGroups.filter( - (msg) => !msg.isLoading + (msg) => !msg.isLoading, ); // 创建AI回复消息对象 @@ -1077,15 +1051,12 @@ export default { }; // 添加到消息列表 - this.$store.commit( - "push_AiMsgList", - baseList.concat([aiMessage]) - ); + this.$store.commit("push_AiMsgList", baseList.concat([aiMessage])); } else { // 从消息列表中移除加载状态消息 this.$store.commit( "push_AiMsgList", - this.aiMessageGroups.filter((msg) => !msg.isLoading) + this.aiMessageGroups.filter((msg) => !msg.isLoading), ); } }) @@ -1093,9 +1064,7 @@ export default { console.error("API请求失败:", error); // 从消息列表中移除加载状态消息 - const baseList = this.aiMessageGroups.filter( - (msg) => !msg.isLoading - ); + const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading); // 添加错误消息 const errorMessage = { @@ -1110,10 +1079,7 @@ export default { displayTime: "", }; - this.$store.commit( - "push_AiMsgList", - baseList.concat([errorMessage]) - ); + this.$store.commit("push_AiMsgList", baseList.concat([errorMessage])); }); }, @@ -1167,10 +1133,7 @@ export default { const currentList = res.item2 || []; // 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面 - this.$store.commit( - "push_AiMsgList", - this.sortMessages(currentList) - ); + this.$store.commit("push_AiMsgList", this.sortMessages(currentList)); }) .finally(() => { // 延迟重置切换对话标志位,确保滚动事件处理完成 @@ -1207,14 +1170,14 @@ export default { const prevList = res3?.item2 || []; this.$store.commit( "push_AiMsgList", - this.sortMessages(prevList) + this.sortMessages(prevList), ); this.pageQuery.PageIndex = prevIndex; }); } else { this.$store.commit( "push_AiMsgList", - this.sortMessages(currentList) + this.sortMessages(currentList), ); } }); @@ -1277,10 +1240,7 @@ export default { // 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面 const nextPageMessageGroups = sortChatMessages(res.item2 || []); - this.$store.commit( - "prepend_AiMsgList", - nextPageMessageGroups - ); + this.$store.commit("prepend_AiMsgList", nextPageMessageGroups); }) .finally(() => { setTimeout(() => { diff --git a/pages/home/userSetting/index.vue b/pages/home/userSetting/index.vue index 289711a..92b8fc1 100644 --- a/pages/home/userSetting/index.vue +++ b/pages/home/userSetting/index.vue @@ -251,7 +251,7 @@ export default { this.imageUrl = ""; this.imageValue = [ { - url: "/static/common/images/avatar_default.jpg", + url: "/static/common/images/avatar_default2.png", extname: "jpg", name: "", }, diff --git a/store/index.js b/store/index.js index 880d37f..3e99122 100644 --- a/store/index.js +++ b/store/index.js @@ -499,9 +499,13 @@ const store = new Vuex.Store({ dialogueManagementId !== "00000000-0000-0000-0000-000000000000" ) { // 有会话ID,直接进入会话 - commit("set_MsgUser", { ...user }); - uni.navigateTo({ - url: `/pages/chat/index`, + Vue.prototype.$u.api.GetReceiverUserInfoApi({ Id: id }).then((res) => { + if (res.succeed && res.data) { + commit("set_MsgUser", { ...res.data, dialogueManagementId }); + uni.navigateTo({ + url: `/pages/chat/index`, + }); + } }); return; } @@ -515,19 +519,13 @@ const store = new Vuex.Store({ const resId = res1.data?.dialogueManagementId || ""; if (res1 && res1.succeed) { - // 获取接收者信息,这里没啥用(先注释) - // Vue.prototype.$u.api.GetReceiverUserInfoApi({ Id: id }).then((res) => { - // if (res.succeed && res.data) { - // commit("set_MsgUser", { ...res.data, dialogueManagementId }); - // uni.navigateTo({ - // url: `/pages/chat/index`, - // }); - // return; - // } - // }); - commit("set_MsgUser", { ...user, dialogueManagementId: resId }); - uni.navigateTo({ - url: `/pages/chat/index`, + Vue.prototype.$u.api.GetReceiverUserInfoApi({ Id: id }).then((res) => { + if (res.succeed && res.data) { + commit("set_MsgUser", { ...res.data, dialogueManagementId: resId }); + uni.navigateTo({ + url: `/pages/chat/index`, + }); + } }); return; }