Skip to content

Commit

Permalink
修改下载图片名称 (IMaker-时间)
Browse files Browse the repository at this point in the history
  • Loading branch information
slince-zero committed May 14, 2024
1 parent 69dcc39 commit e46f436
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/context/imageDownload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,23 @@ export const ImageDownloadProvider = ({
return
}

function generateImageName(
prefix: string,
type: 'JPG' | 'PNG' | 'SVG'
) {
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0')
const hours = String(now.getHours()).padStart(2, '0')
const minutes = String(now.getMinutes()).padStart(2, '0')
const seconds = String(now.getSeconds()).padStart(2, '0')
return `${prefix}-${year}${month}${day}-${hours}${minutes}${seconds}.${type.toLowerCase()}`
}

const imageName = generateImageName('IMAKER', type)
const link = document.createElement('a')
link.download = `image.${type.toLowerCase()}`
link.download = imageName
link.href = dataUrl
link.click()
} catch (err) {
Expand Down

0 comments on commit e46f436

Please sign in to comment.