fix: edit file

This commit is contained in:
somnetsak123 2023-12-01 11:46:55 +07:00
parent b0afe16fbd
commit 362fdcd0bf
2 changed files with 35 additions and 23 deletions

View file

@ -55,14 +55,16 @@ const folderFormData = ref<{
}>({})
const folderFormType = ref<'edit' | 'create'>('create')
const fileFormError = ref<{ fileExist?: boolean }>({})
const fileExistNotification = ref<boolean>(false)
const fileFormState = ref<boolean>(false)
const fileFormPath = ref<string>('')
const fileFormData = ref<{
file?: File
title?: string
description?: string
keyword?: string
category?: string
keyword?: string[]
category?: string[]
}>({})
const fileFormType = ref<'edit' | 'create'>('create')
@ -116,8 +118,8 @@ function triggerFileEdit(
value: {
title: string
description: string
keyword: string
category: string
keyword: string[]
category: string[]
},
pathname: string
) {
@ -128,19 +130,31 @@ function triggerFileEdit(
title: value.title,
description: value.description,
keyword: value.keyword,
category: value.keyword,
category: value.category,
}
}
async function submitFileForm(value: {
mode: 'create' | 'edit'
file: File
title: string
description: string
keyword: string
category: string
}) {
if (value.mode === 'create') {
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
async function submitFileForm(
value: {
mode: 'create' | 'edit'
file?: File
title: string
description: string
keyword: string[]
category: string[]
},
force = false
) {
currentParam.value = value
if (value.file && checkFile(value.file.name) && !force) {
fileExistNotification.value = true
return
}
if (value.mode === 'create' && value.file) {
await uploadFile(currentPath.value, value.file, {
title: value.title,
description: value.description,
@ -161,6 +175,7 @@ async function submitFileForm(value: {
}
fileFormData.value = {}
fileFormState.value = false
currentParam.value = undefined
}
const columnsFolder: QTableProps['columns'] = [

View file

@ -40,9 +40,6 @@ export interface TreeDataFolder {
export const useTreeDataStore = defineStore('changeCabinet', () => {
const loader = useLoader()
const indexToRemove = ref<number>()
const fileNameRemove = ref<string>('')
const data = ref<TreeDataFolder[]>([])
const currentFolder = ref<TreeDataFolder[]>([])
const currentFile = ref<EhrFile[]>([])
@ -96,7 +93,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
currentPath.value = pathname
const res = await axiosClient.get<EhrFolder[]>(
`${apiEndpoint}${requestPath}`,
`${apiEndpoint}${requestPath}`
)
const list = res.data.map((v) => ({
@ -248,7 +245,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
description: string
keyword: string[]
category: string[]
},
}
) {
loader.show()
@ -268,7 +265,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
{
file: file.name,
...metadata,
},
}
)
if (res && res.data.upload) {
@ -297,7 +294,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
keyword: string[]
category: string[]
},
file?: File,
file?: File
) {
loader.show()
@ -312,7 +309,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
const res = await axiosClient.patch<{ upload: string }>(
`${apiEndpoint}${requestPath}`,
{ file: file?.name, ...metadata },
{ file: file?.name, ...metadata }
)
if (res && res.data.upload) {
@ -354,7 +351,7 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
await getFile(currentPath.value)
currentFile.value = currentFile.value.filter((v) => v.pathname !== pathname)
listDataFile.value = currentFile.value
return loader.hide()
}