From d9e171c43077478b5128fefdf5e76130fa46e4a4 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Wed, 22 May 2024 19:14:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E5=9C=BA=E7=99=BD=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81Markdown=E8=A1=A8=E6=A0=BC=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E3=80=82=20#496=20(#511)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/components/ai-chat/index.vue | 41 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index e11768587..948f0ae1d 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -234,22 +234,35 @@ const prologueList = computed(() => { const temp = props.available ? props.data?.prologue : '抱歉,当前正在维护,无法提供服务,请稍后再试!' - let arr: any = [] const lines = temp?.split('\n') - lines?.forEach((str: string, index: number) => { - if (isMdArray(str)) { - arr[index] = { - type: 'question', - str: str.replace(/^-\s+/, '') + return lines + .reduce((pre_array: Array, current: string, index: number) => { + const currentObj = isMdArray(current) + ? { + type: 'question', + str: current.replace(/^-\s+/, ''), + index: index + } + : { + type: 'md', + str: current, + index: index + } + if (pre_array.length > 0) { + const pre = pre_array[pre_array.length - 1] + if (!isMdArray(current) && pre.type == 'md') { + pre.str = [pre.str, current].join('\n') + pre.index = index + return pre_array + } else { + pre_array.push(currentObj) + } + } else { + pre_array.push(currentObj) } - } else { - arr[index] = { - type: 'md', - str - } - } - }) - return arr + return pre_array + }, []) + .sort((pre: any, next: any) => pre.index - next.index) }) watch(