mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-10-18 17:52:25 +00:00
perf: html2canvas => html-to-image
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -2,7 +2,7 @@
|
|||||||
"prettier.enable": false,
|
"prettier.enable": false,
|
||||||
"editor.formatOnSave": false,
|
"editor.formatOnSave": false,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
"eslint.validate": [
|
"eslint.validate": [
|
||||||
"javascript",
|
"javascript",
|
||||||
|
19631
package-lock.json
generated
19631
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,7 @@
|
|||||||
"@traptitech/markdown-it-katex": "^3.6.0",
|
"@traptitech/markdown-it-katex": "^3.6.0",
|
||||||
"@vueuse/core": "^9.13.0",
|
"@vueuse/core": "^9.13.0",
|
||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
"html2canvas": "^1.4.1",
|
"html-to-image": "^1.11.11",
|
||||||
"katex": "^0.16.4",
|
"katex": "^0.16.4",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"naive-ui": "^2.34.3",
|
"naive-ui": "^2.34.3",
|
||||||
|
8612
pnpm-lock.yaml
generated
8612
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { NAutoComplete, NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
import { NAutoComplete, NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
||||||
import html2canvas from 'html2canvas'
|
import { toPng } from 'html-to-image'
|
||||||
import { Message } from './components'
|
import { Message } from './components'
|
||||||
import { useScroll } from './hooks/useScroll'
|
import { useScroll } from './hooks/useScroll'
|
||||||
import { useChat } from './hooks/useChat'
|
import { useChat } from './hooks/useChat'
|
||||||
@@ -327,17 +327,13 @@ function handleExport() {
|
|||||||
try {
|
try {
|
||||||
d.loading = true
|
d.loading = true
|
||||||
const ele = document.getElementById('image-wrapper')
|
const ele = document.getElementById('image-wrapper')
|
||||||
const canvas = await html2canvas(ele as HTMLDivElement, {
|
const imgUrl = await toPng(ele as HTMLDivElement)
|
||||||
useCORS: true,
|
|
||||||
})
|
|
||||||
const imgUrl = canvas.toDataURL('image/png')
|
|
||||||
const tempLink = document.createElement('a')
|
const tempLink = document.createElement('a')
|
||||||
tempLink.style.display = 'none'
|
tempLink.style.display = 'none'
|
||||||
tempLink.href = imgUrl
|
tempLink.href = imgUrl
|
||||||
tempLink.setAttribute('download', 'chat-shot.png')
|
tempLink.setAttribute('download', 'chat-shot.png')
|
||||||
if (typeof tempLink.download === 'undefined')
|
if (typeof tempLink.download === 'undefined')
|
||||||
tempLink.setAttribute('target', '_blank')
|
tempLink.setAttribute('target', '_blank')
|
||||||
|
|
||||||
document.body.appendChild(tempLink)
|
document.body.appendChild(tempLink)
|
||||||
tempLink.click()
|
tempLink.click()
|
||||||
document.body.removeChild(tempLink)
|
document.body.removeChild(tempLink)
|
||||||
@@ -474,10 +470,10 @@ onUnmounted(() => {
|
|||||||
<main class="flex-1 overflow-hidden">
|
<main class="flex-1 overflow-hidden">
|
||||||
<div id="scrollRef" ref="scrollRef" class="h-full overflow-hidden overflow-y-auto">
|
<div id="scrollRef" ref="scrollRef" class="h-full overflow-hidden overflow-y-auto">
|
||||||
<div
|
<div
|
||||||
id="image-wrapper"
|
|
||||||
class="w-full max-w-screen-xl m-auto dark:bg-[#101014]"
|
class="w-full max-w-screen-xl m-auto dark:bg-[#101014]"
|
||||||
:class="[isMobile ? 'p-2' : 'p-4']"
|
:class="[isMobile ? 'p-2' : 'p-4']"
|
||||||
>
|
>
|
||||||
|
<div id="image-wrapper" class="relative">
|
||||||
<template v-if="!dataSources.length">
|
<template v-if="!dataSources.length">
|
||||||
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
||||||
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
||||||
@@ -509,6 +505,7 @@ onUnmounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<footer :class="footerClass">
|
<footer :class="footerClass">
|
||||||
<div class="w-full max-w-screen-xl m-auto">
|
<div class="w-full max-w-screen-xl m-auto">
|
||||||
|
Reference in New Issue
Block a user