feat: upload, edit & delete file, folder
This commit is contained in:
parent
046b915fc3
commit
9e889ccaa1
6 changed files with 583 additions and 227 deletions
|
|
@ -244,8 +244,8 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
|
|||
metadata: {
|
||||
title: string
|
||||
description: string
|
||||
keyword: string[]
|
||||
category: string[]
|
||||
keyword: string
|
||||
category: string
|
||||
}
|
||||
) {
|
||||
loader.show()
|
||||
|
|
@ -261,35 +261,102 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
|
|||
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
|
||||
requestPath += '/file'
|
||||
|
||||
const formData = new FormData()
|
||||
const res = await axiosClient.post<EhrFile & { upload: string }>(
|
||||
`${apiEndpoint}${requestPath}`,
|
||||
{
|
||||
file: file.name,
|
||||
...metadata,
|
||||
}
|
||||
)
|
||||
|
||||
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(','))
|
||||
if (res && res.data.upload) {
|
||||
await fetch(res.data.upload, {
|
||||
method: 'PUT',
|
||||
body: file,
|
||||
})
|
||||
|
||||
await axiosClient.post(`${apiEndpoint}${requestPath}`, formData)
|
||||
loader.hide()
|
||||
}
|
||||
|
||||
if (currentDept.value === 0) await getCabinet()
|
||||
else await getFolder(currentPath.value)
|
||||
if (currentDept.value === 0) {
|
||||
await getCabinet()
|
||||
} else await getFolder(currentPath.value)
|
||||
|
||||
await getFile(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
function checkFile(nameFile: string) {
|
||||
const fileExists = currentFile.value.some((element) => {
|
||||
if (element.fileName === nameFile) {
|
||||
console.log(element.fileName + '===' + nameFile)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
async function updateFile(
|
||||
pathname: string,
|
||||
metadata: {
|
||||
title: string
|
||||
description: string
|
||||
keyword: string
|
||||
category: string
|
||||
},
|
||||
file?: File
|
||||
) {
|
||||
loader.show()
|
||||
|
||||
if (fileExists) {
|
||||
return false
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
if (pathArray.length < 4) return loader.hide()
|
||||
|
||||
let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 4) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 5) requestPath += `/subfolder/${pathArray[3]}`
|
||||
requestPath += `/file/${pathArray.at(-1)}`
|
||||
|
||||
const res = await axiosClient.patch<{ upload: string }>(
|
||||
`${apiEndpoint}${requestPath}`,
|
||||
{ file: file?.name, ...metadata }
|
||||
)
|
||||
|
||||
if (res && res.data.upload) {
|
||||
await fetch(res.data.upload, {
|
||||
method: 'PUT',
|
||||
body: file,
|
||||
})
|
||||
|
||||
loader.hide()
|
||||
}
|
||||
return true
|
||||
|
||||
if (currentDept.value === 0) {
|
||||
await getCabinet()
|
||||
} else await getFolder(currentPath.value)
|
||||
|
||||
await getFile(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function deleteFile(pathname: string) {
|
||||
loader.show()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
if (pathArray.length < 4) return loader.hide()
|
||||
|
||||
let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 4) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 5) requestPath += `/subfolder/${pathArray[3]}`
|
||||
requestPath += `/file/${pathArray.at(-1)}`
|
||||
|
||||
console.log(requestPath, pathArray)
|
||||
await axiosClient.delete(`${apiEndpoint}${requestPath}`)
|
||||
|
||||
if (currentDept.value === 0) {
|
||||
await getCabinet()
|
||||
} else await getFolder(currentPath.value)
|
||||
|
||||
await getFile(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
function checkFile(fileName: string) {
|
||||
return currentFile.value.some((element) => element.fileName === fileName)
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -303,6 +370,8 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
|
|||
getCabinet,
|
||||
getFolder,
|
||||
uploadFile,
|
||||
updateFile,
|
||||
deleteFile,
|
||||
gotoParent,
|
||||
createFolder,
|
||||
deleteFolder,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue