mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-07-15 19:35:07 +08:00
[代码优化]AI: 思维导图
This commit is contained in:
@ -34,16 +34,31 @@ const download = {
|
||||
download0(data, fileName, 'text/markdown')
|
||||
},
|
||||
// 下载图片(允许跨域)
|
||||
image: (url: string) => {
|
||||
image: ({
|
||||
url,
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
drawWithImageSize = true
|
||||
}: {
|
||||
url: string
|
||||
canvasWidth?: number // 指定画布宽度
|
||||
canvasHeight?: number // 指定画布高度
|
||||
drawWithImageSize?: boolean // 将图片绘制在画布上时带上图片的宽高值, 默认是要带上的
|
||||
}) => {
|
||||
const image = new Image()
|
||||
image.setAttribute('crossOrigin', 'anonymous')
|
||||
// image.setAttribute('crossOrigin', 'anonymous')
|
||||
image.src = url
|
||||
image.onload = () => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = image.width
|
||||
canvas.height = image.height
|
||||
const ctx = canvas.getContext('2d') as CanvasDrawImage
|
||||
ctx.drawImage(image, 0, 0, image.width, image.height)
|
||||
canvas.width = canvasWidth || image.width
|
||||
canvas.height = canvasHeight || image.height
|
||||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D
|
||||
ctx?.clearRect(0, 0, canvas.width, canvas.height)
|
||||
if (drawWithImageSize) {
|
||||
ctx.drawImage(image, 0, 0, image.width, image.height)
|
||||
} else {
|
||||
ctx.drawImage(image, 0, 0)
|
||||
}
|
||||
const url = canvas.toDataURL('image/png')
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
|
Reference in New Issue
Block a user