feat: 支持导出单次聊天的全部对话记录为Markdown文件或HTML文件 (#502)
This commit is contained in:
parent
a35b1b824e
commit
b24a19a035
@ -19,6 +19,7 @@
|
|||||||
"cropperjs": "^1.6.2",
|
"cropperjs": "^1.6.2",
|
||||||
"echarts": "^5.5.0",
|
"echarts": "^5.5.0",
|
||||||
"element-plus": "^2.5.6",
|
"element-plus": "^2.5.6",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"katex": "^0.16.10",
|
"katex": "^0.16.10",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@ -31,6 +32,7 @@
|
|||||||
"markdown-it-sup": "^1.0.0",
|
"markdown-it-sup": "^1.0.0",
|
||||||
"markdown-it-task-lists": "^2.1.1",
|
"markdown-it-task-lists": "^2.1.1",
|
||||||
"markdown-it-toc-done-right": "^4.2.0",
|
"markdown-it-toc-done-right": "^4.2.0",
|
||||||
|
"marked": "^12.0.2",
|
||||||
"md-editor-v3": "4.12.1",
|
"md-editor-v3": "4.12.1",
|
||||||
"medium-zoom": "^1.1.0",
|
"medium-zoom": "^1.1.0",
|
||||||
"mermaid": "^10.9.0",
|
"mermaid": "^10.9.0",
|
||||||
@ -49,6 +51,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rushstack/eslint-patch": "^1.3.2",
|
"@rushstack/eslint-patch": "^1.3.2",
|
||||||
"@tsconfig/node18": "^18.2.0",
|
"@tsconfig/node18": "^18.2.0",
|
||||||
|
"@types/file-saver": "^2.0.7",
|
||||||
"@types/jsdom": "^21.1.1",
|
"@types/jsdom": "^21.1.1",
|
||||||
"@types/markdown-it": "^13.0.7",
|
"@types/markdown-it": "^13.0.7",
|
||||||
"@types/markdown-it-highlightjs": "^3.3.4",
|
"@types/markdown-it-highlightjs": "^3.3.4",
|
||||||
|
|||||||
@ -7,7 +7,10 @@
|
|||||||
<div class="chat-pc__left border-r">
|
<div class="chat-pc__left border-r">
|
||||||
<div class="p-24 pb-0">
|
<div class="p-24 pb-0">
|
||||||
<el-button class="add-button w-full primary" @click="newChat">
|
<el-button class="add-button w-full primary" @click="newChat">
|
||||||
<el-icon><Plus /></el-icon><span class="ml-4">新建对话</span>
|
<el-icon>
|
||||||
|
<Plus />
|
||||||
|
</el-icon>
|
||||||
|
<span class="ml-4">新建对话</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
<p class="mt-20 mb-8">历史记录</p>
|
<p class="mt-20 mb-8">历史记录</p>
|
||||||
</div>
|
</div>
|
||||||
@ -46,6 +49,20 @@
|
|||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<span v-if="currentRecordList.length" class="flex align-center">
|
<span v-if="currentRecordList.length" class="flex align-center">
|
||||||
|
<el-dropdown class="mr-8">
|
||||||
|
<AppIcon
|
||||||
|
iconName="takeaway-box"
|
||||||
|
class="info mr-8"
|
||||||
|
style="font-size: 16px"
|
||||||
|
title="导出聊天记录"
|
||||||
|
></AppIcon>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item @click="exportMarkdown">导出 Markdown</el-dropdown-item>
|
||||||
|
<el-dropdown-item @click="exportHTML">导出 HTML</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
<AppIcon iconName="app-chat-record" class="info mr-8" style="font-size: 16px"></AppIcon>
|
<AppIcon iconName="app-chat-record" class="info mr-8" style="font-size: 16px"></AppIcon>
|
||||||
<span class="lighter"> {{ paginationConfig.total }} 条提问 </span>
|
<span class="lighter"> {{ paginationConfig.total }} 条提问 </span>
|
||||||
</span>
|
</span>
|
||||||
@ -76,10 +93,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, onMounted, nextTick, computed } from 'vue'
|
import { reactive, ref, onMounted, nextTick, computed } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
import { marked } from 'marked'
|
||||||
|
import { saveAs } from 'file-saver'
|
||||||
import applicationApi from '@/api/application'
|
import applicationApi from '@/api/application'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
import useResize from '@/layout/hooks/useResize'
|
import useResize from '@/layout/hooks/useResize'
|
||||||
useResize()
|
useResize()
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -144,6 +165,7 @@ function getAccessToken(token: string) {
|
|||||||
applicationAvailable.value = false
|
applicationAvailable.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProfile() {
|
function getProfile() {
|
||||||
applicationApi
|
applicationApi
|
||||||
.getProfile(loading)
|
.getProfile(loading)
|
||||||
@ -210,6 +232,7 @@ function getChatRecord() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const clickListHandle = (item: any) => {
|
const clickListHandle = (item: any) => {
|
||||||
if (item.id !== currentChatId.value) {
|
if (item.id !== currentChatId.value) {
|
||||||
paginationConfig.current_page = 1
|
paginationConfig.current_page = 1
|
||||||
@ -230,6 +253,28 @@ function refresh(id: string) {
|
|||||||
currentChatId.value = id
|
currentChatId.value = id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function exportMarkdown(): Promise<void> {
|
||||||
|
const suggestedName: string = `${currentChatId.value}.md`
|
||||||
|
const markdownContent: string = currentRecordList.value.map((record: any) =>
|
||||||
|
`# ${record.problem_text}\n\n${record.answer_text}\n\n`
|
||||||
|
).join('\n')
|
||||||
|
|
||||||
|
const blob: Blob = new Blob([markdownContent], { type: 'text/markdown;charset=utf-8' })
|
||||||
|
saveAs(blob, suggestedName)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportHTML(): Promise<void> {
|
||||||
|
const suggestedName: string = `${currentChatId.value}.html`
|
||||||
|
const markdownContent: string = currentRecordList.value.map((record: any) =>
|
||||||
|
`# ${record.problem_text}\n\n${record.answer_text}\n\n`
|
||||||
|
).join('\n')
|
||||||
|
const htmlContent: any = marked(markdownContent)
|
||||||
|
|
||||||
|
const blob: Blob = new Blob([htmlContent], { type: 'text/html;charset=utf-8' })
|
||||||
|
saveAs(blob, suggestedName)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
user.changeUserType(2)
|
user.changeUserType(2)
|
||||||
getAccessToken(accessToken)
|
getAccessToken(accessToken)
|
||||||
@ -239,6 +284,7 @@ onMounted(() => {
|
|||||||
.chat-pc {
|
.chat-pc {
|
||||||
background-color: var(--app-layout-bg-color);
|
background-color: var(--app-layout-bg-color);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
&__header {
|
&__header {
|
||||||
background: var(--app-header-bg-color);
|
background: var(--app-header-bg-color);
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -251,25 +297,31 @@ onMounted(() => {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border-bottom: 1px solid var(--el-border-color);
|
border-bottom: 1px solid var(--el-border-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
&__left {
|
&__left {
|
||||||
padding-top: calc(var(--app-header-height) - 8px);
|
padding-top: calc(var(--app-header-height) - 8px);
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
width: 280px;
|
width: 280px;
|
||||||
|
|
||||||
.add-button {
|
.add-button {
|
||||||
border: 1px solid var(--el-color-primary);
|
border: 1px solid var(--el-color-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.left-height {
|
.left-height {
|
||||||
height: calc(100vh - var(--app-header-height) - 135px);
|
height: calc(100vh - var(--app-header-height) - 135px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__right {
|
&__right {
|
||||||
width: calc(100% - 280px);
|
width: calc(100% - 280px);
|
||||||
padding-top: calc(var(--app-header-height));
|
padding-top: calc(var(--app-header-height));
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
.right-header {
|
.right-header {
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-height {
|
.right-height {
|
||||||
height: calc(100vh - var(--app-header-height) * 2 - 24px);
|
height: calc(100vh - var(--app-header-height) * 2 - 24px);
|
||||||
}
|
}
|
||||||
@ -279,6 +331,7 @@ onMounted(() => {
|
|||||||
position: relative;
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--el-color-info);
|
color: var(--el-color-info);
|
||||||
|
|
||||||
::before {
|
::before {
|
||||||
content: '';
|
content: '';
|
||||||
width: 17%;
|
width: 17%;
|
||||||
@ -288,6 +341,7 @@ onMounted(() => {
|
|||||||
left: 16px;
|
left: 16px;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
::after {
|
::after {
|
||||||
content: '';
|
content: '';
|
||||||
width: 17%;
|
width: 17%;
|
||||||
@ -298,6 +352,7 @@ onMounted(() => {
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-width {
|
.chat-width {
|
||||||
max-width: var(--app-chat-width, 860px);
|
max-width: var(--app-chat-width, 860px);
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user