CreateFileFormComponent.vue
1.99 KB
1
2
3
4
5
6
7
8
9
10
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template>
<div>
<v-btn
text
@click="$refs.fileInput.click()">
<v-icon>vertical_align_top</v-icon>
<span class="caption">업로드</span>
</v-btn>
<input
v-show="false"
type="file"
ref="fileInput"
multiple="multiple"
@change="uploadFile">
</div>
</template>
<script>
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import moment from 'moment';
export default {
name: "CreateFileFormComponent",
computed: {
currentFolder() {
return this.$store.state.file.currentFolder
}
},
methods: {
folderpath() {
return this.currentFolder.path;
},
changeFileSize(byteSize) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (byteSize === 0) return '-';
var i = parseInt(Math.floor(Math.log(byteSize) / Math.log(1024)));
return Math.round(byteSize / Math.pow(1024, i), 2) + ' ' + sizes[i];
},
async uploadFile(e) {
try {
const formData = new FormData();
var now = Date.now();
now = moment(now).format('YYYY-MM-DD');
Array.prototype.forEach.call(e.target.files, (file) => {
formData.append('file', file);
formData.append('name', file.name);
formData.append('isFolder', false);
formData.append('path', this.folderpath() + file.name);
formData.append('filesize', this.changeFileSize(file.size));
// formData.append('createdDate', now);
formData.append('modifiedDate', now);
formData.append('share', false);
formData.append('cid', this.currentFolder.id);
console.log(file);
console.log(this.changeFileSize(file.size))
});
await this.$store.dispatch('file/uploadFiles', {formData});
// return this.$router.replace('/');
} catch (e) {
console.error(e);
}
}
}
}
</script>
<style scoped>
</style>