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

@ -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"
/>