@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.
- package/README.md +63 -63
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -2
- package/dist/runtime/components/Alert.vue +48 -48
- package/dist/runtime/components/Avatar.vue +27 -27
- package/dist/runtime/components/Badge.vue +53 -53
- package/dist/runtime/components/Breadcrumb.vue +44 -44
- package/dist/runtime/components/Button/Group.vue +37 -37
- package/dist/runtime/components/Button/index.vue +76 -76
- package/dist/runtime/components/Card.vue +38 -38
- package/dist/runtime/components/Core.vue +13 -13
- package/dist/runtime/components/Dialog/index.vue +108 -108
- package/dist/runtime/components/Dropdown/index.vue +70 -70
- package/dist/runtime/components/FlexDeck/Base.vue +90 -90
- package/dist/runtime/components/FlexDeck/index.vue +66 -66
- package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
- package/dist/runtime/components/Form/Fields.vue +160 -160
- package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
- package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
- package/dist/runtime/components/Form/InputNumber/index.vue +27 -27
- package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
- package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
- package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
- package/dist/runtime/components/Form/InputText/index.vue +67 -67
- package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
- package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
- package/dist/runtime/components/Form/InputUploadDropzone/index.vue +213 -158
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +349 -243
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +3 -0
- package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +101 -101
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +174 -174
- package/dist/runtime/components/Form/index.vue +6 -6
- package/dist/runtime/components/Icon.vue +23 -23
- package/dist/runtime/components/Image.vue +36 -36
- package/dist/runtime/components/Loader.vue +27 -27
- package/dist/runtime/components/Modal/index.vue +146 -146
- package/dist/runtime/components/SimplePagination.vue +96 -96
- package/dist/runtime/components/Slideover/index.vue +110 -110
- package/dist/runtime/components/Table/Base.vue +139 -139
- package/dist/runtime/components/Table/ColumnDate.vue +16 -16
- package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
- package/dist/runtime/components/Table/ColumnImage.vue +15 -15
- package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
- package/dist/runtime/components/Table/ColumnText.vue +25 -25
- package/dist/runtime/components/Table/Simple.vue +69 -69
- package/dist/runtime/components/Table/index.vue +65 -65
- package/dist/runtime/components/Tabs/index.vue +64 -64
- package/dist/runtime/helpers/componentHelper.d.ts +9 -0
- package/dist/runtime/helpers/componentHelper.mjs +30 -0
- package/dist/runtime/ui.config/uploadFileDropzone.d.ts +36 -13
- package/dist/runtime/ui.config/uploadFileDropzone.mjs +42 -19
- package/dist/runtime/utils/StringHelper.d.ts +1 -0
- package/dist/runtime/utils/StringHelper.mjs +6 -0
- 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<div>
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
emits('
|
|
234
|
-
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
)
|
|
243
|
-
|
|
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;
|