-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0b9cb8
commit d208fdb
Showing
10 changed files
with
230 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<template> | ||
<n-button @click="showModal = true" round> {{ buttonText }} </n-button> | ||
<n-modal v-model:show="showModal"> | ||
<n-card | ||
style="width: 600px" | ||
:title="title" | ||
:bordered="false" | ||
size="huge" | ||
role="dialog" | ||
aria-modal="true" | ||
> | ||
<template #footer> | ||
<input type="file" ref="fileinput" @change="onChange" id="upload" /> | ||
<div | ||
id="drop_zone" | ||
@drop.prevent="onDrop" | ||
@dragover="onDragOver" | ||
@click="onDropClick" | ||
@dragstart.prevent.stop | ||
@dragend.prevent.stop | ||
@dragover.prevent.stop | ||
@drop.prevent.stop="onDrop" | ||
@mouseout="onMouseout" | ||
> | ||
<p>{{ $t("buttons.dragdrop") }}</p> | ||
</div> | ||
<n-button v-for="f in filesNames" :key="f" @click="deleteFile(f)" class="file-button" >{{ f }}</n-button> | ||
</template> | ||
<template #action> | ||
<span class="actions"> | ||
<n-button @click="onCancel"> {{ $t("buttons.cancel") }} </n-button> | ||
<n-button type="primary" @click="onOK"> {{ $t("buttons.ok") }} </n-button> | ||
</span> | ||
</template> | ||
</n-card> | ||
</n-modal> | ||
</template> | ||
|
||
<script lang="ts" setup > | ||
import { computed, defineEmits, defineProps, ref } from "vue"; | ||
const files = ref(new Map<string, string>()); | ||
const showModal = ref(false); | ||
const fileinput = ref<HTMLInputElement>(); | ||
const props = defineProps<{ | ||
title: string; | ||
buttonText: string; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(event: "ok", value: string[]): void; | ||
(event: "cancel"): void; | ||
}>(); | ||
const filesNames = computed(() => { | ||
return [...files.value.keys()]; | ||
}); | ||
function onChange(evt) { | ||
[...evt.target.files].forEach((file) => { | ||
readFile(file); | ||
}); | ||
} | ||
function onDropClick() { | ||
fileinput.value.click(); | ||
} | ||
function onDragOver(ev) { | ||
ev.target.classList.add("dragging"); | ||
} | ||
function onDrop(ev: DragEvent) { | ||
ev.preventDefault(); | ||
ev.target.classList.remove("dragging"); | ||
const fileList = ev.dataTransfer?.files; | ||
if (!fileList) return; | ||
[...fileList].forEach((item, i) => { | ||
readFile(item); | ||
}); | ||
} | ||
function onMouseout(ev){ | ||
ev.target.classList.remove("dragging"); | ||
} | ||
function deleteFile(filename: string) { | ||
files.value.delete(filename); | ||
} | ||
function readFile(file) { | ||
const fr = new FileReader(); | ||
fr.readAsText(file); | ||
fr.onloadend = function () { | ||
files.value.set(file.name, fr.result as string); | ||
}; | ||
} | ||
function onOK() { | ||
showModal.value = false; | ||
emit("ok", [...files.value.values()]); | ||
} | ||
function onCancel() { | ||
showModal.value = false; | ||
emit("cancel"); | ||
} | ||
</script> | ||
|
||
<style> | ||
#drop_zone { | ||
border: 2px dashed #ccc; | ||
border-radius: 20px; | ||
width: 480px; | ||
height: 180px; | ||
padding: 20px; | ||
text-align: center; | ||
font-size: 20px; | ||
cursor: pointer; | ||
} | ||
#drop_zone.dragging { | ||
border-color: #18a058; | ||
} | ||
#upload { | ||
display: none; | ||
} | ||
.actions { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
.file-button{ | ||
margin-top: 10px; | ||
margin-right: 10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters