ีupdate: ระบบอัปโหลด ถ้าชื่อไฟล์ซ้ำที่มาจากระบบอื่นจะไม่สามารถ อัปโหลดได้
This commit is contained in:
parent
dbab045c49
commit
3bbacf78d6
3 changed files with 64 additions and 14 deletions
|
|
@ -10,6 +10,7 @@ const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
open: boolean
|
open: boolean
|
||||||
error: {
|
error: {
|
||||||
|
fileExistMetadata?: boolean
|
||||||
fileExist?: boolean
|
fileExist?: boolean
|
||||||
fileName2Long?: boolean
|
fileName2Long?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -187,15 +188,20 @@ const file = ref<File | undefined>()
|
||||||
? undefined
|
? undefined
|
||||||
: 'เลือกไฟล์'
|
: 'เลือกไฟล์'
|
||||||
"
|
"
|
||||||
:error="!!error.fileExist || !!error.fileName2Long"
|
:error="
|
||||||
:error-message="
|
!!error.fileExistMetadata ||
|
||||||
error.fileExist
|
!!error.fileExist ||
|
||||||
? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ'
|
!!error.fileName2Long
|
||||||
: error.fileName2Long
|
"
|
||||||
? 'ไม่สามารถเพิ่มไฟล์ที่ชื่อยาวเกิน 85 ตัวอักษรได้'
|
:error-message="
|
||||||
: ''
|
error.fileExistMetadata
|
||||||
|
? 'พบไฟล์ชื่อซ้ำในระบบอื่น'
|
||||||
|
: error.fileExist
|
||||||
|
? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ'
|
||||||
|
: error.fileName2Long
|
||||||
|
? 'ไม่สามารถเพิ่มไฟล์ที่ชื่อยาวเกิน 85 ตัวอักษรได้'
|
||||||
|
: ''
|
||||||
"
|
"
|
||||||
:disable="disableFields?.includes('file')"
|
|
||||||
id="inputFile"
|
id="inputFile"
|
||||||
:rules="[
|
:rules="[
|
||||||
(v) => v !== undefined || mode === 'edit' || 'โปรดอัปโหลดไฟล์',
|
(v) => v !== undefined || mode === 'edit' || 'โปรดอัปโหลดไฟล์',
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,13 @@ const fileFormData = ref<{
|
||||||
metadata?: Record<string, unknown>
|
metadata?: Record<string, unknown>
|
||||||
}>({})
|
}>({})
|
||||||
const fileFormType = ref<'edit' | 'create'>('create')
|
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 fileExistNotification = ref<boolean>(false)
|
||||||
|
const errorState = ref<'fileExist' | 'fileExistMetadata'>('fileExist')
|
||||||
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
|
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
|
||||||
const fileNameLabel = ref<string>()
|
const fileNameLabel = ref<string>()
|
||||||
|
|
||||||
|
|
@ -65,6 +70,18 @@ defineExpose({
|
||||||
|
|
||||||
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
|
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) {
|
function checkFileExist(name: string, except?: string) {
|
||||||
return Boolean(
|
return Boolean(
|
||||||
file.value[currentInfo.value.path].find(
|
file.value[currentInfo.value.path].find(
|
||||||
|
|
@ -91,6 +108,16 @@ async function submitFileForm(
|
||||||
) {
|
) {
|
||||||
currentParam.value = value
|
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 (
|
if (
|
||||||
value.file &&
|
value.file &&
|
||||||
file.value[currentInfo.value.path].find(
|
file.value[currentInfo.value.path].find(
|
||||||
|
|
@ -99,6 +126,7 @@ async function submitFileForm(
|
||||||
!force
|
!force
|
||||||
) {
|
) {
|
||||||
fileExistNotification.value = true
|
fileExistNotification.value = true
|
||||||
|
errorState.value = 'fileExist'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,6 +178,7 @@ async function submitFileForm(
|
||||||
@reset="() => (fileFormError = {})"
|
@reset="() => (fileFormError = {})"
|
||||||
@filechange="
|
@filechange="
|
||||||
(name: string) => {
|
(name: string) => {
|
||||||
|
fileFormError.fileExistMetadata = checkFileExistMetadata(name)
|
||||||
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
|
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
|
||||||
(fileFormError.fileName2Long = checkFileName2Long(
|
(fileFormError.fileName2Long = checkFileName2Long(
|
||||||
name,
|
name,
|
||||||
|
|
@ -161,6 +190,7 @@ async function submitFileForm(
|
||||||
/>
|
/>
|
||||||
<upload-exist-dialog
|
<upload-exist-dialog
|
||||||
v-model:notification="fileExistNotification"
|
v-model:notification="fileExistNotification"
|
||||||
|
v-model:errorState="errorState"
|
||||||
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
||||||
@cancel="() => (currentParam = undefined)"
|
@cancel="() => (currentParam = undefined)"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
defineProps<{
|
defineProps<{
|
||||||
notification: boolean
|
notification: boolean
|
||||||
|
errorState: 'fileExist' | 'fileExistMetadata'
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineEmits(['update:notification', 'confirm', 'cancel'])
|
defineEmits(['update:notification', 'confirm', 'cancel'])
|
||||||
|
|
@ -22,11 +23,19 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h6 class="q-my-none">ยืนยันการเพิ่มข้อมูล</h6>
|
<h6 class="q-my-none">
|
||||||
|
{{
|
||||||
|
errorState === 'fileExistMetadata'
|
||||||
|
? 'พบไฟล์ชื่อช้ำในระบบอื่น'
|
||||||
|
: 'ยืนยันการเพิ่มข้อมูล'
|
||||||
|
}}
|
||||||
|
</h6>
|
||||||
<p class="q-my-none">
|
<p class="q-my-none">
|
||||||
พบไฟล์ชื่อซ้ำในระบบ หากดำเนินการต่อ
|
{{
|
||||||
ไฟล์ที่มีอยู่จะถูกแทนที่ด้วยไฟล์ใหม่
|
errorState === 'fileExistMetadata'
|
||||||
ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่
|
? 'พบไฟล์ชื่อช้ำในระบบอื่น จะไม่สามารถอัปโหลดไฟล์นี้ได้'
|
||||||
|
: 'ไฟล์ที่มีอยู่จะถูกแทนที่ด้วยไฟล์ใหม่ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่'
|
||||||
|
}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -44,7 +53,12 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
|
||||||
label="ดำเนินการต่อ"
|
label="ดำเนินการต่อ"
|
||||||
v-close-popup
|
v-close-popup
|
||||||
color="warning"
|
color="warning"
|
||||||
@click="() => $emit('confirm')"
|
@click="
|
||||||
|
() =>
|
||||||
|
errorState === 'fileExistMetadata'
|
||||||
|
? $emit('cancel')
|
||||||
|
: $emit('confirm')
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue