@finema/core 1.4.90 → 1.4.91

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.
Files changed (54) hide show
  1. package/README.md +63 -63
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +3 -2
  4. package/dist/runtime/components/Alert.vue +48 -48
  5. package/dist/runtime/components/Avatar.vue +27 -27
  6. package/dist/runtime/components/Badge.vue +53 -53
  7. package/dist/runtime/components/Breadcrumb.vue +44 -44
  8. package/dist/runtime/components/Button/Group.vue +37 -37
  9. package/dist/runtime/components/Button/index.vue +76 -76
  10. package/dist/runtime/components/Card.vue +38 -38
  11. package/dist/runtime/components/Core.vue +13 -13
  12. package/dist/runtime/components/Dialog/index.vue +108 -108
  13. package/dist/runtime/components/Dropdown/index.vue +70 -70
  14. package/dist/runtime/components/FlexDeck/Base.vue +90 -90
  15. package/dist/runtime/components/FlexDeck/index.vue +66 -66
  16. package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
  17. package/dist/runtime/components/Form/Fields.vue +160 -160
  18. package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
  19. package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
  20. package/dist/runtime/components/Form/InputNumber/index.vue +27 -27
  21. package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
  22. package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
  23. package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
  24. package/dist/runtime/components/Form/InputText/index.vue +67 -67
  25. package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
  26. package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
  27. package/dist/runtime/components/Form/InputUploadDropzone/index.vue +213 -158
  28. package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +349 -243
  29. package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +3 -0
  30. package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +101 -101
  31. package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +174 -174
  32. package/dist/runtime/components/Form/index.vue +6 -6
  33. package/dist/runtime/components/Icon.vue +23 -23
  34. package/dist/runtime/components/Image.vue +36 -36
  35. package/dist/runtime/components/Loader.vue +27 -27
  36. package/dist/runtime/components/Modal/index.vue +146 -146
  37. package/dist/runtime/components/SimplePagination.vue +96 -96
  38. package/dist/runtime/components/Slideover/index.vue +110 -110
  39. package/dist/runtime/components/Table/Base.vue +139 -139
  40. package/dist/runtime/components/Table/ColumnDate.vue +16 -16
  41. package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
  42. package/dist/runtime/components/Table/ColumnImage.vue +15 -15
  43. package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
  44. package/dist/runtime/components/Table/ColumnText.vue +25 -25
  45. package/dist/runtime/components/Table/Simple.vue +69 -69
  46. package/dist/runtime/components/Table/index.vue +65 -65
  47. package/dist/runtime/components/Tabs/index.vue +64 -64
  48. package/dist/runtime/helpers/componentHelper.d.ts +9 -0
  49. package/dist/runtime/helpers/componentHelper.mjs +30 -0
  50. package/dist/runtime/ui.config/uploadFileDropzone.d.ts +36 -13
  51. package/dist/runtime/ui.config/uploadFileDropzone.mjs +42 -19
  52. package/dist/runtime/utils/StringHelper.d.ts +1 -0
  53. package/dist/runtime/utils/StringHelper.mjs +6 -0
  54. package/package.json +88 -88
@@ -1,243 +1,349 @@
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,
11
- },
12
- ]"
13
- >
14
- <Icon
15
- v-if="selectedFile"
16
- :name="ui.default.closeIcon"
17
- :class="[ui.button.delete]"
18
- @click="handleDeleteFile"
19
- />
20
- <input
21
- ref="fileInputRef"
22
- type="file"
23
- class="hidden"
24
- :name="name"
25
- :accept="acceptFile"
26
- :disabled="isDisabled"
27
- @change="handleChange"
28
- />
29
- <div :class="[ui.wrapper]">
30
- <div v-if="selectedFile" :class="[ui.preview.wrapper]">
31
- <div
32
- v-if="isImage(selectedFile) && upload.status.value.isLoaded"
33
- :class="[ui.preview.image.wrapper]"
34
- >
35
- <img
36
- :src="upload.data.value[responseKey || 'url']"
37
- :class="[ui.preview.image.img]"
38
- alt="file"
39
- />
40
- </div>
41
- <Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
42
- <div :class="[ui.preview.filename]">
43
- <p class="truncate">{{ selectedFile.name }}</p>
44
- </div>
45
- <div class="flex items-center space-x-1">
46
- <Badge size="xs" variant="outline" class="mt-1">
47
- {{ isSelectedFileUseMb ? `${selectedFileSizeMb} MB` : `${selectedFileSizeKb} KB` }}
48
- </Badge>
49
- <div>
50
- <Icon
51
- v-if="upload.status.value.isSuccess"
52
- name="heroicons:check-circle-20-solid"
53
- class="text-success"
54
- />
55
- <Icon
56
- v-if="upload.status.value.isError"
57
- name="heroicons:x-circle-20-solid"
58
- class="text-danger"
59
- />
60
- </div>
61
- </div>
62
- </div>
63
- <div v-if="upload.status.value.isLoading" :class="[ui.uploadStatus.wrapper]">
64
- <UProgress :class="[ui.uploadStatus.progressBar]" :value="100" />
65
- </div>
66
- <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
67
- <Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
68
- <div :class="[ui.labelWrapper]">
69
- <p class="text-primary cursor-pointer" @click="handleOpenFile">
70
- {{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
71
- </p>
72
- <p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
73
- </div>
74
- <p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
75
- </div>
76
- </div>
77
- </div>
78
- </FieldWrapper>
79
- </template>
80
-
81
- <script lang="ts" setup>
82
- import { useDropZone } from '@vueuse/core'
83
- import { type IUploadDropzoneAutoProps } from './types'
84
- import { isImage, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
85
- import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
86
- import { useFieldHOC } from '#core/composables/useForm'
87
- import {
88
- type IUploadRequest,
89
- computed,
90
- ref,
91
- toRef,
92
- useUI,
93
- useUiConfig,
94
- useUploadLoader,
95
- useWatchTrue,
96
- StringHelper,
97
- _get,
98
- } from '#imports'
99
- import { uploadFileDropzone } from '#core/ui.config'
100
- import i18next from 'i18next'
101
-
102
- const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
103
-
104
- const props = withDefaults(defineProps<IUploadDropzoneAutoProps>(), {})
105
- const emits = defineEmits(['change', 'success', 'delete'])
106
-
107
- const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
108
-
109
- const request: IUploadRequest = {
110
- pathURL: props.uploadPathURL,
111
- requestOptions: props.requestOptions,
112
- }
113
-
114
- const upload = useUploadLoader(request)
115
-
116
- const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
117
-
118
- const fileInputRef = ref<HTMLInputElement>()
119
- const dropzoneRef = ref<HTMLDivElement>()
120
- const selectedFile = ref<File | undefined>()
121
- const percent = ref<number>(0)
122
-
123
- const acceptFile = computed(() =>
124
- typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
125
- )
126
-
127
- const acceptFileSizeKb = computed(() => props.maxSize)
128
- const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
129
- const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
130
-
131
- const selectedFileSizeKb = computed(() => ((selectedFile.value?.size || 0) / 1000).toFixed(2))
132
- const selectedFileSizeMb = computed(() =>
133
- ((selectedFile.value?.size || 0) / 1000 / 1000).toFixed(2)
134
- )
135
-
136
- const isSelectedFileUseMb = computed(() => (selectedFile.value?.size || 0) / 1000 > 1024)
137
-
138
- const onDrop = (files: File[] | null) => {
139
- if (props.isDisabled || files?.length === 0 || !files) return
140
-
141
- const file = files[0]
142
- const result = handleCheckFileCondition(file)
143
-
144
- if (result && file) {
145
- selectedFile.value = file
146
- const formData = new FormData()
147
-
148
- emits('change', file)
149
-
150
- formData.append(_get(props, props.bodyKey || 'file'), file)
151
- upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
152
- }
153
- }
154
-
155
- const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
156
- onDrop,
157
- })
158
-
159
- const handleChange = (e: Event) => {
160
- if (props.isDisabled) return
161
-
162
- const file = (e.target as HTMLInputElement).files?.[0]
163
- const result = handleCheckFileCondition(file)
164
-
165
- if (result && file) {
166
- selectedFile.value = file
167
- const formData = new FormData()
168
-
169
- emits('change', file)
170
-
171
- formData.append(props.bodyKey || 'file', file)
172
- upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
173
- }
174
- }
175
-
176
- const handleOpenFile = () => {
177
- fileInputRef.value?.click()
178
- }
179
-
180
- const handleDeleteFile = () => {
181
- fileInputRef.value?.value && (fileInputRef.value.value = '')
182
- selectedFile.value = undefined
183
- onChange(undefined)
184
- emits('delete')
185
- }
186
-
187
- const handleCheckFileCondition = (file: File | undefined): boolean => {
188
- if (!file) return false
189
-
190
- const fileType = checkFileType(file, acceptFile.value ?? '')
191
-
192
- if (!fileType) {
193
- setErrors(i18next.t('custom:invalid_file_type'))
194
-
195
- return false
196
- }
197
-
198
- const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
199
-
200
- if (!maxSize) {
201
- if (isAcceptFileUseMb.value) {
202
- setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
203
- } else {
204
- setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
205
- }
206
-
207
- return false
208
- }
209
-
210
- setErrors('')
211
-
212
- return true
213
- }
214
-
215
- const onUploadProgress = (progressEvent: ProgressEvent) => {
216
- percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.8
217
- }
218
-
219
- const onDownloadProgress = (progressEvent: ProgressEvent) => {
220
- if (progressEvent.total === 0) {
221
- percent.value = 100
222
-
223
- return
224
- }
225
-
226
- percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.2 + 80
227
- }
228
-
229
- useWatchTrue(
230
- () => upload.status.value.isSuccess,
231
- () => {
232
- value.value = _get(upload.data.value, props.responseKey || 'url')
233
- emits('success', upload.data.value)
234
- }
235
- )
236
-
237
- useWatchTrue(
238
- () => upload.status.value.isError,
239
- () => {
240
- setErrors(StringHelper.getError(upload.status.value.errorData))
241
- }
242
- )
243
- </script>
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,
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="acceptFile"
21
+ :disabled="isDisabled"
22
+ @change="handleChange"
23
+ />
24
+ <div :class="[ui.wrapper]">
25
+ <div v-if="!selectedFile" :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
54
+ ? `${fileAllocate.selectedFileSizeMb} MB`
55
+ : `${fileAllocate.selectedFileSizeKb} 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="selectedFile && upload.status.value.isSuccess" :class="[ui.onPreview.wrapper]">
71
+ <div :class="[ui.onPreview.previewImgWrapper]">
72
+ <div v-if="isImage(selectedFile)" class="size-full overflow-hidden">
73
+ <img
74
+ :src="upload.data.value[responseKey || 'url']"
75
+ :class="[ui.onPreview.previewImgClass]"
76
+ alt="image-preview"
77
+ />
78
+ </div>
79
+ <div v-else>
80
+ <Icon
81
+ :name="ui.onPreview.previewFileIcon || ui.default.filePreviewIcon"
82
+ :class="[ui.onPreview.previewFileClass]"
83
+ />
84
+ </div>
85
+ </div>
86
+ <div :class="[ui.onPreview.textWrapper]">
87
+ <div class="truncate">
88
+ <h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
89
+ <p class="truncate text-sm font-light text-gray-400">
90
+ {{
91
+ fileAllocate.isSelectedFileUseMb
92
+ ? `${fileAllocate.selectedFileSizeMb} MB`
93
+ : `${fileAllocate.selectedFileSizeKb} KB`
94
+ }}
95
+ </p>
96
+ </div>
97
+ <div :class="[ui.action.wrapper]">
98
+ <Icon
99
+ v-if="isImage(selectedFile)"
100
+ :name="ui.action.previewIcon"
101
+ :class="[ui.action.iconClass]"
102
+ title="ดูตัวอย่าง"
103
+ @click="() => (isPreviewOpen = true)"
104
+ />
105
+ <Icon
106
+ :name="ui.action.downloadIcon"
107
+ :class="[ui.action.iconClass]"
108
+ title="ดาวน์โหลดไฟล์"
109
+ @click="handleDownloadFile"
110
+ />
111
+ <Icon
112
+ :name="ui.action.deleteIcon"
113
+ :class="[ui.action.iconClass]"
114
+ title="ลบไฟล์"
115
+ @click="handleDeleteFile"
116
+ />
117
+ <Modal v-model="isPreviewOpen" :title="selectedFile?.name">
118
+ <img :src="upload.data.value[responseKey || 'url']" alt="image-preview" />
119
+ </Modal>
120
+ </div>
121
+ </div>
122
+ </div>
123
+
124
+ <!-- Failed State -->
125
+ <div v-if="selectedFile && upload.status.value.isError" :class="[ui.onFailed.wrapper]">
126
+ <div :class="[ui.onFailed.failedImgWrapper]">
127
+ <Icon
128
+ :name="
129
+ isImage(selectedFile)
130
+ ? ui.onFailed.failedImgIcon || ui.default.placeholderImgIcon
131
+ : ui.onFailed.failedFileIcon || ui.default.filePreviewIcon
132
+ "
133
+ :class="[ui.onFailed.failedIconClass]"
134
+ />
135
+ </div>
136
+ <div :class="[ui.onFailed.textWrapper]">
137
+ <div class="truncate">
138
+ <h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
139
+ <p class="text-danger truncate font-light">
140
+ {{ uploadFailedLabel || 'อัพโหลดล้มเหลว, กรุณาลองอีกครั้ง' }}
141
+ </p>
142
+ <Button
143
+ variant="ghost"
144
+ :label="retryLabel || 'ลองอีกครั้ง'"
145
+ :leading-icon="ui.action.retryIcon"
146
+ :class="[ui.action.retryBtnClass]"
147
+ size="sm"
148
+ @click="handleRetryUpload"
149
+ />
150
+ </div>
151
+ <div :class="[ui.action.wrapper]">
152
+ <Icon
153
+ title="ลบไฟล์"
154
+ :name="ui.action.deleteIcon"
155
+ :class="[ui.action.deleteIconClass]"
156
+ @click="handleDeleteFile"
157
+ />
158
+ </div>
159
+ </div>
160
+ </div>
161
+ </div>
162
+ </div>
163
+ </FieldWrapper>
164
+ </template>
165
+
166
+ <script lang="ts" setup>
167
+ import { useDropZone } from '@vueuse/core'
168
+ import { type IUploadDropzoneAutoProps } from './types'
169
+ import {
170
+ checkMaxSize,
171
+ checkFileType,
172
+ isImage,
173
+ getFileAllocate,
174
+ downloadFileFromURL,
175
+ } from '#core/helpers/componentHelper'
176
+ import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
177
+ import { useFieldHOC } from '#core/composables/useForm'
178
+ import {
179
+ type IUploadRequest,
180
+ computed,
181
+ ref,
182
+ toRef,
183
+ useUI,
184
+ useUiConfig,
185
+ useUploadLoader,
186
+ useWatchTrue,
187
+ StringHelper,
188
+ _get,
189
+ } from '#imports'
190
+ import { uploadFileDropzone } from '#core/ui.config'
191
+ import i18next from 'i18next'
192
+
193
+ const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
194
+
195
+ const props = withDefaults(defineProps<IUploadDropzoneAutoProps>(), {})
196
+ const emits = defineEmits(['change', 'success', 'delete'])
197
+
198
+ const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
199
+
200
+ const request: IUploadRequest = {
201
+ pathURL: props.uploadPathURL,
202
+ requestOptions: props.requestOptions,
203
+ }
204
+
205
+ const upload = useUploadLoader(request)
206
+
207
+ const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
208
+
209
+ const fileInputRef = ref<HTMLInputElement>()
210
+ const dropzoneRef = ref<HTMLDivElement>()
211
+ const selectedFile = ref<File | undefined>()
212
+ const percent = ref<number | string>(0)
213
+ const isPreviewOpen = ref<boolean>(false)
214
+
215
+ const acceptFile = computed(() =>
216
+ typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
217
+ )
218
+
219
+ const fileAllocate = computed(() =>
220
+ getFileAllocate(props.maxSize ?? 0, selectedFile.value?.size ?? 0)
221
+ )
222
+
223
+ const onDrop = (files: File[] | null) => {
224
+ if (props.isDisabled || files?.length === 0 || !files) return
225
+
226
+ const file = files[0]
227
+ const result = handleCheckFileCondition(file)
228
+
229
+ if (result && file) {
230
+ selectedFile.value = file
231
+ const formData = new FormData()
232
+
233
+ emits('change', file)
234
+
235
+ formData.append(_get(props, props.bodyKey || 'file'), file)
236
+ upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
237
+ }
238
+ }
239
+
240
+ const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
241
+ onDrop,
242
+ })
243
+
244
+ const handleChange = (e: Event) => {
245
+ if (props.isDisabled) return
246
+
247
+ const file = (e.target as HTMLInputElement).files?.[0]
248
+ const result = handleCheckFileCondition(file)
249
+
250
+ if (result && file) {
251
+ selectedFile.value = file
252
+ const formData = new FormData()
253
+
254
+ emits('change', file)
255
+
256
+ formData.append(props.bodyKey || 'file', file)
257
+ upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
258
+ }
259
+ }
260
+
261
+ const handleOpenFile = () => {
262
+ fileInputRef.value?.click()
263
+ }
264
+
265
+ const handleDeleteFile = () => {
266
+ fileInputRef.value?.value && (fileInputRef.value.value = '')
267
+ selectedFile.value = undefined
268
+ onChange(undefined)
269
+ emits('delete')
270
+ }
271
+
272
+ const handleCheckFileCondition = (file: File | undefined): boolean => {
273
+ if (!file) return false
274
+
275
+ const fileType = checkFileType(file, acceptFile.value ?? '')
276
+
277
+ if (!fileType) {
278
+ setErrors(i18next.t('custom:invalid_file_type'))
279
+
280
+ return false
281
+ }
282
+
283
+ const maxSize = checkMaxSize(file, fileAllocate.value.acceptFileSizeKb ?? 0)
284
+
285
+ if (!maxSize) {
286
+ if (fileAllocate.value.isAcceptFileUseMb) {
287
+ setErrors(
288
+ i18next.t('custom:invalid_file_size_mb', { size: fileAllocate.value.acceptFileSizeMb })
289
+ )
290
+ } else {
291
+ setErrors(
292
+ i18next.t('custom:invalid_file_size_kb', { size: fileAllocate.value.acceptFileSizeKb })
293
+ )
294
+ }
295
+
296
+ return false
297
+ }
298
+
299
+ setErrors('')
300
+
301
+ return true
302
+ }
303
+
304
+ const handleDownloadFile = () => {
305
+ downloadFileFromURL(_get(upload.data.value, props.responseKey || 'url'), selectedFile.value?.name)
306
+ }
307
+
308
+ const handleRetryUpload = () => {
309
+ if (selectedFile.value) {
310
+ const formData = new FormData()
311
+
312
+ formData.append(props.bodyKey || 'file', selectedFile.value)
313
+ upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
314
+ }
315
+ }
316
+
317
+ const onUploadProgress = (progressEvent: ProgressEvent) => {
318
+ percent.value = StringHelper.withFixed(
319
+ (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.8
320
+ )
321
+ }
322
+
323
+ const onDownloadProgress = (progressEvent: ProgressEvent) => {
324
+ if (progressEvent.total === 0) {
325
+ percent.value = 100
326
+
327
+ return
328
+ }
329
+
330
+ percent.value = StringHelper.withFixed(
331
+ (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.2 + 80
332
+ )
333
+ }
334
+
335
+ useWatchTrue(
336
+ () => upload.status.value.isSuccess,
337
+ () => {
338
+ value.value = _get(upload.data.value, props.responseKey || 'url')
339
+ emits('success', upload.data.value)
340
+ }
341
+ )
342
+
343
+ useWatchTrue(
344
+ () => upload.status.value.isError,
345
+ () => {
346
+ setErrors(StringHelper.getError(upload.status.value.errorData))
347
+ }
348
+ )
349
+ </script>
@@ -7,6 +7,9 @@ export interface IUploadDropzoneAutoProps extends IFieldProps {
7
7
  uploadPathURL?: string;
8
8
  selectFileLabel?: string;
9
9
  selectFileSubLabel?: string;
10
+ uploadingLabel?: string;
11
+ uploadFailedLabel?: string;
12
+ retryLabel?: string;
10
13
  accept?: string[] | string;
11
14
  bodyKey?: string;
12
15
  responseKey?: string;