ีupdate: ระบบอัปโหลด ถ้าชื่อไฟล์ซ้ำที่มาจากระบบอื่นจะไม่สามารถ อัปโหลดได้

This commit is contained in:
net 2024-01-12 13:44:22 +07:00
parent dbab045c49
commit 3bbacf78d6
3 changed files with 64 additions and 14 deletions

View file

@ -10,6 +10,7 @@ const props = withDefaults(
defineProps<{
open: boolean
error: {
fileExistMetadata?: boolean
fileExist?: boolean
fileName2Long?: boolean
}
@ -187,15 +188,20 @@ const file = ref<File | undefined>()
? undefined
: 'เลือกไฟล์'
"
:error="!!error.fileExist || !!error.fileName2Long"
:error-message="
error.fileExist
? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ'
: error.fileName2Long
? 'ไม่สามารถเพิ่มไฟล์ที่ชื่อยาวเกิน 85 ตัวอักษรได้'
: ''
:error="
!!error.fileExistMetadata ||
!!error.fileExist ||
!!error.fileName2Long
"
:error-message="
error.fileExistMetadata
? 'พบไฟล์ชื่อซ้ำในระบบอื่น'
: error.fileExist
? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ'
: error.fileName2Long
? 'ไม่สามารถเพิ่มไฟล์ที่ชื่อยาวเกิน 85 ตัวอักษรได้'
: ''
"
:disable="disableFields?.includes('file')"
id="inputFile"
:rules="[
(v) => v !== undefined || mode === 'edit' || 'โปรดอัปโหลดไฟล์',

View file

@ -21,8 +21,13 @@ const fileFormData = ref<{
metadata?: Record<string, unknown>
}>({})
const fileFormType = ref<'edit' | 'create'>('create')
const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({})
const fileFormError = ref<{
fileExistMetadata?: boolean
fileExist?: boolean
fileName2Long?: boolean
}>({})
const fileExistNotification = ref<boolean>(false)
const errorState = ref<'fileExist' | 'fileExistMetadata'>('fileExist')
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
const fileNameLabel = ref<string>()
@ -65,6 +70,18 @@ defineExpose({
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
function checkFileExistMetadata(name: string) {
const fileInfo = file.value[currentInfo.value.path].find(
(v) => v.fileName === name,
)
if (fileInfo?.metadata && Object.keys(fileInfo?.metadata).length > 0) {
return Boolean(true)
}
return Boolean(false)
}
function checkFileExist(name: string, except?: string) {
return Boolean(
file.value[currentInfo.value.path].find(
@ -91,6 +108,16 @@ async function submitFileForm(
) {
currentParam.value = value
const fileInfo = file.value[currentInfo.value.path].find(
(v) => v.fileName === value.file?.name,
)
if (fileInfo?.metadata && Object.keys(fileInfo.metadata).length > 0) {
fileExistNotification.value = true
errorState.value = 'fileExistMetadata'
return
}
if (
value.file &&
file.value[currentInfo.value.path].find(
@ -99,6 +126,7 @@ async function submitFileForm(
!force
) {
fileExistNotification.value = true
errorState.value = 'fileExist'
return
}
@ -150,6 +178,7 @@ async function submitFileForm(
@reset="() => (fileFormError = {})"
@filechange="
(name: string) => {
fileFormError.fileExistMetadata = checkFileExistMetadata(name)
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
(fileFormError.fileName2Long = checkFileName2Long(
name,
@ -161,6 +190,7 @@ async function submitFileForm(
/>
<upload-exist-dialog
v-model:notification="fileExistNotification"
v-model:errorState="errorState"
@confirm="() => currentParam && submitFileForm(currentParam, true)"
@cancel="() => (currentParam = undefined)"
/>

View file

@ -1,6 +1,7 @@
<script lang="ts" setup>
defineProps<{
notification: boolean
errorState: 'fileExist' | 'fileExistMetadata'
}>()
defineEmits(['update:notification', 'confirm', 'cancel'])
@ -22,11 +23,19 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
</div>
</div>
<div>
<h6 class="q-my-none">นยนการเพมขอม</h6>
<h6 class="q-my-none">
{{
errorState === 'fileExistMetadata'
? 'พบไฟล์ชื่อช้ำในระบบอื่น'
: 'ยืนยันการเพิ่มข้อมูล'
}}
</h6>
<p class="q-my-none">
พบไฟลอซำในระบบ หากดำเนนการต
ไฟลอยจะถกแทนทวยไฟลใหม
องการยนยนการอปโหลดไฟลหรอไม
{{
errorState === 'fileExistMetadata'
? 'พบไฟล์ชื่อช้ำในระบบอื่น จะไม่สามารถอัปโหลดไฟล์นี้ได้'
: 'ไฟล์ที่มีอยู่จะถูกแทนที่ด้วยไฟล์ใหม่ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่'
}}
</p>
</div>
</div>
@ -44,7 +53,12 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
label="ดำเนินการต่อ"
v-close-popup
color="warning"
@click="() => $emit('confirm')"
@click="
() =>
errorState === 'fileExistMetadata'
? $emit('cancel')
: $emit('confirm')
"
/>
</q-card-actions>
</q-card>