
获得徽章 17
- 通过url下载文件方法export const downloadFileByUrl = async (url: string, isCurrentSite: boolean, onDownloadProgress?: (p?: string | number) => void, fileName?: string) => {
let _fileUrl = url
if (isCurrentSite) {
const temp = new URL(url)
_fileUrl = temp.pathname + temp.search
}
const fileBlob = await axiosInstance.get(_fileUrl, {
responseType: 'blob',
returnType: 'axios',
onDownloadProgress(event) {
onDownloadProgress?.(event.total ? event.loaded / event.total * 100 : 0)
},
})
downloadFileByBlob(fileBlob.data, fileName || fileBlob.headers.filename || fileBlob.headers?.['content-disposition']?.match?.(/filename=(.*)/)?.[1] || '下载')
}展开等人赞过评论4 - 推荐一个好用的svg Icon组件unplugin-icons/webpack 配好之后可以随心所欲更改svg的颜色Icons({
scale: 1,
jsx: 'react',
compiler: 'jsx',
customCollections: {
svg: FileSystemIconLoader('./src/assets/icons/svg'),
colour: FileSystemIconLoader('./src/assets/icons/colour')
},
transform(svg, collection) {
const out = svg
.replace(/(<svg[^>]+)(width=['"][^'"]+['"]+)/g, '$1')
.replace(/(<svg[^>]+)(height=['"][^'"]+['"]+)/g, '$1')
.replace(/<svg/, '<svg style="vertical-align: middle;"')
return collection === 'svg'
? out
.replace(/(?<=<path (?!class="not-main")[^>]*)fill="(?!none)[^"]*"/g, 'fill="currentColor"')
.replace(/(?<=<rect (?!class="not-main")[^>]*)(?<=(stroke|fill)=)"(?!none)[^"]*"/g, '"currentColor"')
: out
}
}),展开评论点赞