feat: file name as label when edit

This commit is contained in:
Methapon2001 2023-12-12 17:32:16 +07:00
parent e20d5a4c50
commit 7e5cb46e97
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
4 changed files with 20 additions and 4 deletions

View file

@ -14,6 +14,7 @@ const props = withDefaults(
fileName2Long?: boolean
}
mode: 'create' | 'edit'
fileNameLabel?: string
title?: string
description?: string
keyword?: string[]
@ -146,7 +147,13 @@ const file = ref<File | undefined>()
outlined
v-model="file"
@update:model-value="(v) => $emit('filechange', v.name)"
:label="file?.name ? undefined : 'เลือกไฟล์'"
:label="
mode === 'edit' && fileNameLabel && !file?.name
? fileNameLabel
: file?.name
? undefined
: 'เลือกไฟล์'
"
:error="!!error.fileExist || !!error.fileName2Long"
:error-message="
error.fileExist

View file

@ -22,6 +22,7 @@ const fileFormType = ref<'edit' | 'create'>('create')
const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({})
const fileExistNotification = ref<boolean>(false)
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
const fileNameLabel = ref<string>()
function triggerFileCreate() {
fileFormType.value = 'create'
@ -37,6 +38,7 @@ function triggerFileEdit(
category: string[]
},
pathname: string,
file?: string,
) {
fileFormState.value = true
fileFormType.value = 'edit'
@ -47,6 +49,7 @@ function triggerFileEdit(
keyword: value.keyword,
category: value.category,
}
fileNameLabel.value = file
}
defineExpose({
@ -56,9 +59,11 @@ defineExpose({
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
function checkFileExist(name: string) {
function checkFileExist(name: string, except?: string) {
return Boolean(
file.value[currentInfo.value.path].find((v) => v.fileName === name),
file.value[currentInfo.value.path].find(
(v) => v.fileName === name && v.fileName !== except,
),
)
}
@ -117,6 +122,7 @@ async function submitFileForm(
ref="fileFormComponent"
:mode="fileFormType"
:error="fileFormError"
:fileNameLabel="fileNameLabel"
v-model:open="fileFormState"
v-model:title="fileFormData.title"
v-model:description="fileFormData.description"
@ -124,7 +130,8 @@ async function submitFileForm(
v-model:category="fileFormData.category"
@reset="() => (fileFormError = {})"
@filechange="
(name: string) => (fileFormError.fileExist = checkFileExist(name))
(name: string) =>
(fileFormError.fileExist = checkFileExist(name, fileNameLabel))
"
@submit="submitFileForm"
/>

View file

@ -248,6 +248,7 @@ function triggerFileDelete(pathname: string) {
category: value.category,
},
value.pathname,
value.fileName,
)
"
@delete="() => triggerFileDelete(value.pathname)"

View file

@ -312,6 +312,7 @@ const onRowClick = ((_, row) => {
fileFormComponent?.triggerFileEdit(
data.row,
data.row.pathname,
data.row.fileName,
)
"
id="listViewFileEdit"