refactor(home): 优化代码结构和逻辑,提取头像URL生成方法
This commit is contained in:
parent
d2cf481a67
commit
c8b66929ae
|
|
@ -193,10 +193,7 @@
|
|||
</view>
|
||||
<view
|
||||
class="transfer-card-status"
|
||||
v-if="
|
||||
isTransferSubmitting ||
|
||||
!!message.transferTipText
|
||||
"
|
||||
v-if="isTransferSubmitting || !!message.transferTipText"
|
||||
>
|
||||
{{ getTransferCardTip(message) }}
|
||||
</view>
|
||||
|
|
@ -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 })"
|
||||
>
|
||||
<image class="tab-icon" :src="tab.icon" mode="scaleToFill" />
|
||||
<text>{{ tab.title }}</text>
|
||||
|
|
@ -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.messageId ||
|
||||
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(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue