feat: add author field
This commit is contained in:
parent
257a112eae
commit
04f33808d5
3 changed files with 43 additions and 10 deletions
|
|
@ -19,6 +19,7 @@ const props = withDefaults(
|
|||
description?: string
|
||||
keyword?: string[]
|
||||
category?: string[]
|
||||
author?: string
|
||||
}>(),
|
||||
{
|
||||
open: false,
|
||||
|
|
@ -34,6 +35,7 @@ const emit = defineEmits([
|
|||
'update:description',
|
||||
'update:keyword',
|
||||
'update:category',
|
||||
'update:author',
|
||||
'filechange',
|
||||
'reset',
|
||||
'submit',
|
||||
|
|
@ -56,6 +58,7 @@ function reset() {
|
|||
emit('update:description', '')
|
||||
emit('update:keyword', '')
|
||||
emit('update:category', '')
|
||||
emit('update:author', '')
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +70,7 @@ function submit() {
|
|||
description: props.description ?? '',
|
||||
keyword: props.keyword,
|
||||
category: props.category,
|
||||
author: props.author,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +169,9 @@ const file = ref<File | undefined>()
|
|||
: ''
|
||||
"
|
||||
id="inputFile"
|
||||
:rules="[(v) => (v !== undefined || mode === 'edit' ) || ('โปรดอัปโหลดไฟล์')]"
|
||||
:rules="[
|
||||
(v) => v !== undefined || mode === 'edit' || 'โปรดอัปโหลดไฟล์',
|
||||
]"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="attach_file" />
|
||||
|
|
@ -181,7 +187,10 @@ const file = ref<File | undefined>()
|
|||
class="q-my-sm"
|
||||
placeholder="กรอกชื่อเรื่อง"
|
||||
:model-value="title"
|
||||
:rules="[(v) => (v != undefined && v.length > 3) || 'ชื่อต้องยาวกว่า 3 ตัวอักษร']"
|
||||
:rules="[
|
||||
(v) =>
|
||||
(v != undefined && v.length > 3) || 'ชื่อต้องยาวกว่า 3 ตัวอักษร',
|
||||
]"
|
||||
@update:model-value="(v) => $emit('update:title', v)"
|
||||
id="inputTitle"
|
||||
/>
|
||||
|
|
@ -217,7 +226,6 @@ const file = ref<File | undefined>()
|
|||
@new-value="createCategory"
|
||||
:options="filterDataCategory"
|
||||
@filter="filterCategory"
|
||||
style="width: 250px"
|
||||
@update:model-value="(v) => $emit('update:category', v)"
|
||||
data-testid="filterDataCategory"
|
||||
>
|
||||
|
|
@ -237,7 +245,6 @@ const file = ref<File | undefined>()
|
|||
multiple
|
||||
hide-dropdown-icon
|
||||
input-debounce="0"
|
||||
style="width: 250px"
|
||||
:model-value="props.keyword"
|
||||
@update:model-value="(v) => $emit('update:keyword', v)"
|
||||
@new-value="createKeyword"
|
||||
|
|
@ -247,6 +254,23 @@ const file = ref<File | undefined>()
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<section class="q-mb-md">
|
||||
<span class="text-weight-bold">เจ้าของผลงาน</span>
|
||||
<q-input
|
||||
outlined
|
||||
dense
|
||||
class="q-my-sm"
|
||||
placeholder="เจ้าของผลงาน"
|
||||
:model-value="author"
|
||||
:rules="[
|
||||
(v) =>
|
||||
(v != undefined && v.length > 3) || 'ชื่อต้องยาวกว่า 3 ตัวอักษร',
|
||||
]"
|
||||
@update:model-value="(v) => $emit('update:author', v)"
|
||||
id="inputAuthor"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section :style="{ display: 'flex', gap: '.5rem' }">
|
||||
<q-btn
|
||||
label="บันทึก"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ const fileFormData = ref<{
|
|||
description?: string
|
||||
keyword?: string[]
|
||||
category?: string[]
|
||||
author?: string
|
||||
}>({})
|
||||
const fileFormType = ref<'edit' | 'create'>('create')
|
||||
const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({})
|
||||
|
|
@ -68,7 +69,7 @@ function checkFileExist(name: string, except?: string) {
|
|||
}
|
||||
|
||||
function checkFileName2Long(name: string, except?: string) {
|
||||
return Boolean(name.length > 85)
|
||||
return name !== except && Boolean(name.length > 85)
|
||||
}
|
||||
|
||||
async function submitFileForm(
|
||||
|
|
@ -79,6 +80,7 @@ async function submitFileForm(
|
|||
description: string
|
||||
keyword: string[]
|
||||
category: string[]
|
||||
author: string
|
||||
},
|
||||
force = false,
|
||||
) {
|
||||
|
|
@ -101,6 +103,7 @@ async function submitFileForm(
|
|||
description: value.description,
|
||||
keyword: value.keyword,
|
||||
category: value.category,
|
||||
author: value.author,
|
||||
})
|
||||
} else {
|
||||
await updateFile(
|
||||
|
|
@ -110,6 +113,7 @@ async function submitFileForm(
|
|||
description: value.description,
|
||||
keyword: value.keyword,
|
||||
category: value.category,
|
||||
author: value.author,
|
||||
},
|
||||
value.file,
|
||||
)
|
||||
|
|
@ -132,11 +136,15 @@ async function submitFileForm(
|
|||
v-model:description="fileFormData.description"
|
||||
v-model:keyword="fileFormData.keyword"
|
||||
v-model:category="fileFormData.category"
|
||||
v-model:author="fileFormData.author"
|
||||
@reset="() => (fileFormError = {})"
|
||||
@filechange="
|
||||
(name: string) => {
|
||||
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
|
||||
(fileFormError.fileName2Long = checkFileName2Long(name, fileNameLabel))
|
||||
(fileFormError.fileName2Long = checkFileName2Long(
|
||||
name,
|
||||
fileNameLabel,
|
||||
))
|
||||
}
|
||||
"
|
||||
@submit="submitFileForm"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue