diff --git a/src/api/download/index.ts b/src/api/download/index.ts new file mode 100644 index 0000000..d9ce1e4 --- /dev/null +++ b/src/api/download/index.ts @@ -0,0 +1,23 @@ +import axios from "axios"; + +const downloadPhoto = (imgSrc:any) => { + axios({ + url: imgSrc, + method: 'get', + headers: { 'Content-Type': 'application/json' }, + responseType: 'blob', + }).then(res => { + const url = window.URL.createObjectURL(res.data); + const a = document.createElement('a'); + a.href = url; + a.download = '下载图片.jpg'; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }).catch(error => { + console.error('Download error:', error); + }); +}; + +export { downloadPhoto }; \ No newline at end of file