refactor(home): 优化代码结构和逻辑,提取头像URL生成方法
This commit is contained in:
parent
d2cf481a67
commit
c8b66929ae
|
|
@ -193,10 +193,7 @@
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
class="transfer-card-status"
|
class="transfer-card-status"
|
||||||
v-if="
|
v-if="isTransferSubmitting || !!message.transferTipText"
|
||||||
isTransferSubmitting ||
|
|
||||||
!!message.transferTipText
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
{{ getTransferCardTip(message) }}
|
{{ getTransferCardTip(message) }}
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -321,7 +318,7 @@
|
||||||
class="tab-item"
|
class="tab-item"
|
||||||
v-for="(tab, index) in floatingTabs"
|
v-for="(tab, index) in floatingTabs"
|
||||||
:key="index"
|
:key="index"
|
||||||
@click="handleFeatureClick({ title: tab.title })"
|
@click="handleFeatureClick({ title: tab.title, path: tab.path })"
|
||||||
>
|
>
|
||||||
<image class="tab-icon" :src="tab.icon" mode="scaleToFill" />
|
<image class="tab-icon" :src="tab.icon" mode="scaleToFill" />
|
||||||
<text>{{ tab.title }}</text>
|
<text>{{ tab.title }}</text>
|
||||||
|
|
@ -445,6 +442,7 @@ export default {
|
||||||
{
|
{
|
||||||
title: "招生在线",
|
title: "招生在线",
|
||||||
icon: "/static/common/images/icon_admissions2.png",
|
icon: "/static/common/images/icon_admissions2.png",
|
||||||
|
path: "/pages/home/admissions/index",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "转人工",
|
title: "转人工",
|
||||||
|
|
@ -506,23 +504,10 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
headSculptureUrl() {
|
headSculptureUrl() {
|
||||||
if (this.vuex_user.HeadSculptureUrl) {
|
return this.$getHeadImgUrl(this.vuex_user.HeadSculptureUrl);
|
||||||
return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "/static/common/images/avatar.png";
|
|
||||||
},
|
},
|
||||||
receiverHeadSculptureUrl() {
|
receiverHeadSculptureUrl() {
|
||||||
const url =
|
return this.$getHeadImgUrl(this.vuex_msgUser.headSculptureUrl);
|
||||||
(this.vuex_msgUser &&
|
|
||||||
(this.vuex_msgUser.headSculptureUrl ||
|
|
||||||
this.vuex_msgUser.HeadSculptureUrl)) ||
|
|
||||||
"";
|
|
||||||
if (url) {
|
|
||||||
return this.baseUrl + "/" + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "/static/common/images/avatar_default2.png";
|
|
||||||
},
|
},
|
||||||
aiMessageGroups() {
|
aiMessageGroups() {
|
||||||
return Array.isArray(this.vuex_aiMessageGroups)
|
return Array.isArray(this.vuex_aiMessageGroups)
|
||||||
|
|
@ -544,7 +529,8 @@ export default {
|
||||||
isLiveAgentChat() {
|
isLiveAgentChat() {
|
||||||
if (!this.vuex_isTransferChat) return false;
|
if (!this.vuex_isTransferChat) return false;
|
||||||
const current = this.currentDMid || "";
|
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));
|
return !!(current && active && String(active) === String(current));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -677,7 +663,6 @@ export default {
|
||||||
this.resetChatState({ isChat: false });
|
this.resetChatState({ isChat: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.title === "转人工") {
|
if (item.title === "转人工") {
|
||||||
this.handleTransferEntryClick();
|
this.handleTransferEntryClick();
|
||||||
return;
|
return;
|
||||||
|
|
@ -746,7 +731,7 @@ export default {
|
||||||
this.isTransferSubmitting = false;
|
this.isTransferSubmitting = false;
|
||||||
|
|
||||||
const nextList = this.aiMessageGroups.filter(
|
const nextList = this.aiMessageGroups.filter(
|
||||||
(m) => !(m && m.customType === "transferCard")
|
(m) => !(m && m.customType === "transferCard"),
|
||||||
);
|
);
|
||||||
|
|
||||||
nextList.push(this.createLocalUserTextMessage("转人工"));
|
nextList.push(this.createLocalUserTextMessage("转人工"));
|
||||||
|
|
@ -767,14 +752,10 @@ export default {
|
||||||
const cardId = this.activeTransferCardId;
|
const cardId = this.activeTransferCardId;
|
||||||
const findCardIndex = (list) => {
|
const findCardIndex = (list) => {
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
const byId = list.findIndex(
|
const byId = list.findIndex((m) => m && m.id === cardId);
|
||||||
(m) => m && m.id === cardId
|
|
||||||
);
|
|
||||||
if (byId >= 0) return byId;
|
if (byId >= 0) return byId;
|
||||||
}
|
}
|
||||||
return list.findIndex(
|
return list.findIndex((m) => m && m.customType === "transferCard");
|
||||||
(m) => m && m.customType === "transferCard"
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
const updateTransferCard = (patch) => {
|
const updateTransferCard = (patch) => {
|
||||||
const list = this.aiMessageGroups;
|
const list = this.aiMessageGroups;
|
||||||
|
|
@ -792,7 +773,8 @@ export default {
|
||||||
if (idx < 0) return;
|
if (idx < 0) return;
|
||||||
|
|
||||||
const current = list[idx] || {};
|
const current = list[idx] || {};
|
||||||
if (this.isTransferSubmitting || current.transferStatus === "done") return;
|
if (this.isTransferSubmitting || current.transferStatus === "done")
|
||||||
|
return;
|
||||||
|
|
||||||
updateTransferCard({
|
updateTransferCard({
|
||||||
transferStatus: "idle",
|
transferStatus: "idle",
|
||||||
|
|
@ -815,7 +797,8 @@ export default {
|
||||||
.TransferToALiveAgentApi(params)
|
.TransferToALiveAgentApi(params)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const succeed = res && res.succeed !== false;
|
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) {
|
if (!succeed) {
|
||||||
updateTransferCard({
|
updateTransferCard({
|
||||||
transferStatus: "idle",
|
transferStatus: "idle",
|
||||||
|
|
@ -940,15 +923,11 @@ export default {
|
||||||
this.currentDMid = data.dmid;
|
this.currentDMid = data.dmid;
|
||||||
|
|
||||||
// 从消息列表中移除加载状态消息
|
// 从消息列表中移除加载状态消息
|
||||||
const baseList = this.aiMessageGroups.filter(
|
const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading);
|
||||||
(msg) => !msg.isLoading
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建AI回复消息对象
|
// 创建AI回复消息对象
|
||||||
const aiMessage = {
|
const aiMessage = {
|
||||||
id:
|
id: data.messageId || Math.random().toString(36).substring(2, 15),
|
||||||
data.messageId ||
|
|
||||||
Math.random().toString(36).substring(2, 15),
|
|
||||||
message: data.content,
|
message: data.content,
|
||||||
sendDate: "",
|
sendDate: "",
|
||||||
isSend: true,
|
isSend: true,
|
||||||
|
|
@ -966,9 +945,7 @@ export default {
|
||||||
console.error("API请求失败:", error);
|
console.error("API请求失败:", error);
|
||||||
|
|
||||||
// 从消息列表中移除加载状态消息
|
// 从消息列表中移除加载状态消息
|
||||||
const baseList = this.aiMessageGroups.filter(
|
const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading);
|
||||||
(msg) => !msg.isLoading
|
|
||||||
);
|
|
||||||
|
|
||||||
// 添加错误消息
|
// 添加错误消息
|
||||||
const errorMessage = {
|
const errorMessage = {
|
||||||
|
|
@ -983,10 +960,7 @@ export default {
|
||||||
displayTime: "",
|
displayTime: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$store.commit(
|
this.$store.commit("push_AiMsgList", baseList.concat([errorMessage]));
|
||||||
"push_AiMsgList",
|
|
||||||
baseList.concat([errorMessage])
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1058,7 +1032,7 @@ export default {
|
||||||
|
|
||||||
// 从消息列表中移除加载状态消息
|
// 从消息列表中移除加载状态消息
|
||||||
const baseList = this.aiMessageGroups.filter(
|
const baseList = this.aiMessageGroups.filter(
|
||||||
(msg) => !msg.isLoading
|
(msg) => !msg.isLoading,
|
||||||
);
|
);
|
||||||
|
|
||||||
// 创建AI回复消息对象
|
// 创建AI回复消息对象
|
||||||
|
|
@ -1077,15 +1051,12 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
// 添加到消息列表
|
// 添加到消息列表
|
||||||
this.$store.commit(
|
this.$store.commit("push_AiMsgList", baseList.concat([aiMessage]));
|
||||||
"push_AiMsgList",
|
|
||||||
baseList.concat([aiMessage])
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// 从消息列表中移除加载状态消息
|
// 从消息列表中移除加载状态消息
|
||||||
this.$store.commit(
|
this.$store.commit(
|
||||||
"push_AiMsgList",
|
"push_AiMsgList",
|
||||||
this.aiMessageGroups.filter((msg) => !msg.isLoading)
|
this.aiMessageGroups.filter((msg) => !msg.isLoading),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -1093,9 +1064,7 @@ export default {
|
||||||
console.error("API请求失败:", error);
|
console.error("API请求失败:", error);
|
||||||
|
|
||||||
// 从消息列表中移除加载状态消息
|
// 从消息列表中移除加载状态消息
|
||||||
const baseList = this.aiMessageGroups.filter(
|
const baseList = this.aiMessageGroups.filter((msg) => !msg.isLoading);
|
||||||
(msg) => !msg.isLoading
|
|
||||||
);
|
|
||||||
|
|
||||||
// 添加错误消息
|
// 添加错误消息
|
||||||
const errorMessage = {
|
const errorMessage = {
|
||||||
|
|
@ -1110,10 +1079,7 @@ export default {
|
||||||
displayTime: "",
|
displayTime: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$store.commit(
|
this.$store.commit("push_AiMsgList", baseList.concat([errorMessage]));
|
||||||
"push_AiMsgList",
|
|
||||||
baseList.concat([errorMessage])
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1167,10 +1133,7 @@ export default {
|
||||||
|
|
||||||
const currentList = res.item2 || [];
|
const currentList = res.item2 || [];
|
||||||
// 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面
|
// 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面
|
||||||
this.$store.commit(
|
this.$store.commit("push_AiMsgList", this.sortMessages(currentList));
|
||||||
"push_AiMsgList",
|
|
||||||
this.sortMessages(currentList)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
// 延迟重置切换对话标志位,确保滚动事件处理完成
|
// 延迟重置切换对话标志位,确保滚动事件处理完成
|
||||||
|
|
@ -1207,14 +1170,14 @@ export default {
|
||||||
const prevList = res3?.item2 || [];
|
const prevList = res3?.item2 || [];
|
||||||
this.$store.commit(
|
this.$store.commit(
|
||||||
"push_AiMsgList",
|
"push_AiMsgList",
|
||||||
this.sortMessages(prevList)
|
this.sortMessages(prevList),
|
||||||
);
|
);
|
||||||
this.pageQuery.PageIndex = prevIndex;
|
this.pageQuery.PageIndex = prevIndex;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$store.commit(
|
this.$store.commit(
|
||||||
"push_AiMsgList",
|
"push_AiMsgList",
|
||||||
this.sortMessages(currentList)
|
this.sortMessages(currentList),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1277,10 +1240,7 @@ export default {
|
||||||
// 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面
|
// 将消息按sendDate升序排列,时间相同时用户消息(interactMode=0)排在前面
|
||||||
const nextPageMessageGroups = sortChatMessages(res.item2 || []);
|
const nextPageMessageGroups = sortChatMessages(res.item2 || []);
|
||||||
|
|
||||||
this.$store.commit(
|
this.$store.commit("prepend_AiMsgList", nextPageMessageGroups);
|
||||||
"prepend_AiMsgList",
|
|
||||||
nextPageMessageGroups
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue