refactor: refaceFile

This commit is contained in:
somnetsak123 2023-12-01 16:47:19 +07:00
parent 774b8fb2fd
commit 963c08160e
2 changed files with 39 additions and 9 deletions

View file

@ -15,12 +15,13 @@ const props = withDefaults(
defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(), defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(),
{ {
action: false, action: false,
}, }
) )
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
const { getFileInfo, getFileNameFormat } = useFileInfoStore() const { getFileInfo, getFileNameFormat } = useFileInfoStore()
const { currentFolder, currentFile, currentDept, currentPath } = const { currentFolder, currentFile, currentDept, currentPath } = storeToRefs(
storeToRefs(useTreeDataStore()) useTreeDataStore()
)
const { const {
createFolder, createFolder,
editFolder, editFolder,
@ -30,14 +31,15 @@ const {
updateFile, updateFile,
deleteFile, deleteFile,
checkFile, checkFile,
refaceFile,
} = useTreeDataStore() } = useTreeDataStore()
const currentIcon = computed(() => const currentIcon = computed(() =>
currentDept.value === 0 currentDept.value === 0
? 'mdi-file-cabinet' ? 'mdi-file-cabinet'
: currentDept.value === 1 : currentDept.value === 1
? 'inbox' ? 'inbox'
: 'o_folder_open', : 'o_folder_open'
) )
const dialogDeleteState = ref<boolean>(false) const dialogDeleteState = ref<boolean>(false)
@ -112,7 +114,7 @@ function triggerFileEdit(
keyword: string[] keyword: string[]
category: string[] category: string[]
}, },
pathname: string, pathname: string
) { ) {
fileFormState.value = true fileFormState.value = true
fileFormType.value = 'edit' fileFormType.value = 'edit'
@ -136,7 +138,7 @@ async function submitFileForm(
keyword: string[] keyword: string[]
category: string[] category: string[]
}, },
force = false, force = false
) { ) {
currentParam.value = value currentParam.value = value
@ -152,6 +154,13 @@ async function submitFileForm(
keyword: value.keyword, keyword: value.keyword,
category: value.category, category: value.category,
}) })
setTimeout(() => {
refaceFile(currentPath.value)
}, 3000)
setTimeout(() => {
refaceFile(currentPath.value)
}, 10000)
} else { } else {
await updateFile( await updateFile(
fileFormPath.value, fileFormPath.value,
@ -161,7 +170,7 @@ async function submitFileForm(
keyword: value.keyword, keyword: value.keyword,
category: value.category, category: value.category,
}, },
value.file, value.file
) )
} }
fileFormData.value = {} fileFormData.value = {}
@ -313,7 +322,7 @@ async function submitFileForm(
keyword: value.keyword, keyword: value.keyword,
category: value.category, category: value.category,
}, },
value.pathname, value.pathname
) )
" "
@delete="() => triggerFileDelete(value.pathname)" @delete="() => triggerFileDelete(value.pathname)"

View file

@ -363,6 +363,26 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
return fileName.length >= 85 return fileName.length >= 85
} }
async function refaceFile(pathname: string) {
const pathArray: string[] = pathname.split('/').filter(Boolean)
if (pathArray.length <= 2) {
currentFile.value = []
return loader.hide()
}
let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
if (pathArray.length >= 3) requestPath += `/folder/${pathArray[2]}`
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
requestPath += '/file'
const res = await axiosClient.get<EhrFile[]>(`${apiEndpoint}${requestPath}`)
currentFile.value = res.data
listDataFile.value = currentFile.value
}
return { return {
data, data,
currentFolder, currentFolder,
@ -382,5 +402,6 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
editFolder, editFolder,
checkFile, checkFile,
checkFileName, checkFileName,
refaceFile,
} }
}) })