wrong chat

This commit is contained in:
AceDataCloud committed 2023-12-30 19:12:48 +08:00
1 parent 6a16b1a16a
commit dd7d0b0a5d
2 files changed
+23 -20

No files matched your search

+1 -1
View File
@@ -68,7 +68,7 @@
import { defineComponent } from 'vue';
import { ElSkeleton, ElInput } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router/constants';
import { ROUTE_CHAT_CONVERSATION } from '@/router/constants';
import { chatOperator } from '@/operators';
import { IChatConversation } from '@/operators/chat/models';
import { Status } from '@/store/common/models';
+22 -19
View File
@@ -63,15 +63,18 @@ export default defineComponent({
},
computed: {
messages() {
return (
this.$store.state.chat.conversations?.find(
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
)?.messages || []
);
return this.$store.state.chat.conversations?.find(
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
)?.messages;
},
conversationId(): string | undefined {
return this.$route.params.id?.toString();
},
conversation() {
return this.$store.state.chat.conversations?.find(
(conversation: IChatConversation) => conversation.id === this.conversationId
);
},
application() {
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
},
@@ -85,9 +88,21 @@ export default defineComponent({
return this.$store.state.chat.getApplicationsStatus === Status.Request;
}
},
watch: {
conversationId() {
if (!this.conversation) {
this.onCreateNewConversation(this.conversationId);
}
}
},
mounted() {
if (!this.conversation) {
this.onCreateNewConversation(this.conversationId);
}
},
methods: {
async onCreateNewConversation() {
const newConversationId = uuid();
async onCreateNewConversation(id?: string) {
const newConversationId = id || uuid();
await this.$router.push({
name: ROUTE_CHAT_CONVERSATION,
params: {
@@ -117,10 +132,6 @@ export default defineComponent({
this.question = '';
await this.onFetchAnswer();
},
async onFetchHistory(id?: string) {
const { data: data } = await chatOperator.getConversation(id || this.conversationId);
this.messages = data.messages || [];
},
async onFetchAnswer() {
const token = this.application?.credential?.token;
const endpoint = this.application?.api?.endpoint;
@@ -153,14 +164,6 @@ export default defineComponent({
content: response.answer,
state: IChatMessageState.ANSWERING
};
if (!this.conversationId) {
this.$router.push({
name: ROUTE_CHAT_CONVERSATION,
params: {
id: response.conversation_id
}
});
}
}
}
)