画布图片预览

This commit is contained in:
lzp
2026-03-06 10:21:05 +08:00
parent 68d3a90940
commit a3938662c9
7 changed files with 170 additions and 107 deletions

View File

@@ -2,4 +2,17 @@ export const createId = (before: string = 'node') => {
const time = Date.now().toString(36)
const random = Math.random().toString(36).substring(2, 20)
return `${before}_${time}${random}`
}
/** 下载图片 */
export const downloadImage = (url: string, name: string) => {
fetch(url)
.then((res) => res.blob())
.then((blob) => {
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.target = '_blank'
a.download = name || 'image.png'
a.click()
})
}