diff --git a/src/components/dialoguePanel/DialoguePanel.vue b/src/components/dialoguePanel/DialoguePanel.vue index 38a8eadaa273197a5a7a07476d5d0f1f8be93873..c11bad5eca1e5325ce582b06558622eabbfaa66b 100644 --- a/src/components/dialoguePanel/DialoguePanel.vue +++ b/src/components/dialoguePanel/DialoguePanel.vue @@ -55,6 +55,8 @@ export interface DialoguePanelProps { userSelectedApp?: any; // recordList?: string[] | undefined; + // MessageList 结构 + messageArray?: MessageArray[] | undefined; // isCommentList?: string[] | undefined; // @@ -78,6 +80,7 @@ import JsonFormComponent from './JsonFormComponent.vue'; import { Metadata } from 'src/apis/paths/type'; import DialogueFlow from './DialogueFlow.vue'; import { api } from 'src/apis'; +import { MessageArray } from 'src/views/dialogue/types'; var option = ref(); var show = ref(false); const size = reactive({ @@ -93,9 +96,10 @@ const props = withDefaults(defineProps(), { // currentSelected: 0, needRegernerate: false, }); +const messageArray = ref(props.messageArray); const thoughtContent = ref(''); const index = ref(0); -const isComment = ref(props.isCommentList); +const isComment = ref("none"); const emits = defineEmits<{ (e: 'handleReport', qaRecordId: string, reason?: string): void; ( @@ -116,12 +120,13 @@ const handlePauseAndReGenerate = (cid?: number) => { if (!cid) { return; } - emits('clearSuggestion', props.key); if (props.isFinish) { // 重新生成 thoughtContent.value = ''; reGenerateAnswer(cid, user_selected_app.value); + index.value = messageArray.value.getAllItems().length - 1; + isComment.value = "none"; } else { // 停止生成 pausedStream(cid); @@ -154,9 +159,10 @@ const handleLike = async ( comment: !isSupport.value ? 'liked' : 'none', groupId: props.groupId, }).then((res) => { - if(res[0].status === 200){ - isComment.value[index.value] = 'liked'; - handleIsLike(); + if(res[1].code === 200){ + isSupport.value = isSupport.value ? false : true; + isAgainst.value = false; + messageArray.value.getAllItems()[index.value].comment = isSupport.value ? 'liked' : 'none'; } }) } else if (type === 'disliked') { @@ -182,7 +188,8 @@ const handleDislike = async ( { type: 'disliked', qaRecordId: qaRecordId, - comment: reason, + comment: !isAgainst.value ? 'disliked' : 'none', + dislikeReason: reason, groupId: props.groupId, reasonLink: reasionLink, reasonDescription: reasonDescription, @@ -190,8 +197,9 @@ const handleDislike = async ( ).then((res) => { if(res[0].status === 200){ isAgainstVisible.value = false; - isComment.value[index.value] = 'disliked'; - handleIsLike(); + isAgainst.value = isAgainst.value ? false : true; + isSupport.value = false; + messageArray.value.getAllItems()[index.value].comment = isAgainst.value ? 'disliked' : 'none'; }; }); }; @@ -244,7 +252,7 @@ const contentAfterMark = computed(() => { } //xxs将大于号转为html实体以防歧义;将< >替换为正常字符; let str = marked.parse( - xss(props.content[props.currentSelected]) + xss(props.content[index.value]) .replace(/>/g, '>') .replace(/</g, '<'), ); @@ -280,6 +288,7 @@ const prePageHandle = (cid: number) => { index.value = 0; } else { index.value--; + isComment.value = messageArray.value.getAllItems()[index.value].comment; handleIsLike(); } }; @@ -287,10 +296,11 @@ const prePageHandle = (cid: number) => { const nextPageHandle = (cid: number) => { thoughtContent.value = ''; nextPage(cid); - if (index.value === (props.isCommentList as number[]).length - 1) { - index.value = (props.isCommentList as number[]).length - 1; + if (index.value === (props.content as string[]).length - 1) { + index.value = (props.content as string[]).length - 1; } else { index.value++; + isComment.value = messageArray.value.getAllItems()[index.value].comment; handleIsLike(); } }; @@ -300,38 +310,43 @@ const isAgainst = ref(false); const handleIsLike = () => { if (isComment.value === undefined) { - return; + isSupport.value = false; + isAgainst.value = false; } else { - if (index.value <= isComment.value.length && isComment.value.length !== 0) { - let comment = isComment.value[index.value]; - if (comment !== 'none') { - isSupport.value = comment === 'liked'; + if (isComment.value !== 'none') { + isSupport.value = isComment.value === 'liked'; isAgainst.value = !isSupport.value; } else { isSupport.value = false; isAgainst.value = false; } - } } }; onMounted(() => { - isComment.value = props.isCommentList; + if(props.messageArray?.value){ + isComment.value = props.messageArray.value.getCommentbyIndex(index.value); + } setTimeout(() => { handleIsLike(); }, 200); }); watch( - () => props.isCommentList, + () => props.messageArray, () => { - if (isComment.value.length === props.isCommentList?.length) { - handleIsLike(); - } else { - isComment.value = props.isCommentList; + index.value = 0; + if(props.messageArray){ + index.value = props.messageArray?.getAllItems().length - 1; + } + messageArray.value = props.messageArray; + if(props.messageArray){ + isComment.value = props.messageArray.getAllItems()[index.value].comment; + } handleIsLike(); - } - }, + },{ + immediate: true, + } ); watch( @@ -379,6 +394,13 @@ watch( }, ); +watch( + () => index.value, + () => { + handleIsLike(); + } +) + onBeforeUnmount(() => { isComment.value = undefined; index.value = 0; @@ -548,7 +570,7 @@ const chatWithParams = async () => { @click="prePageHandle(Number(cid))" src="@/assets/svgs/arror_left.svg" /> - {{ currentSelected! + 1 }} + {{ index! + 1 }} {{ `/${content?.length}` }} { case 'text.add': { scrollBottom(); + //向message添加值 conversationItem.message[conversationItem.currentInd] += - message.content.text; + message.content.text; + //向messageList添加值 + conversationItem.messageList.getAllItems()[conversationItem.currentInd].message += + message.content.text; } break; case 'heartbeat': @@ -606,6 +610,14 @@ export const useSessionStore = defineStore('conversation', () => { ( conversationList.value[regenerateInd] as RobotConversationItem ).message.push(''); //123 + // 重新生成,指定某个回答,修改默认索引 + ( + conversationList.value[regenerateInd] as RobotConversationItem + ).messageList.push({ + message:"", + record_id:qaRecordId, + comment:"none", + }); ( conversationList.value[regenerateInd] as RobotConversationItem ).currentInd = @@ -772,9 +784,6 @@ export const useSessionStore = defineStore('conversation', () => { */ const getConversation = async (conversationId: string): Promise => { const [_, res] = await api.getHistoryConversation(conversationId); - //解析读取 records字段得到对话数组列表 - // const [_, res] = await api.getHistoryConversation(conversationId).records; - if (!_ && res) { conversationList.value = []; res.result.records.forEach((record) => { diff --git a/src/views/createapp/components/workFlowDebug.vue b/src/views/createapp/components/workFlowDebug.vue index 4c3628b3ce3522b96074fddad0291f426302129e..b15bb0596262b9c7aaecfc512d94e526314ff7cf 100644 --- a/src/views/createapp/components/workFlowDebug.vue +++ b/src/views/createapp/components/workFlowDebug.vue @@ -134,7 +134,6 @@ const handleSendMessage = async ( ) return; dialogueInput.value = ''; - // console.log(!currentSelectedSession.value, 'currentSelectedSession') if (!tmpConversationId.value) { const res = await generateSessionDebug({ debug: true }); tmpConversationId.value = res || 1; diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index 2bde91d12042115d946546c4305108865b605924..79edc0fed09d4332df4d4076db314adb1924cab4 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -757,6 +757,9 @@ watch( :isCommentList=" item.belong === 'robot' ? item.messageList.getCommentList() : '' " + :messageArray=" + item.belong === 'robot' ? item.messageList : '' + " :is-finish="getItem(item, 'isFinish')" :test="getItem(item, 'test')" :metadata="getItem(item, 'metadata')" diff --git a/src/views/dialogue/types.ts b/src/views/dialogue/types.ts index 7626b8301294ae9c67c490e0a3e43847d9008e09..54130b899fa97b82f01d32a821fa2e53cc912366 100644 --- a/src/views/dialogue/types.ts +++ b/src/views/dialogue/types.ts @@ -117,11 +117,15 @@ export class MessageArray { }; this.items.push(newItem); } - + push(item: MessageRecord): void { + this.items.push(item); + } getItem(index: number): MessageRecord | undefined { return this.items[index]; } - + getContentbyIndex(index: number): string | undefined { + return this.items[index]?.message; + } getLength(): number { return this.items.length; } @@ -139,19 +143,16 @@ export class MessageArray { } getCommentList(): string[] { - //类型断言,将undefined转换为0。 return this.items.map((item) => item.comment ? item.comment : 'none'); } - getCommentyIndex(index: number): string { + getCommentbyIndex(index: number): string { return this.items.map((item) => item.comment ? item.comment : 'none')[index]; } - - changeCommentByCidAndIndex( - cid: number, + changeCommentByIndex( index: number, comment: string, ): void { - + this.items[index].comment = comment; } }