feat(file):add validateFileSize
This commit is contained in:
parent
c69c4c1fa8
commit
44487139ea
2 changed files with 28 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ import { checkPermission } from "@/utils/permissions";
|
|||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { usePlacementDataStore } from "@/modules/05_placement/store";
|
||||
import { useMenuDataStore } from "@/stores/menuList";
|
||||
import { validateFileSize } from "@/utils/function";
|
||||
import avatar from "@/assets/avatar_user.jpg";
|
||||
|
||||
import type { PartialTableName } from "@/modules/05_placement/interface/request/placement";
|
||||
|
|
@ -1056,7 +1057,8 @@ onMounted(async () => {
|
|||
checkPermission($route)?.attrIsUpdate &&
|
||||
props.row.isDraft &&
|
||||
props.row.statusId === 'PREPARE-CONTAIN' &&
|
||||
(DataStore.isOfficer || checkPermission($route)?.attrOwnership == 'OWNER')
|
||||
(DataStore.isOfficer ||
|
||||
checkPermission($route)?.attrOwnership == 'OWNER')
|
||||
"
|
||||
clickable
|
||||
v-close-popup
|
||||
|
|
@ -1543,7 +1545,10 @@ onMounted(async () => {
|
|||
:label="`${'เลือกไฟล์เอกสารหลักฐาน'}`"
|
||||
outlined
|
||||
use-chips
|
||||
:rules="[(val:string) => !!val || 'กรุณาเลือกไฟล์เอกสารหลักฐาน']"
|
||||
:rules="[
|
||||
(val) => !!val || 'กรุณาเลือกไฟล์เอกสารหลักฐาน',
|
||||
(val) => validateFileSize(val),
|
||||
]"
|
||||
multiple
|
||||
@update:model-value="clickEditRow"
|
||||
class="q-py-sm"
|
||||
|
|
|
|||
|
|
@ -73,3 +73,24 @@ export function getColumnLabel(col: any, isAct: boolean) {
|
|||
}
|
||||
return col.label;
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจสอบขนาดไฟล์
|
||||
* @param val ไฟล์หรืออาร์เรย์ของไฟล์ที่ต้องการตรวจสอบ
|
||||
* @param maxSizeMB ขนาดจำกัดในหน่วย MB (ค่าเริ่มต้นคือ 10MB)
|
||||
* @returns true หากไฟล์ทั้งหมดมีขนาดไม่เกินที่กำหนด, หรือข้อความแจ้งเตือนหากมีไฟล์ที่เกินขนาด
|
||||
*/
|
||||
export function validateFileSize(
|
||||
val: File | File[],
|
||||
maxSizeMB: number = 10
|
||||
): string | true {
|
||||
if (!val) return true;
|
||||
|
||||
const filesArray = Array.isArray(val) ? val : [val];
|
||||
const limit = maxSizeMB * 1024 * 1024;
|
||||
|
||||
const isAllValid = filesArray.every((file: File) => file.size <= limit);
|
||||
if (isAllValid) return true;
|
||||
|
||||
return `ขนาดไฟล์ไม่เกิน ${maxSizeMB}MB`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue