1
1
<template >
2
- <input type =" file" name =" fileInput" id =" fileInput" @change =" uploadFile() " ref =" fileInput" :multiple =" multiple" ><br >
2
+ <input type =" file" name =" fileInput" id =" fileInput" @change =" uploadFile" ref =" fileInput" :multiple =" multiple" ><br >
3
3
<progress ref =" progressBar" style =" width : 100% " :value =" imagesProgress" max =" 100" ></progress >
4
4
</template >
5
5
@@ -16,18 +16,22 @@ export default {
16
16
props: [' onUpload-success' , ' onUpload-error' , ' purpose' ],
17
17
setup (props , { emit }) { // , { emit }) {
18
18
/* View Methods */
19
- const uploadFile = () => {
20
- for (var i = 0 ; i < v .fileInput .files .length ; i++ ) {
21
- var file = v .fileInput .files [i]
19
+ const uploadFile = (e ) => {
20
+ emit (' upload-error' , null ) // clear previous errors
21
+
22
+ let files = e .target .files || e .dataTransfer .files
23
+ let images = []
24
+ for (var i = 0 ; i < files .length ; i++ ) {
25
+ let file = files[i]
22
26
if (! file .type .match (/ image. * / )) continue
23
- v . images .push (file)
27
+ images .push (file)
24
28
}
25
29
console .log (props .purpose )
26
- if (props .purpose === ' avatar' || props .purpose === ' logo' || props .purpose === ' favicon' ) { v . images = [v . images [0 ]] }
30
+ if (props .purpose === ' avatar' || props .purpose === ' logo' || props .purpose === ' favicon' ) { images = [images[0 ]] }
27
31
28
- console .log (v . images )
32
+ console .log (images)
29
33
30
- if (v . images .length > 0 ) {
34
+ if (images .length > 0 ) {
31
35
// if (v.fileInput.files.length > 10) {
32
36
// return $timeout(function() { Alert.error('Error: Exceeded 10 images.'); });
33
37
// }
@@ -49,7 +53,7 @@ export default {
49
53
* url: {string} The url where the image is hosted (upon upload completion)
50
54
*/
51
55
// prep each image
52
- v . images .forEach (fsImage => {
56
+ images .forEach (fsImage => {
53
57
let image = {
54
58
name: fsImage .name ,
55
59
file: fsImage,
@@ -103,25 +107,27 @@ export default {
103
107
if (err .status === 429 ) { message += ' Exceeded 10 images in batch upload.' }
104
108
else { message += ' Error: ' + err .message }
105
109
// Alert.error(message);
106
- emit (' upload-error' , message)
107
-
110
+ handleError (message)
108
111
}))
109
112
.finally (() => index++ )
110
113
})
111
114
.then (function () {
112
115
// log error images after all uploads finish
113
116
if (errImages .length ) {
114
- emit ( ' upload-error ' , v .warningMsg )
117
+ handleError ( v .warningMsg )
115
118
// TODO(akinsey) return $timeout(function() { Alert.warning(warningMsg); })
116
119
}
117
120
})
118
121
})
119
- .catch (() => {
120
- emit (' upload-error' , v .warningMsg )
121
- })
122
+ .catch (() => handleError (v .warningMsg ))
122
123
}
123
124
}
124
125
126
+ const handleError = msg => {
127
+ v .currentImages = []
128
+ emit (' upload-error' , msg)
129
+ }
130
+
125
131
// update loading status
126
132
function updateImagesUploading (index , percent , url ) {
127
133
// on successful update
0 commit comments