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

View file

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