perf: 优化 pr 代码

This commit is contained in:
ChenZhaoYu
2023-02-15 13:26:02 +08:00
parent b2977d8c44
commit 79eeb51537
10 changed files with 132 additions and 76 deletions

View File

@@ -9,11 +9,14 @@ defineProps<Props>()
<template>
<div class="p-2 mt-2 rounded-md" :class="[reversal ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]']">
<span v-if="!reversal" class="leading-relaxed whitespace-pre-wrap" :class="[{ 'text-red-500': error }]" v-hljs>
<slot />
</span>
<span v-else class="leading-relaxed whitespace-pre-wrap" :class="[{ 'text-red-500': error }]">
<span v-highlight class="leading-relaxed whitespace-pre-wrap">
<slot />
</span>
</div>
</template>
<style>
.hljs {
background-color: #fff0 !important;
}
</style>

View File

@@ -17,7 +17,7 @@ const historyStore = useHistoryStore()
const scrollRef = ref<HTMLDivElement>()
const { addChat, clearChat: handleClear } = useChat()
const { addChat, clearChat } = useChat()
const prompt = ref('')
const loading = ref(false)
@@ -54,7 +54,7 @@ async function handleSubmit() {
}
catch (error: any) {
if (error.message !== 'cancelled')
addMessage(`Error: ${error.message ?? 'Request failed, please try again later.'}`, { error: true })
addMessage(`${error.message ?? 'Request failed, please try again later.'}`, { error: true })
}
finally {
loading.value = false
@@ -79,8 +79,12 @@ function scrollToBottom() {
nextTick(() => scrollRef.value && (scrollRef.value.scrollTop = scrollRef.value.scrollHeight))
}
function handleClear() {
handleCancel()
clearChat()
}
function handleCancel() {
// 取消之后一定要重新赋值,否则会报错
controller.abort()
controller = new AbortController()
loading.value = false