|
2 | 2 | <v-row> |
3 | 3 | <v-col class="pa-0"> |
4 | 4 | <v-file-input |
5 | | - v-model="files" |
6 | | - :multiple="multiple" |
| 5 | + v-model="internal_files" |
| 6 | + :multiple="props.multiple" |
7 | 7 | :label="label" |
8 | | - :accept="accept" |
| 8 | + :accept="props.accept" |
9 | 9 | :rules="[(value) => !!value || 'The file is mandatory']" |
10 | 10 | color="primary" |
| 11 | + :hide-input="props.mini" |
| 12 | + :hide-details="props.mini" |
11 | 13 | chips |
12 | 14 | counter |
13 | 15 | show-size |
14 | 16 | @click:clear="clear()" |
15 | 17 | /> |
16 | 18 | </v-col> |
17 | 19 | </v-row> |
18 | | - <v-row> |
| 20 | + <v-row v-if="!props.auto_upload"> |
19 | 21 | <v-col cols="auto"> |
20 | 22 | <v-btn |
21 | 23 | color="primary" |
22 | | - :disabled="!files.length && !files_uploaded" |
| 24 | + :disabled="!internal_files.length && !files_uploaded" |
23 | 25 | :loading="loading" |
24 | 26 | class="pa-2" |
25 | 27 | @click="upload_files" |
|
41 | 43 | accept: { type: String, required: true }, |
42 | 44 | files: { type: Array, required: false, default: [] }, |
43 | 45 | auto_upload: { type: Boolean, required: false, default: false }, |
| 46 | + mini: { type: Boolean, required: false, default: false }, |
44 | 47 | }) |
45 | 48 |
|
46 | | - const { multiple, accept } = toRefs(props) |
47 | | -
|
48 | | - const label = multiple |
| 49 | + const label = props.multiple |
49 | 50 | ? "Please select file(s) to import" |
50 | 51 | : "Please select a file to import" |
51 | | - const files = ref([]) |
| 52 | + const internal_files = ref([]) |
52 | 53 | const loading = ref(false) |
53 | 54 | const files_uploaded = ref(false) |
54 | 55 |
|
|
57 | 58 | async function upload_files() { |
58 | 59 | toggle_loading() |
59 | 60 | var promise_array = [] |
60 | | - for (const file of files.value) { |
| 61 | + for (const file of internal_files.value) { |
61 | 62 | const promise = new Promise((resolve, reject) => { |
62 | 63 | upload_file( |
63 | 64 | { route: schema.$id, file }, |
|
78 | 79 | } |
79 | 80 | await Promise.all(promise_array) |
80 | 81 | files_uploaded.value = true |
81 | | - emit("files_uploaded", files.value) |
| 82 | + emit("files_uploaded", internal_files.value) |
82 | 83 | toggle_loading() |
83 | 84 | } |
84 | 85 |
|
85 | 86 | if (props.files.length) { |
86 | | - files.value = props.files |
| 87 | + internal_files.value = props.files |
87 | 88 | if (props.auto_upload) { |
88 | 89 | upload_files() |
89 | 90 | } |
90 | 91 | } |
91 | 92 |
|
92 | 93 | function clear() { |
93 | | - files.value = [] |
94 | | - emit("files_uploaded", files.value) |
| 94 | + internal_files.value = [] |
| 95 | + emit("files_uploaded", internal_files.value) |
95 | 96 | } |
96 | 97 |
|
97 | | - watch(files, () => { |
| 98 | + watch(internal_files, (value) => { |
98 | 99 | files_uploaded.value = false |
| 100 | + if (props.auto_upload) { |
| 101 | + if (props.multiple.value == false) { |
| 102 | + internal_files.value = [value] |
| 103 | + } |
| 104 | + upload_files() |
| 105 | + } |
99 | 106 | }) |
100 | 107 | </script> |
| 108 | + |
| 109 | +<style scoped> |
| 110 | + .div.v-input__details { |
| 111 | + display: none; |
| 112 | + } |
| 113 | +</style> |
0 commit comments