【增加】消息增加 marked 渲染 markdown

This commit is contained in:
cherishsince 2024-05-13 18:26:28 +08:00
parent 7f25419caf
commit 10beee84fb
2 changed files with 19 additions and 8 deletions

View File

@ -52,6 +52,7 @@
"highlight.js": "^11.9.0", "highlight.js": "^11.9.0",
"jsencrypt": "^3.3.2", "jsencrypt": "^3.3.2",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"marked": "^12.0.2",
"min-dash": "^4.1.1", "min-dash": "^4.1.1",
"mitt": "^3.0.1", "mitt": "^3.0.1",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",

View File

@ -98,9 +98,7 @@
<el-text class="time">{{formatDate(item.createTime)}}</el-text> <el-text class="time">{{formatDate(item.createTime)}}</el-text>
</div> </div>
<div class="left-text-container"> <div class="left-text-container">
<el-text class="left-text"> <div class="left-text" v-html="item.content"></div>
{{item.content}}
</el-text>
</div> </div>
<div class="left-btns"> <div class="left-btns">
<div class="btn-cus" @click="noCopy(item.content)"> <div class="btn-cus" @click="noCopy(item.content)">
@ -126,9 +124,7 @@
<el-text class="time">{{formatDate(item.createTime)}}</el-text> <el-text class="time">{{formatDate(item.createTime)}}</el-text>
</div> </div>
<div class="right-text-container"> <div class="right-text-container">
<el-text class="right-text"> <div class="right-text" v-html="item.content"></div>
{{item.content}}
</el-text>
</div> </div>
<div class="right-btns"> <div class="right-btns">
<div class="btn-cus" @click="noCopy(item.content)"> <div class="btn-cus" @click="noCopy(item.content)">
@ -165,9 +161,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ChatMessageApi, ChatMessageSendVO, ChatMessageVO} from "@/api/ai/chat/message"; import 'highlight.js/styles/idea.css'
import {formatDate} from "@/utils/formatTime"; import {ChatMessageApi, ChatMessageSendVO, ChatMessageVO} from "@/api/ai/chat/message"
import {formatDate} from "@/utils/formatTime"
import {useClipboard} from '@vueuse/core' import {useClipboard} from '@vueuse/core'
import { marked } from 'marked'
// copy // copy
const { copy } = useClipboard(); const { copy } = useClipboard();
@ -257,6 +256,8 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
} else { } else {
const lastMessage = list.value[list.value.length - 1]; const lastMessage = list.value[list.value.length - 1];
lastMessage.content = lastMessage.content + data.content lastMessage.content = lastMessage.content + data.content
// markdown
lastMessage.content = marked(lastMessage.content)
list.value[list.value - 1] = lastMessage list.value[list.value - 1] = lastMessage
} }
// //
@ -285,7 +286,15 @@ const messageList = async () => {
try { try {
// //
const res = await ChatMessageApi.messageList(conversationId.value) const res = await ChatMessageApi.messageList(conversationId.value)
// markdown
// marked(this.markdownText)
res.map(item => {
item.content = marked(item.content)
})
list.value = res; list.value = res;
// //
scrollToBottom(); scrollToBottom();
} finally { } finally {
@ -558,6 +567,7 @@ onMounted(async () => {
.left-text { .left-text {
color: #393939; color: #393939;
//font-size: 14px;
} }
} }