Skip to content

Commit

Permalink
feat: export markdown, close #72 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangelckc committed Mar 22, 2023
1 parent 6d01959 commit 4c718fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/Session/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MarkdownItHighlight from 'markdown-it-highlightjs'
import { IconImage } from '@arco-design/web-vue/es/icon'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import { copyText, copyCode, saveImage } from '@/utils'
import { copyText, copyCode, saveImage, saveMarkdown } from '@/utils'
import { useSettingsStore, useSessionStore, useRoleStore } from '@/stores'
dayjs.extend(utc)
Expand Down Expand Up @@ -86,7 +86,7 @@ onUpdated(() => {
<div
class="markdown"
:id="`markdown-${item.id}`"
@click="copyText($event, { content: item.message.content })"
@click="saveMarkdown(item.message.content)"
></div>

<IconImage @click="saveImage(`session-data-${item.id}`)" />
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './tauri'
export * from './keyMap'
export * from './saveImage'
export * from './copy'
export * from './saveMarkdown'
15 changes: 15 additions & 0 deletions src/utils/saveMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useSessionStore } from '@/stores'
import { Message } from '@arco-design/web-vue'
import { writeTextFile, BaseDirectory } from '@tauri-apps/api/fs'

export const saveMarkdown = async (content: string) => {
try {
const { currentSession } = useSessionStore()
await writeTextFile(`${currentSession?.title}-${Date.now()}.md`, content, {
dir: BaseDirectory.Download
})
Message.success('Markdown导出成功')
} catch (error) {
Message.error('Markdown导出失败,请重试!')
}
}

0 comments on commit 4c718fa

Please sign in to comment.