-
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
6a62a29
commit 73a5dbf
Showing
6 changed files
with
124 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<AppCard @click="clickUpload" class="cursor-pointer !py-3"> | ||
<div class="flex flex-row items-center"> | ||
<div class="flex-1 flex flex-col"> | ||
<template v-if="modelFile"> | ||
<span>{{ modelFile.name }}</span> | ||
<span class="text-sm">{{ formatBytes(modelFile.size) }}</span> | ||
</template> | ||
<span v-else>Click to upload here</span> | ||
</div> | ||
<Button v-if="modelFile" icon="pi pi-times" text @click="(e) => { | ||
e.stopPropagation() | ||
model = undefined | ||
}" /> | ||
<Button v-else icon=" pi pi-upload" text /> | ||
</div> | ||
</AppCard> | ||
<input ref="fileRef" :modelValue="model" class="hidden" type="file" :accept="prop.accept" @change="(e) => { | ||
onChange(e) | ||
}"> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { formatBytes } from '#imports' | ||
defineOptions({ | ||
inheritAttrs: false, | ||
}) | ||
const fileRef = ref<HTMLInputElement>() | ||
const model = defineModel<FileList | undefined>() | ||
watchEffect(() => { | ||
if (!model.value && fileRef.value) { | ||
fileRef.value.value = '' | ||
} | ||
}) | ||
const modelFile = computed(() => model.value && model.value.length ? model.value.item(0) : undefined) | ||
const prop = defineProps<{ | ||
accept?: string, | ||
}>() | ||
function onChange(event: Event) { | ||
const inputEl = event.target as HTMLInputElement | ||
model.value = inputEl?.files || undefined | ||
emit('change', event) | ||
} | ||
const emit = defineEmits<{ | ||
(e: 'change', event: Event): void | ||
}>() | ||
function clickUpload() { | ||
fileRef.value?.click() | ||
} | ||
</script> |
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