mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.4 KiB
98 lines
2.4 KiB
3 years ago
|
<template>
|
||
|
<div class="pa-4">
|
||
|
<div
|
||
|
class="nc-droppable d-flex align-center justify-center flex-column"
|
||
|
:style="{
|
||
2 years ago
|
background: dragOver ? '#7774' : '',
|
||
3 years ago
|
}"
|
||
|
@click="$refs.file.click()"
|
||
|
@drop.prevent="dropHandler"
|
||
|
@dragover.prevent="dragOver = true"
|
||
|
@dragenter.prevent="dragOver = true"
|
||
|
@dragexit="dragOver = false"
|
||
|
@dragleave="dragOver = false"
|
||
|
@dragend="dragOver = false"
|
||
|
>
|
||
2 years ago
|
<v-icon size="50" color="grey"> mdi-file-plus-outline </v-icon>
|
||
|
<p class="title grey--text mb-1 mt-2">Select {{ text }} file to Upload</p>
|
||
|
<p class="grey--text">or drag and drop {{ text }} file</p>
|
||
3 years ago
|
</div>
|
||
|
<input
|
||
|
ref="file"
|
||
|
class="nc-excel-import-input"
|
||
|
type="file"
|
||
|
style="display: none"
|
||
|
:accept="accept"
|
||
|
@change="_change($event)"
|
||
2 years ago
|
/>
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
name: 'DropOrSelectFile',
|
||
|
props: {
|
||
|
accept: String,
|
||
2 years ago
|
text: String,
|
||
3 years ago
|
},
|
||
|
data() {
|
||
|
return {
|
||
2 years ago
|
dragOver: false,
|
||
|
};
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
|
dropOrUpload: {
|
||
|
set(v) {
|
||
2 years ago
|
this.$emit('input', v);
|
||
3 years ago
|
},
|
||
|
get() {
|
||
2 years ago
|
return this.value;
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
|
_change(event) {
|
||
2 years ago
|
const files = event.target.files;
|
||
3 years ago
|
if (files && files[0]) {
|
||
2 years ago
|
this.$emit('file', files[0]);
|
||
|
event.target.value = '';
|
||
3 years ago
|
}
|
||
|
},
|
||
|
dropHandler(ev) {
|
||
2 years ago
|
this.dragOver = false;
|
||
|
let file;
|
||
3 years ago
|
if (ev.dataTransfer.items) {
|
||
|
// Use DataTransferItemList interface to access the file(s)
|
||
|
if (ev.dataTransfer.items.length && ev.dataTransfer.items[0].kind === 'file') {
|
||
2 years ago
|
file = ev.dataTransfer.items[0].getAsFile();
|
||
3 years ago
|
}
|
||
|
} else if (ev.dataTransfer.files.length) {
|
||
2 years ago
|
file = ev.dataTransfer.files[0];
|
||
3 years ago
|
}
|
||
|
|
||
|
if (this.accept && !this.accept.split(',').some(ext => file.name.endsWith(ext.trim()))) {
|
||
2 years ago
|
return this.$toast
|
||
|
.error(`Dropped file is not an accepted file type. The accepted file types are ${this.accept}!`)
|
||
|
.goAway(3000);
|
||
3 years ago
|
}
|
||
|
if (file) {
|
||
2 years ago
|
this.$emit('file', file);
|
||
3 years ago
|
}
|
||
|
},
|
||
|
dragOverHandler(ev) {
|
||
|
// Prevent default behavior (Prevent file from being opened)
|
||
2 years ago
|
ev.preventDefault();
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.nc-droppable {
|
||
|
width: 100%;
|
||
|
min-height: 200px;
|
||
|
border-radius: 4px;
|
||
|
border: 2px dashed var(--v-textColor-lighten5);
|
||
|
}
|
||
|
</style>
|