fix: download in subfolder
This commit is contained in:
parent
0d7944e9cf
commit
1a3c179f20
1 changed files with 31 additions and 21 deletions
|
|
@ -11,27 +11,37 @@ import FileIcon from '@/components/FileIcon.vue'
|
|||
const { isFilePreview, fileInfo } = storeToRefs(useFileInfoStore())
|
||||
const { getType, getFormatDate, getSize } = useFileInfoStore()
|
||||
|
||||
async function downloadSubmit(path: any) {
|
||||
const [cabinet, drawer, folder, file] = path.split('/')
|
||||
const formatPath = `/cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/file/${file}`
|
||||
const res = await axiosClient.get<EhrFile & { download: string }>(
|
||||
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
||||
)
|
||||
await axios
|
||||
.get(res.data.download, {
|
||||
method: 'GET',
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: res.data.fileType,
|
||||
},
|
||||
})
|
||||
.then((r) => {
|
||||
const a = document.createElement('a')
|
||||
a.href = window.URL.createObjectURL(r.data)
|
||||
a.download = res.data.fileName
|
||||
a.click()
|
||||
})
|
||||
async function downloadSubmit(path: string | undefined) {
|
||||
if (path) {
|
||||
let formatPath: string
|
||||
|
||||
if (path.split('/').length - 1 === 3) {
|
||||
const [cabinet, drawer, folder, file] = path.split('/')
|
||||
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/file/${file}`
|
||||
} else {
|
||||
const [cabinet, drawer, folder, subfolder, file] = path.split('/')
|
||||
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/subfolder/${subfolder}/file/${file}`
|
||||
}
|
||||
|
||||
const res = await axiosClient.get<EhrFile & { download: string }>(
|
||||
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
||||
)
|
||||
await axios
|
||||
.get(res.data.download, {
|
||||
method: 'GET',
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: res.data.fileType,
|
||||
},
|
||||
})
|
||||
.then((r) => {
|
||||
const a = document.createElement('a')
|
||||
a.href = window.URL.createObjectURL(r.data)
|
||||
a.download = res.data.fileName
|
||||
a.click()
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue