@finema/core 1.4.220 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -60
- package/dist/module.d.mts +4 -24
- package/dist/module.json +4 -3
- package/dist/module.mjs +75 -213
- package/dist/runtime/components/App.vue +27 -0
- package/dist/runtime/components/App.vue.d.ts +12 -0
- package/dist/runtime/components/DevToolsWindow/index.vue +312 -0
- package/dist/runtime/components/DevToolsWindow/index.vue.d.ts +2 -0
- package/dist/runtime/components/Dialog/index.vue +77 -110
- package/dist/runtime/components/Dialog/index.vue.d.ts +10 -0
- package/dist/runtime/components/Empty.vue +33 -18
- package/dist/runtime/components/Empty.vue.d.ts +12 -0
- package/dist/runtime/components/FlexDeck/Base.vue +154 -159
- package/dist/runtime/components/FlexDeck/Base.vue.d.ts +63 -0
- package/dist/runtime/components/FlexDeck/index.vue +67 -68
- package/dist/runtime/components/FlexDeck/index.vue.d.ts +43 -0
- package/dist/runtime/components/Form/FieldWrapper.vue +35 -23
- package/dist/runtime/components/Form/FieldWrapper.vue.d.ts +16 -0
- package/dist/runtime/components/Form/Fields.vue +92 -230
- package/dist/runtime/components/Form/Fields.vue.d.ts +14 -0
- package/dist/runtime/components/Form/InputCheckbox/index.vue +53 -28
- package/dist/runtime/components/Form/InputCheckbox/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputCheckbox/types.d.ts +5 -1
- package/dist/runtime/components/Form/InputDateTime/date_time_field.types.d.ts +1 -1
- package/dist/runtime/components/Form/InputDateTime/index.vue +97 -68
- package/dist/runtime/components/Form/InputDateTime/index.vue.d.ts +4 -0
- package/dist/runtime/components/Form/InputNumber/index.vue +61 -27
- package/dist/runtime/components/Form/InputNumber/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputNumber/types.d.ts +10 -5
- package/dist/runtime/components/Form/InputSelect/index.vue +95 -55
- package/dist/runtime/components/Form/InputSelect/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputSelect/types.d.ts +14 -8
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue +108 -54
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputSelectMultiple/types.d.ts +9 -8
- package/dist/runtime/components/Form/InputText/index.vue +135 -68
- package/dist/runtime/components/Form/InputText/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputText/types.d.ts +4 -3
- package/dist/runtime/components/Form/InputTextarea/index.vue +57 -25
- package/dist/runtime/components/Form/InputTextarea/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputTextarea/types.d.ts +7 -2
- package/dist/runtime/components/Form/InputToggle/index.vue +51 -27
- package/dist/runtime/components/Form/InputToggle/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputToggle/types.d.ts +5 -1
- package/dist/runtime/components/Form/index.vue +5 -6
- package/dist/runtime/components/Form/index.vue.d.ts +12 -0
- package/dist/runtime/components/Form/types.d.ts +13 -27
- package/dist/runtime/components/Image.vue +51 -36
- package/dist/runtime/components/Image.vue.d.ts +13 -0
- package/dist/runtime/components/Loader.vue +29 -27
- package/dist/runtime/components/Loader.vue.d.ts +22 -0
- package/dist/runtime/components/{LogItem.vue → Log/LogItem.vue} +44 -41
- package/dist/runtime/components/Log/LogItem.vue.d.ts +6 -0
- package/dist/runtime/components/Log/index.vue +28 -0
- package/dist/runtime/components/Log/index.vue.d.ts +7 -0
- package/dist/runtime/components/Table/Base.vue +166 -161
- package/dist/runtime/components/Table/Base.vue.d.ts +47 -0
- package/dist/runtime/components/Table/ColumnDate.vue +14 -16
- package/dist/runtime/components/Table/ColumnDate.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnDateTime.vue +16 -18
- package/dist/runtime/components/Table/ColumnDateTime.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnImage.vue +16 -15
- package/dist/runtime/components/Table/ColumnImage.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
- package/dist/runtime/components/Table/ColumnNumber.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnText.vue +24 -29
- package/dist/runtime/components/Table/ColumnText.vue.d.ts +8 -0
- package/dist/runtime/components/Table/Simple.vue +69 -70
- package/dist/runtime/components/Table/Simple.vue.d.ts +24 -0
- package/dist/runtime/components/Table/index.vue +178 -65
- package/dist/runtime/components/Table/index.vue.d.ts +25 -0
- package/dist/runtime/components/Table/types.d.ts +14 -18
- package/dist/runtime/components/Table/{types.mjs → types.js} +1 -0
- package/dist/runtime/components/TeleportSafe.vue +42 -40
- package/dist/runtime/components/TeleportSafe.vue.d.ts +16 -0
- package/dist/runtime/composables/loaderList.d.ts +2 -2
- package/dist/runtime/composables/loaderList.js +51 -0
- package/dist/runtime/composables/loaderObject.d.ts +1 -1
- package/dist/runtime/composables/loaderObject.js +50 -0
- package/dist/runtime/composables/loaderPage.d.ts +10 -11
- package/dist/runtime/composables/loaderPage.js +243 -0
- package/dist/runtime/composables/useApp.d.ts +4 -9
- package/dist/runtime/composables/{useApp.mjs → useApp.js} +0 -12
- package/dist/runtime/composables/useConfig.d.ts +3 -3
- package/dist/runtime/composables/useConfig.js +12 -0
- package/dist/runtime/composables/useDialog.d.ts +1 -7
- package/dist/runtime/composables/useDialog.js +53 -0
- package/dist/runtime/composables/useFlexDeck.d.ts +1 -1
- package/dist/runtime/composables/{useFlexDeck.mjs → useFlexDeck.js} +5 -5
- package/dist/runtime/composables/useForm.d.ts +5 -2
- package/dist/runtime/composables/useForm.js +37 -0
- package/dist/runtime/composables/useNotification.d.ts +6 -22
- package/dist/runtime/composables/{useNotification.mjs → useNotification.js} +5 -21
- package/dist/runtime/composables/useTable.d.ts +12 -11
- package/dist/runtime/composables/{useTable.mjs → useTable.js} +3 -8
- package/dist/runtime/composables/useUpload.d.ts +2 -2
- package/dist/runtime/composables/{useUpload.mjs → useUpload.js} +1 -1
- package/dist/runtime/helpers/apiBaseHelper.d.ts +29 -0
- package/dist/runtime/helpers/apiBaseHelper.js +63 -0
- package/dist/runtime/helpers/apiListHelper.d.ts +4 -6
- package/dist/runtime/helpers/apiListHelper.js +50 -0
- package/dist/runtime/helpers/apiObjectHelper.d.ts +19 -20
- package/dist/runtime/helpers/apiObjectHelper.js +51 -0
- package/dist/runtime/helpers/apiPageHelper.d.ts +44 -44
- package/dist/runtime/helpers/apiPageHelper.js +287 -0
- package/dist/runtime/helpers/componentHelper.d.ts +11 -12
- package/dist/runtime/helpers/{componentHelper.mjs → componentHelper.js} +2 -7
- package/dist/runtime/i18n/valibot.d.ts +69 -0
- package/dist/runtime/i18n/valibot.js +72 -0
- package/dist/runtime/plugin.d.ts +1 -1
- package/dist/runtime/plugin.js +12 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/theme/button.d.ts +5 -0
- package/dist/runtime/theme/button.js +1 -0
- package/dist/runtime/theme/dialog.d.ts +31 -0
- package/dist/runtime/theme/dialog.js +21 -0
- package/dist/runtime/theme/empty.d.ts +7 -0
- package/dist/runtime/theme/empty.js +7 -0
- package/dist/runtime/theme/form.d.ts +18 -0
- package/dist/runtime/theme/form.js +16 -0
- package/dist/runtime/theme/index.d.ts +10 -0
- package/dist/runtime/theme/index.js +10 -0
- package/dist/runtime/theme/input.d.ts +8 -0
- package/dist/runtime/theme/input.js +4 -0
- package/dist/runtime/theme/inputNumber.d.ts +8 -0
- package/dist/runtime/theme/inputNumber.js +4 -0
- package/dist/runtime/theme/loader.d.ts +28 -0
- package/dist/runtime/theme/loader.js +18 -0
- package/dist/runtime/theme/selectMenu.d.ts +17 -0
- package/dist/runtime/theme/selectMenu.js +18 -0
- package/dist/runtime/theme/table.d.ts +10 -0
- package/dist/runtime/theme/table.js +10 -0
- package/dist/runtime/theme/textarea.d.ts +5 -0
- package/dist/runtime/theme/textarea.js +1 -0
- package/dist/runtime/types/lib.d.ts +1 -1
- package/dist/runtime/utils/ArrayHelper.d.ts +1 -1
- package/dist/runtime/utils/{ArrayHelper.mjs → ArrayHelper.js} +1 -1
- package/dist/runtime/utils/ObjectHelper.d.ts +3 -3
- package/dist/runtime/utils/{ObjectHelper.mjs → ObjectHelper.js} +3 -3
- package/dist/runtime/utils/ParamHelper.d.ts +1 -1
- package/dist/runtime/utils/{ParamHelper.mjs → ParamHelper.js} +1 -1
- package/dist/types.d.mts +2 -15
- package/package.json +91 -100
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -50
- package/dist/runtime/components/Alert.vue +0 -48
- package/dist/runtime/components/Avatar.vue +0 -27
- package/dist/runtime/components/Badge.vue +0 -11
- package/dist/runtime/components/Breadcrumb.vue +0 -44
- package/dist/runtime/components/Button/Group.vue +0 -37
- package/dist/runtime/components/Button/index.vue +0 -75
- package/dist/runtime/components/Card.vue +0 -38
- package/dist/runtime/components/Core.vue +0 -45
- package/dist/runtime/components/Dropdown/index.vue +0 -70
- package/dist/runtime/components/Dropdown/types.d.ts +0 -2
- package/dist/runtime/components/Dropdown/types.mjs +0 -17
- package/dist/runtime/components/Form/InputDateTimeRange/date_range_time_field.types.d.ts +0 -17
- package/dist/runtime/components/Form/InputDateTimeRange/index.vue +0 -91
- package/dist/runtime/components/Form/InputRadio/index.vue +0 -27
- package/dist/runtime/components/Form/InputRadio/types.d.ts +0 -8
- package/dist/runtime/components/Form/InputStatic/index.vue +0 -16
- package/dist/runtime/components/Form/InputStatic/types.d.ts +0 -4
- package/dist/runtime/components/Form/InputTags/index.vue +0 -141
- package/dist/runtime/components/Form/InputTags/types.d.ts +0 -11
- package/dist/runtime/components/Form/InputTextarea/types.mjs +0 -0
- package/dist/runtime/components/Form/InputToggle/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzone/index.vue +0 -206
- package/dist/runtime/components/Form/InputUploadDropzone/types.d.ts +0 -11
- package/dist/runtime/components/Form/InputUploadDropzone/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +0 -362
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +0 -23
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/ItemUpload.vue +0 -241
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/ItemView.vue +0 -110
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/index.vue +0 -171
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/types.d.ts +0 -23
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/ItemUpload.vue +0 -161
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/ItemView.vue +0 -64
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/index.vue +0 -178
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/types.d.ts +0 -21
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +0 -95
- package/dist/runtime/components/Form/InputUploadFileClassic/types.d.ts +0 -13
- package/dist/runtime/components/Form/InputUploadFileClassic/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +0 -151
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/types.d.ts +0 -18
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadImageAuto/index.vue +0 -219
- package/dist/runtime/components/Form/InputUploadImageAuto/types.d.ts +0 -20
- package/dist/runtime/components/Form/InputUploadImageAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputWYSIWYG/UploadImageForm.vue +0 -55
- package/dist/runtime/components/Form/InputWYSIWYG/index.vue +0 -230
- package/dist/runtime/components/Form/InputWYSIWYG/types.d.ts +0 -19
- package/dist/runtime/components/Form/InputWYSIWYG/types.mjs +0 -0
- package/dist/runtime/components/Icon.vue +0 -23
- package/dist/runtime/components/Log.vue +0 -22
- package/dist/runtime/components/Modal/index.vue +0 -146
- package/dist/runtime/components/OTPInput.vue +0 -127
- package/dist/runtime/components/QRCode.vue +0 -22
- package/dist/runtime/components/SimplePagination.vue +0 -96
- package/dist/runtime/components/Slideover/index.vue +0 -110
- package/dist/runtime/components/Tabs/index.vue +0 -64
- package/dist/runtime/composables/loaderList.mjs +0 -52
- package/dist/runtime/composables/loaderObject.mjs +0 -52
- package/dist/runtime/composables/loaderPage.mjs +0 -229
- package/dist/runtime/composables/useConfig.mjs +0 -9
- package/dist/runtime/composables/useDialog.mjs +0 -81
- package/dist/runtime/composables/useForm.mjs +0 -18
- package/dist/runtime/core.config.d.ts +0 -14
- package/dist/runtime/core.config.mjs +0 -14
- package/dist/runtime/helpers/apiListHelper.mjs +0 -44
- package/dist/runtime/helpers/apiObjectHelper.mjs +0 -46
- package/dist/runtime/helpers/apiPageHelper.mjs +0 -270
- package/dist/runtime/plugin.mjs +0 -149
- package/dist/runtime/types/common.mjs +0 -0
- package/dist/runtime/types/config.d.ts +0 -1
- package/dist/runtime/types/config.mjs +0 -0
- package/dist/runtime/types/lib.mjs +0 -0
- package/dist/runtime/ui.config/alert.d.ts +0 -3
- package/dist/runtime/ui.config/alert.mjs +0 -6
- package/dist/runtime/ui.config/badge.d.ts +0 -3
- package/dist/runtime/ui.config/badge.mjs +0 -1
- package/dist/runtime/ui.config/breadcrumb.d.ts +0 -1
- package/dist/runtime/ui.config/breadcrumb.mjs +0 -7
- package/dist/runtime/ui.config/button.d.ts +0 -3
- package/dist/runtime/ui.config/button.mjs +0 -8
- package/dist/runtime/ui.config/buttonGroup.d.ts +0 -3
- package/dist/runtime/ui.config/buttonGroup.mjs +0 -1
- package/dist/runtime/ui.config/card.d.ts +0 -1
- package/dist/runtime/ui.config/card.mjs +0 -2
- package/dist/runtime/ui.config/checkbox.d.ts +0 -3
- package/dist/runtime/ui.config/checkbox.mjs +0 -1
- package/dist/runtime/ui.config/formGroup.d.ts +0 -3
- package/dist/runtime/ui.config/formGroup.mjs +0 -5
- package/dist/runtime/ui.config/icon.d.ts +0 -3
- package/dist/runtime/ui.config/icon.mjs +0 -3
- package/dist/runtime/ui.config/index.d.ts +0 -16
- package/dist/runtime/ui.config/index.mjs +0 -16
- package/dist/runtime/ui.config/input.d.ts +0 -3
- package/dist/runtime/ui.config/input.mjs +0 -5
- package/dist/runtime/ui.config/modal.d.ts +0 -1
- package/dist/runtime/ui.config/modal.mjs +0 -34
- package/dist/runtime/ui.config/notification.d.ts +0 -11
- package/dist/runtime/ui.config/notification.mjs +0 -13
- package/dist/runtime/ui.config/notifications.d.ts +0 -3
- package/dist/runtime/ui.config/notifications.mjs +0 -3
- package/dist/runtime/ui.config/pagination.d.ts +0 -3
- package/dist/runtime/ui.config/pagination.mjs +0 -37
- package/dist/runtime/ui.config/select.d.ts +0 -3
- package/dist/runtime/ui.config/select.mjs +0 -5
- package/dist/runtime/ui.config/selectMenu.d.ts +0 -3
- package/dist/runtime/ui.config/selectMenu.mjs +0 -5
- package/dist/runtime/ui.config/slideover.d.ts +0 -1
- package/dist/runtime/ui.config/slideover.mjs +0 -16
- package/dist/runtime/ui.config/table.d.ts +0 -3
- package/dist/runtime/ui.config/table.mjs +0 -47
- package/dist/runtime/ui.config/tabs.d.ts +0 -3
- package/dist/runtime/ui.config/tabs.mjs +0 -4
- package/dist/runtime/ui.config/tags.d.ts +0 -25
- package/dist/runtime/ui.config/tags.mjs +0 -25
- package/dist/runtime/ui.config/textarea.d.ts +0 -3
- package/dist/runtime/ui.config/textarea.mjs +0 -5
- package/dist/runtime/ui.config/toggle.d.ts +0 -3
- package/dist/runtime/ui.config/toggle.mjs +0 -5
- package/dist/runtime/ui.config/uploadDropzoneImage.d.ts +0 -83
- package/dist/runtime/ui.config/uploadDropzoneImage.mjs +0 -26
- package/dist/runtime/ui.config/uploadFileDropzone.d.ts +0 -61
- package/dist/runtime/ui.config/uploadFileDropzone.mjs +0 -61
- package/dist/runtime/ui.config/uploadFileInputClassicAuto.d.ts +0 -8
- package/dist/runtime/ui.config/uploadFileInputClassicAuto.mjs +0 -8
- package/dist/runtime/ui.config/uploadImage.d.ts +0 -34
- package/dist/runtime/ui.config/uploadImage.mjs +0 -36
- package/dist/runtime/ui.css +0 -1
- package/dist/runtime/utils/ArrayHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ArrayHelper.spec.mjs +0 -112
- package/dist/runtime/utils/FileHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/FileHelper.spec.mjs +0 -14
- package/dist/runtime/utils/ObjectHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ObjectHelper.spec.mjs +0 -52
- package/dist/runtime/utils/ParamHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ParamHelper.spec.mjs +0 -78
- package/dist/runtime/utils/StringHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/StringHelper.spec.mjs +0 -76
- package/dist/runtime/utils/TimeHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/TimeHelper.spec.mjs +0 -79
- package/dist/runtime/utils/TimeHelper.thai.spec.d.ts +0 -1
- package/dist/runtime/utils/TimeHelper.thai.spec.mjs +0 -31
- package/dist/types.d.ts +0 -16
- package/dist/runtime/components/FlexDeck/{types.mjs → types.js} +0 -0
- package/dist/runtime/components/Form/InputCheckbox/{types.mjs → types.js} +0 -0
- package/dist/runtime/components/Form/InputDateTime/{date_time_field.types.mjs → date_time_field.types.js} +0 -0
- package/dist/runtime/components/Form/{InputDateTimeRange/date_range_time_field.types.mjs → InputNumber/types.js} +0 -0
- package/dist/runtime/components/Form/{InputNumber/types.mjs → InputSelect/types.js} +0 -0
- package/dist/runtime/components/Form/{InputRadio/types.mjs → InputSelectMultiple/types.js} +0 -0
- package/dist/runtime/components/Form/{InputSelect/types.mjs → InputText/types.js} +0 -0
- package/dist/runtime/components/Form/{InputSelectMultiple/types.mjs → InputTextarea/types.js} +0 -0
- package/dist/runtime/components/Form/{InputStatic/types.mjs → InputToggle/types.js} +0 -0
- package/dist/runtime/components/Form/{types.mjs → types.js} +0 -0
- package/dist/runtime/composables/{useWatch.mjs → useWatch.js} +0 -0
- package/dist/runtime/lib/{Requester.mjs → Requester.js} +0 -0
- package/dist/runtime/{components/Form/InputTags/types.mjs → types/common.js} +0 -0
- package/dist/runtime/{components/Form/InputText/types.mjs → types/lib.js} +0 -0
- package/dist/runtime/utils/{FileHelper.mjs → FileHelper.js} +0 -0
- package/dist/runtime/utils/{StringHelper.mjs → StringHelper.js} +0 -0
- package/dist/runtime/utils/{TimeHelper.mjs → TimeHelper.js} +1 -1
- /package/dist/runtime/utils/{lodash.mjs → lodash.js} +0 -0
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<div
|
|
4
|
-
ref="dropzoneRef"
|
|
5
|
-
:class="[
|
|
6
|
-
ui.base,
|
|
7
|
-
{
|
|
8
|
-
[ui.disabled]: isDisabled,
|
|
9
|
-
[ui.background.default]: !isOverDropZone && !isDisabled,
|
|
10
|
-
[ui.background.dragover]: isOverDropZone && (!isDisabled || !isReadonly),
|
|
11
|
-
[ui.failed]: upload.status.value.isError,
|
|
12
|
-
},
|
|
13
|
-
]"
|
|
14
|
-
>
|
|
15
|
-
<input
|
|
16
|
-
ref="fileInputRef"
|
|
17
|
-
type="file"
|
|
18
|
-
class="hidden"
|
|
19
|
-
:name="name"
|
|
20
|
-
:accept="fileAllocate.acceptFile.value"
|
|
21
|
-
:disabled="isDisabled || isReadonly"
|
|
22
|
-
@change="handleChange"
|
|
23
|
-
/>
|
|
24
|
-
<div :class="[ui.wrapper]">
|
|
25
|
-
<div v-if="!selectedFile && !value" :class="[ui.placeholderWrapper]">
|
|
26
|
-
<Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
|
|
27
|
-
<div :class="[ui.labelWrapper]">
|
|
28
|
-
<p class="text-primary cursor-pointer" @click="handleOpenFile">
|
|
29
|
-
{{ selectFileLabel }}
|
|
30
|
-
</p>
|
|
31
|
-
<p>{{ selectFileSubLabel }}</p>
|
|
32
|
-
</div>
|
|
33
|
-
<p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
|
|
34
|
-
</div>
|
|
35
|
-
|
|
36
|
-
<!-- Loading State -->
|
|
37
|
-
<div v-if="selectedFile && upload.status.value.isLoading" :class="[ui.onLoading.wrapper]">
|
|
38
|
-
<div :class="[ui.onLoading.placeholderWrapper]">
|
|
39
|
-
<Icon
|
|
40
|
-
:name="
|
|
41
|
-
isImage(selectedFile)
|
|
42
|
-
? ui.onLoading.placeholderImgIcon || ui.default.placeholderImgIcon
|
|
43
|
-
: ui.onLoading.placeholderFileIcon || ui.default.filePreviewIcon
|
|
44
|
-
"
|
|
45
|
-
:class="[ui.onLoading.placeholderIconClass]"
|
|
46
|
-
/>
|
|
47
|
-
</div>
|
|
48
|
-
<div :class="[ui.onLoading.textWrapper]">
|
|
49
|
-
<div class="truncate">
|
|
50
|
-
<h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
|
|
51
|
-
<p class="truncate font-light text-gray-400">
|
|
52
|
-
{{
|
|
53
|
-
fileAllocate.isSelectedFileUseMb.value
|
|
54
|
-
? `${fileAllocate.selectedFileSizeMb.value} MB`
|
|
55
|
-
: `${fileAllocate.selectedFileSizeKb.value} KB`
|
|
56
|
-
}}
|
|
57
|
-
- {{ percent }}% {{ uploadingLabel }}
|
|
58
|
-
</p>
|
|
59
|
-
</div>
|
|
60
|
-
<div>
|
|
61
|
-
<Icon
|
|
62
|
-
:name="ui.onLoading.loadingIcon || ui.default.loadingIcon"
|
|
63
|
-
:class="[ui.onLoading.loadingIconClass]"
|
|
64
|
-
/>
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
</div>
|
|
68
|
-
|
|
69
|
-
<!-- Success State -->
|
|
70
|
-
<div v-if="value" :class="[ui.onPreview.wrapper]">
|
|
71
|
-
<div :class="[ui.onPreview.previewImgWrapper]">
|
|
72
|
-
<div v-if="isImageFromPath(value.path)" class="size-full overflow-hidden">
|
|
73
|
-
<img :src="value.url" :class="[ui.onPreview.previewImgClass]" alt="img-preview" />
|
|
74
|
-
</div>
|
|
75
|
-
<div v-else>
|
|
76
|
-
<Icon
|
|
77
|
-
:name="ui.onPreview.previewFileIcon || ui.default.filePreviewIcon"
|
|
78
|
-
:class="[ui.onPreview.previewFileClass]"
|
|
79
|
-
/>
|
|
80
|
-
</div>
|
|
81
|
-
</div>
|
|
82
|
-
<div :class="[ui.onPreview.textWrapper]">
|
|
83
|
-
<div class="truncate">
|
|
84
|
-
<h1 class="truncate font-bold">{{ value.name }}</h1>
|
|
85
|
-
<p class="truncate text-sm font-light text-gray-400">
|
|
86
|
-
{{
|
|
87
|
-
fileAllocateFromPath.isSelectedFileUseMb.value
|
|
88
|
-
? `${fileAllocateFromPath.selectedFileSizeMb.value} MB`
|
|
89
|
-
: `${fileAllocateFromPath.selectedFileSizeKb.value} KB`
|
|
90
|
-
}}
|
|
91
|
-
</p>
|
|
92
|
-
</div>
|
|
93
|
-
<div :class="[ui.action.wrapper]">
|
|
94
|
-
<a v-if="isPDFFromPath(value.path)" :href="value.url" target="_blank" class="flex">
|
|
95
|
-
<Icon
|
|
96
|
-
:name="ui.action.previewIcon"
|
|
97
|
-
:class="[ui.action.iconClass]"
|
|
98
|
-
title="ดูตัวอย่าง"
|
|
99
|
-
/>
|
|
100
|
-
</a>
|
|
101
|
-
<Icon
|
|
102
|
-
v-if="isImageFromPath(value.path) || isVideoFromPath(value.path)"
|
|
103
|
-
:name="ui.action.previewIcon"
|
|
104
|
-
:class="[ui.action.iconClass]"
|
|
105
|
-
title="ดูตัวอย่าง"
|
|
106
|
-
@click="() => (isPreviewOpen = true)"
|
|
107
|
-
/>
|
|
108
|
-
<Icon
|
|
109
|
-
:name="ui.action.downloadIcon"
|
|
110
|
-
:class="[ui.action.iconClass]"
|
|
111
|
-
title="ดาวน์โหลดไฟล์"
|
|
112
|
-
@click="handleDownloadFile"
|
|
113
|
-
/>
|
|
114
|
-
<Icon
|
|
115
|
-
v-if="!(isDisabled || isReadonly)"
|
|
116
|
-
:name="ui.action.deleteIcon"
|
|
117
|
-
:class="[ui.action.iconClass]"
|
|
118
|
-
title="ลบไฟล์"
|
|
119
|
-
@click="handleDeleteFile"
|
|
120
|
-
/>
|
|
121
|
-
<Modal v-model="isPreviewOpen" :title="value.name">
|
|
122
|
-
<img
|
|
123
|
-
v-if="isImageFromPath(value.path)"
|
|
124
|
-
:src="value.url"
|
|
125
|
-
alt="img-preview"
|
|
126
|
-
class="mx-auto max-w-full rounded-lg"
|
|
127
|
-
/>
|
|
128
|
-
<video
|
|
129
|
-
v-else-if="isVideoFromPath(value.path)"
|
|
130
|
-
:src="value.url"
|
|
131
|
-
controls
|
|
132
|
-
class="mx-auto max-w-full"
|
|
133
|
-
/>
|
|
134
|
-
</Modal>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
</div>
|
|
138
|
-
|
|
139
|
-
<!-- Failed State -->
|
|
140
|
-
<div v-if="selectedFile && upload.status.value.isError" :class="[ui.onFailed.wrapper]">
|
|
141
|
-
<div :class="[ui.onFailed.failedImgWrapper]">
|
|
142
|
-
<Icon
|
|
143
|
-
:name="
|
|
144
|
-
isImage(selectedFile)
|
|
145
|
-
? ui.onFailed.failedImgIcon || ui.default.placeholderImgIcon
|
|
146
|
-
: ui.onFailed.failedFileIcon || ui.default.filePreviewIcon
|
|
147
|
-
"
|
|
148
|
-
:class="[ui.onFailed.failedIconClass]"
|
|
149
|
-
/>
|
|
150
|
-
</div>
|
|
151
|
-
<div :class="[ui.onFailed.textWrapper]">
|
|
152
|
-
<div class="truncate">
|
|
153
|
-
<h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
|
|
154
|
-
<p class="text-danger truncate font-light">
|
|
155
|
-
{{ uploadFailedLabel }}
|
|
156
|
-
</p>
|
|
157
|
-
<Button
|
|
158
|
-
variant="ghost"
|
|
159
|
-
:label="retryLabel"
|
|
160
|
-
:leading-icon="ui.action.retryIcon"
|
|
161
|
-
:class="[ui.action.retryBtnClass]"
|
|
162
|
-
size="sm"
|
|
163
|
-
@click="handleRetryUpload"
|
|
164
|
-
/>
|
|
165
|
-
</div>
|
|
166
|
-
<div :class="[ui.action.wrapper]">
|
|
167
|
-
<Icon
|
|
168
|
-
title="ลบไฟล์"
|
|
169
|
-
:name="ui.action.deleteIcon"
|
|
170
|
-
:class="[ui.action.deleteIconClass]"
|
|
171
|
-
@click="handleDeleteFile"
|
|
172
|
-
/>
|
|
173
|
-
</div>
|
|
174
|
-
</div>
|
|
175
|
-
</div>
|
|
176
|
-
</div>
|
|
177
|
-
</div>
|
|
178
|
-
</FieldWrapper>
|
|
179
|
-
</template>
|
|
180
|
-
|
|
181
|
-
<script lang="ts" setup>
|
|
182
|
-
import { useDropZone } from '@vueuse/core'
|
|
183
|
-
import { type IUploadDropzoneAutoProps } from './types'
|
|
184
|
-
import {
|
|
185
|
-
checkMaxSize,
|
|
186
|
-
checkFileType,
|
|
187
|
-
isImage,
|
|
188
|
-
downloadFileFromURL,
|
|
189
|
-
useFileAllocate,
|
|
190
|
-
useFileProgress,
|
|
191
|
-
isImageFromPath,
|
|
192
|
-
useFileSize,
|
|
193
|
-
isPDFFromPath,
|
|
194
|
-
isVideoFromPath,
|
|
195
|
-
} from '#core/helpers/componentHelper'
|
|
196
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
197
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
198
|
-
import {
|
|
199
|
-
type IUploadRequest,
|
|
200
|
-
ref,
|
|
201
|
-
computed,
|
|
202
|
-
toRef,
|
|
203
|
-
useUI,
|
|
204
|
-
useUiConfig,
|
|
205
|
-
useUploadLoader,
|
|
206
|
-
useWatchTrue,
|
|
207
|
-
StringHelper,
|
|
208
|
-
_get,
|
|
209
|
-
} from '#imports'
|
|
210
|
-
import { uploadFileDropzone } from '#core/ui.config'
|
|
211
|
-
import i18next from 'i18next'
|
|
212
|
-
import type { IFileValue } from '#core/components/Form/types'
|
|
213
|
-
|
|
214
|
-
const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
|
|
215
|
-
|
|
216
|
-
const props = withDefaults(defineProps<IUploadDropzoneAutoProps>(), {
|
|
217
|
-
bodyKey: 'file',
|
|
218
|
-
responseURL: 'url',
|
|
219
|
-
responsePath: 'path',
|
|
220
|
-
selectFileLabel: 'คลิกเพื่อเลือกไฟล์',
|
|
221
|
-
selectFileSubLabel: 'หรือ ลากและวางที่นี่',
|
|
222
|
-
uploadingLabel: 'กำลังอัพโหลด...',
|
|
223
|
-
uploadFailedLabel: 'อัพโหลดล้มเหลว, กรุณาลองอีกครั้ง',
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
const emits = defineEmits(['change', 'success', 'delete'])
|
|
227
|
-
|
|
228
|
-
const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<IFileValue>(props)
|
|
229
|
-
|
|
230
|
-
const request: IUploadRequest = {
|
|
231
|
-
pathURL: props.uploadPathURL,
|
|
232
|
-
requestOptions: props.requestOptions,
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const upload = useUploadLoader(request)
|
|
236
|
-
|
|
237
|
-
const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
|
|
238
|
-
|
|
239
|
-
const fileInputRef = ref<HTMLInputElement>()
|
|
240
|
-
const dropzoneRef = ref<HTMLDivElement>()
|
|
241
|
-
const selectedFile = ref<File | undefined>()
|
|
242
|
-
const isPreviewOpen = ref<boolean>(false)
|
|
243
|
-
|
|
244
|
-
const { onUploadProgress, onDownloadProgress, percent } = useFileProgress()
|
|
245
|
-
const fileAllocate = useFileAllocate(selectedFile, props)
|
|
246
|
-
const fileAllocateFromPath = computed(() => useFileSize(value.value?.size))
|
|
247
|
-
|
|
248
|
-
const onDrop = (files: File[] | null) => {
|
|
249
|
-
if (props.isDisabled || files?.length === 0 || !files) return
|
|
250
|
-
|
|
251
|
-
const file = files[0]
|
|
252
|
-
const result = handleCheckFileCondition(file)
|
|
253
|
-
|
|
254
|
-
if (result && file) {
|
|
255
|
-
selectedFile.value = file
|
|
256
|
-
const formData = new FormData()
|
|
257
|
-
|
|
258
|
-
emits('change', file)
|
|
259
|
-
|
|
260
|
-
formData.append(props.bodyKey, file)
|
|
261
|
-
upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
|
|
266
|
-
onDrop,
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
const handleChange = (e: Event) => {
|
|
270
|
-
if (props.isDisabled || props.isReadonly) return
|
|
271
|
-
|
|
272
|
-
const file = (e.target as HTMLInputElement).files?.[0]
|
|
273
|
-
const result = handleCheckFileCondition(file)
|
|
274
|
-
|
|
275
|
-
if (result && file) {
|
|
276
|
-
selectedFile.value = file
|
|
277
|
-
const formData = new FormData()
|
|
278
|
-
|
|
279
|
-
emits('change', file)
|
|
280
|
-
|
|
281
|
-
formData.append(props.bodyKey, file)
|
|
282
|
-
upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const handleOpenFile = () => {
|
|
287
|
-
fileInputRef.value?.click()
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const handleDeleteFile = () => {
|
|
291
|
-
fileInputRef.value?.value && (fileInputRef.value.value = '')
|
|
292
|
-
selectedFile.value = undefined
|
|
293
|
-
onChange(undefined)
|
|
294
|
-
emits('delete')
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const handleCheckFileCondition = (file: File | undefined): boolean => {
|
|
298
|
-
if (!file) return false
|
|
299
|
-
|
|
300
|
-
const fileType = checkFileType(file, fileAllocate.acceptFile.value ?? '')
|
|
301
|
-
|
|
302
|
-
if (!fileType) {
|
|
303
|
-
setErrors(i18next.t('custom:invalid_file_type'))
|
|
304
|
-
|
|
305
|
-
return false
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const maxSize = checkMaxSize(file, fileAllocate.acceptFileSizeKb.value)
|
|
309
|
-
|
|
310
|
-
if (!maxSize) {
|
|
311
|
-
if (fileAllocate.isAcceptFileUseMb.value) {
|
|
312
|
-
setErrors(
|
|
313
|
-
i18next.t('custom:invalid_file_size_mb', { size: fileAllocate.acceptFileSizeMb.value })
|
|
314
|
-
)
|
|
315
|
-
} else {
|
|
316
|
-
setErrors(
|
|
317
|
-
i18next.t('custom:invalid_file_size_kb', { size: fileAllocate.acceptFileSizeKb.value })
|
|
318
|
-
)
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return false
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
setErrors('')
|
|
325
|
-
|
|
326
|
-
return true
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const handleDownloadFile = () => {
|
|
330
|
-
downloadFileFromURL(value.value?.url, value.value?.name)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const handleRetryUpload = () => {
|
|
334
|
-
if (selectedFile.value) {
|
|
335
|
-
const formData = new FormData()
|
|
336
|
-
|
|
337
|
-
formData.append(props.bodyKey, selectedFile.value)
|
|
338
|
-
upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
useWatchTrue(
|
|
343
|
-
() => upload.status.value.isSuccess,
|
|
344
|
-
() => {
|
|
345
|
-
value.value = {
|
|
346
|
-
url: _get(upload.data.value, props.responseURL),
|
|
347
|
-
path: _get(upload.data.value, props.responsePath),
|
|
348
|
-
name: upload.data.value.file_name,
|
|
349
|
-
size: upload.data.value.size,
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
emits('success', value.value)
|
|
353
|
-
}
|
|
354
|
-
)
|
|
355
|
-
|
|
356
|
-
useWatchTrue(
|
|
357
|
-
() => upload.status.value.isError,
|
|
358
|
-
() => {
|
|
359
|
-
setErrors(StringHelper.getError(upload.status.value.errorData))
|
|
360
|
-
}
|
|
361
|
-
)
|
|
362
|
-
</script>
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { type IFieldProps, type IFormFieldBase, type INPUT_TYPES } from '../types';
|
|
3
|
-
export interface IUploadDropzoneAutoProps extends IFieldProps {
|
|
4
|
-
requestOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
5
|
-
baseURL: string;
|
|
6
|
-
};
|
|
7
|
-
uploadPathURL?: string;
|
|
8
|
-
selectFileLabel?: string;
|
|
9
|
-
selectFileSubLabel?: string;
|
|
10
|
-
uploadingLabel?: string;
|
|
11
|
-
uploadFailedLabel?: string;
|
|
12
|
-
retryLabel?: string;
|
|
13
|
-
accept?: string[] | string;
|
|
14
|
-
bodyKey?: string;
|
|
15
|
-
responseURL?: string;
|
|
16
|
-
responsePath?: string;
|
|
17
|
-
maxSize?: number;
|
|
18
|
-
}
|
|
19
|
-
export type IUploadDropzoneAutoField = IFormFieldBase<INPUT_TYPES.UPLOAD_DROPZONE_AUTO, IUploadDropzoneAutoProps, {
|
|
20
|
-
change: (value: File | undefined) => void;
|
|
21
|
-
success: (res: any) => void;
|
|
22
|
-
delete: () => void;
|
|
23
|
-
}>;
|
|
File without changes
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
:class="[
|
|
4
|
-
ui.base,
|
|
5
|
-
ui.background.default,
|
|
6
|
-
{
|
|
7
|
-
[ui.failed]: upload.status.value.isError || errMsg,
|
|
8
|
-
},
|
|
9
|
-
]"
|
|
10
|
-
>
|
|
11
|
-
<!-- Loading State -->
|
|
12
|
-
<div v-if="selectedFile && upload.status.value.isLoading" :class="[ui.onLoading.wrapper]">
|
|
13
|
-
<div :class="[ui.onLoading.placeholderWrapper]">
|
|
14
|
-
<Icon
|
|
15
|
-
:name="
|
|
16
|
-
isImage(selectedFile)
|
|
17
|
-
? ui.onLoading.placeholderImgIcon || ui.default.placeholderImgIcon
|
|
18
|
-
: ui.onLoading.placeholderFileIcon || ui.default.filePreviewIcon
|
|
19
|
-
"
|
|
20
|
-
:class="[ui.onLoading.placeholderIconClass]"
|
|
21
|
-
/>
|
|
22
|
-
</div>
|
|
23
|
-
<div :class="[ui.onLoading.textWrapper]">
|
|
24
|
-
<div class="truncate">
|
|
25
|
-
<h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
|
|
26
|
-
<p class="truncate font-light text-gray-400">
|
|
27
|
-
{{
|
|
28
|
-
fileAllocate.isSelectedFileUseMb.value
|
|
29
|
-
? `${fileAllocate.selectedFileSizeMb.value} MB`
|
|
30
|
-
: `${fileAllocate.selectedFileSizeKb.value} KB`
|
|
31
|
-
}}
|
|
32
|
-
- {{ percent }}% {{ uploadingLabel }}
|
|
33
|
-
</p>
|
|
34
|
-
</div>
|
|
35
|
-
<div>
|
|
36
|
-
<Icon
|
|
37
|
-
:name="ui.onLoading.loadingIcon || ui.default.loadingIcon"
|
|
38
|
-
:class="[ui.onLoading.loadingIconClass]"
|
|
39
|
-
/>
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<!-- Success State -->
|
|
45
|
-
<div v-if="selectedFile && upload.status.value.isSuccess" :class="[ui.onPreview.wrapper]">
|
|
46
|
-
<div :class="[ui.onPreview.previewImgWrapper]">
|
|
47
|
-
<div v-if="isImage(selectedFile)" class="size-full overflow-hidden">
|
|
48
|
-
<img
|
|
49
|
-
:src="upload.data.value[responseURL!]"
|
|
50
|
-
:class="[ui.onPreview.previewImgClass]"
|
|
51
|
-
alt="image-preview"
|
|
52
|
-
/>
|
|
53
|
-
</div>
|
|
54
|
-
<div v-else>
|
|
55
|
-
<Icon
|
|
56
|
-
:name="ui.onPreview.previewFileIcon || ui.default.filePreviewIcon"
|
|
57
|
-
:class="[ui.onPreview.previewFileClass]"
|
|
58
|
-
/>
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
<div :class="[ui.onPreview.textWrapper]">
|
|
62
|
-
<div class="truncate">
|
|
63
|
-
<h1 class="truncate font-bold" :title="selectedFile?.name">
|
|
64
|
-
{{ StringHelper.truncate(selectedFile?.name, 40) }}
|
|
65
|
-
</h1>
|
|
66
|
-
<p class="truncate text-sm font-light text-gray-400">
|
|
67
|
-
{{
|
|
68
|
-
fileAllocate.isSelectedFileUseMb.value
|
|
69
|
-
? `${fileAllocate.selectedFileSizeMb.value} MB`
|
|
70
|
-
: `${fileAllocate.selectedFileSizeKb.value} KB`
|
|
71
|
-
}}
|
|
72
|
-
</p>
|
|
73
|
-
</div>
|
|
74
|
-
<div :class="[ui.action.wrapper]">
|
|
75
|
-
<Icon
|
|
76
|
-
:name="ui.action.deleteIcon"
|
|
77
|
-
:class="[ui.action.iconClass]"
|
|
78
|
-
title="ลบไฟล์"
|
|
79
|
-
@click="handleDeleteFile"
|
|
80
|
-
/>
|
|
81
|
-
</div>
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
|
|
85
|
-
<!-- Failed State -->
|
|
86
|
-
<div
|
|
87
|
-
v-if="selectedFile && (upload.status.value.isError || errMsg)"
|
|
88
|
-
:class="[ui.onFailed.wrapper]"
|
|
89
|
-
>
|
|
90
|
-
<div :class="[ui.onFailed.failedImgWrapper]">
|
|
91
|
-
<Icon
|
|
92
|
-
:name="
|
|
93
|
-
isImage(selectedFile)
|
|
94
|
-
? ui.onFailed.failedImgIcon || ui.default.placeholderImgIcon
|
|
95
|
-
: ui.onFailed.failedFileIcon || ui.default.filePreviewIcon
|
|
96
|
-
"
|
|
97
|
-
:class="[ui.onFailed.failedIconClass]"
|
|
98
|
-
/>
|
|
99
|
-
</div>
|
|
100
|
-
<div :class="[ui.onFailed.textWrapper]">
|
|
101
|
-
<div class="truncate">
|
|
102
|
-
<h1 class="truncate font-bold" :title="selectedFile?.name">
|
|
103
|
-
{{ StringHelper.truncate(selectedFile?.name, 40) }}
|
|
104
|
-
</h1>
|
|
105
|
-
<p class="text-danger truncate font-light">
|
|
106
|
-
{{ errMsg ? errMsg : uploadFailedLabel }}
|
|
107
|
-
</p>
|
|
108
|
-
<Button
|
|
109
|
-
v-if="upload.status.value.isError"
|
|
110
|
-
variant="ghost"
|
|
111
|
-
:label="retryLabel"
|
|
112
|
-
:leading-icon="ui.action.retryIcon"
|
|
113
|
-
:class="[ui.action.retryBtnClass]"
|
|
114
|
-
size="sm"
|
|
115
|
-
@click="handleRetryUpload"
|
|
116
|
-
/>
|
|
117
|
-
</div>
|
|
118
|
-
<div :class="[ui.action.wrapper]">
|
|
119
|
-
<Icon
|
|
120
|
-
title="ลบไฟล์"
|
|
121
|
-
:name="ui.action.deleteIcon"
|
|
122
|
-
:class="[ui.action.deleteIconClass]"
|
|
123
|
-
@click="handleDeleteFile"
|
|
124
|
-
/>
|
|
125
|
-
</div>
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
</template>
|
|
130
|
-
<script lang="ts" setup>
|
|
131
|
-
import {
|
|
132
|
-
checkFileType,
|
|
133
|
-
checkMaxSize,
|
|
134
|
-
isImage,
|
|
135
|
-
useFileAllocate,
|
|
136
|
-
useFileProgress,
|
|
137
|
-
} from '#core/helpers/componentHelper'
|
|
138
|
-
import { type uploadFileDropzone } from '#core/ui.config'
|
|
139
|
-
import type { IUploadDropzoneAutoMultipleProps } from '#core/components/Form/InputUploadDropzoneAutoMultiple/types'
|
|
140
|
-
import {
|
|
141
|
-
type IUploadRequest,
|
|
142
|
-
onMounted,
|
|
143
|
-
ref,
|
|
144
|
-
toRef,
|
|
145
|
-
StringHelper,
|
|
146
|
-
useUploadLoader,
|
|
147
|
-
useWatchTrue,
|
|
148
|
-
} from '#imports'
|
|
149
|
-
import i18next from 'i18next'
|
|
150
|
-
|
|
151
|
-
const emits = defineEmits(['success', 'error', 'delete'])
|
|
152
|
-
const props = defineProps<
|
|
153
|
-
{
|
|
154
|
-
ui: typeof uploadFileDropzone
|
|
155
|
-
selectedFile: File
|
|
156
|
-
} & IUploadDropzoneAutoMultipleProps
|
|
157
|
-
>()
|
|
158
|
-
|
|
159
|
-
const request: IUploadRequest = {
|
|
160
|
-
pathURL: props.uploadPathURL,
|
|
161
|
-
requestOptions: props.requestOptions,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const upload = useUploadLoader(request)
|
|
165
|
-
const errMsg = ref<string>('')
|
|
166
|
-
|
|
167
|
-
const { onUploadProgress, onDownloadProgress, percent } = useFileProgress()
|
|
168
|
-
const fileAllocate = useFileAllocate(toRef(props.selectedFile), props)
|
|
169
|
-
|
|
170
|
-
const handleDeleteFile = () => {
|
|
171
|
-
emits('delete')
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const handleRetryUpload = () => {
|
|
175
|
-
const formData = new FormData()
|
|
176
|
-
|
|
177
|
-
formData.append(props.bodyKey!, props.selectedFile)
|
|
178
|
-
upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const handleCheckFileCondition = (file: File | undefined): boolean => {
|
|
182
|
-
if (!file) return false
|
|
183
|
-
|
|
184
|
-
const fileType = checkFileType(file, fileAllocate.acceptFile.value ?? '')
|
|
185
|
-
|
|
186
|
-
if (!fileType) {
|
|
187
|
-
errMsg.value = i18next.t('custom:invalid_file_type')
|
|
188
|
-
|
|
189
|
-
return false
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const maxSize = checkMaxSize(file, fileAllocate.acceptFileSizeKb.value)
|
|
193
|
-
|
|
194
|
-
if (!maxSize) {
|
|
195
|
-
if (fileAllocate.isAcceptFileUseMb.value) {
|
|
196
|
-
errMsg.value = i18next.t('custom:invalid_file_size_mb', {
|
|
197
|
-
size: fileAllocate.acceptFileSizeMb.value,
|
|
198
|
-
})
|
|
199
|
-
} else {
|
|
200
|
-
errMsg.value = i18next.t('custom:invalid_file_size_kb', {
|
|
201
|
-
size: fileAllocate.acceptFileSizeKb.value,
|
|
202
|
-
})
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return false
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
errMsg.value = ''
|
|
209
|
-
|
|
210
|
-
return true
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
onMounted(() => {
|
|
214
|
-
const result = handleCheckFileCondition(props.selectedFile)
|
|
215
|
-
|
|
216
|
-
if (result) {
|
|
217
|
-
const formData = new FormData()
|
|
218
|
-
|
|
219
|
-
formData.append(props.bodyKey!, props.selectedFile)
|
|
220
|
-
upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
useWatchTrue(
|
|
225
|
-
() => upload.status.value.isSuccess,
|
|
226
|
-
() => {
|
|
227
|
-
emits('success', {
|
|
228
|
-
...upload.data.value,
|
|
229
|
-
name: props.selectedFile.name,
|
|
230
|
-
size: +props.selectedFile.size,
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
)
|
|
234
|
-
|
|
235
|
-
useWatchTrue(
|
|
236
|
-
() => upload.status.value.isError,
|
|
237
|
-
() => {
|
|
238
|
-
emits('error', upload.status.value.errorData)
|
|
239
|
-
}
|
|
240
|
-
)
|
|
241
|
-
</script>
|