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="{
|
||
3 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"
|
||
|
>
|
||
3 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)"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
name: 'DropOrSelectFile',
|
||
|
props: {
|
||
|
accept: String,
|
||
3 years ago
|
text: String,
|
||
3 years ago
|
},
|
||
|
data() {
|
||
|
return {
|
||
3 years ago
|
dragOver: false,
|
||
|
};
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
|
dropOrUpload: {
|
||
|
set(v) {
|
||
3 years ago
|
this.$emit('input', v);
|
||
3 years ago
|
},
|
||
|
get() {
|
||
3 years ago
|
return this.value;
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
|
_change(event) {
|
||
3 years ago
|
const files = event.target.files;
|
||
3 years ago
|
if (files && files[0]) {
|
||
3 years ago
|
this.$emit('file', files[0]);
|
||
|
event.target.value = '';
|
||
3 years ago
|
}
|
||
|
},
|
||
|
dropHandler(ev) {
|
||
3 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') {
|
||
3 years ago
|
file = ev.dataTransfer.items[0].getAsFile();
|
||
3 years ago
|
}
|
||
|
} else if (ev.dataTransfer.files.length) {
|
||
3 years ago
|
file = ev.dataTransfer.files[0];
|
||
3 years ago
|
}
|
||
|
|
||
|
if (this.accept && !this.accept.split(',').some(ext => file.name.endsWith(ext.trim()))) {
|
||
3 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) {
|
||
3 years ago
|
this.$emit('file', file);
|
||
3 years ago
|
}
|
||
|
},
|
||
|
dragOverHandler(ev) {
|
||
|
// Prevent default behavior (Prevent file from being opened)
|
||
3 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>
|