refactor: upload file
This commit is contained in:
parent
b10679b53c
commit
74c5115e95
2 changed files with 71 additions and 10 deletions
|
|
@ -238,15 +238,56 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
|
|||
await getFolder(pathname.join('/') + '/')
|
||||
}
|
||||
|
||||
async function uploadFile(
|
||||
pathname: string,
|
||||
file: File,
|
||||
metadata: {
|
||||
title: string
|
||||
description: string
|
||||
keyword: string[]
|
||||
category: string[]
|
||||
}
|
||||
) {
|
||||
loader.show()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
if (pathArray.length <= 2) return
|
||||
|
||||
let requestPath = 'cabinet'
|
||||
if (pathArray.length >= 1) requestPath += `/${pathArray[0]}`
|
||||
if (pathArray.length >= 2) requestPath += `/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 3) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
|
||||
requestPath += '/file'
|
||||
|
||||
const formData = new FormData()
|
||||
|
||||
formData.append('file', file)
|
||||
formData.append('title', metadata.title)
|
||||
formData.append('description', metadata.description)
|
||||
formData.append('keyword', metadata.keyword.join(','))
|
||||
formData.append('category', metadata.category.join(','))
|
||||
|
||||
await axiosClient.post(`${apiEndpoint}${requestPath}`, formData)
|
||||
|
||||
if (currentDept.value === 0) await getCabinet()
|
||||
else await getFolder(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
currentFolder,
|
||||
currentFile,
|
||||
currentDept,
|
||||
listDataFolder,
|
||||
currentPath,
|
||||
listDataFile,
|
||||
listDataFolder,
|
||||
getCabinet,
|
||||
getFolder,
|
||||
uploadFile,
|
||||
gotoParent,
|
||||
createFolder,
|
||||
deleteFolder,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue