feat: emit event when in headless mode

This commit is contained in:
Methapon2001 2024-08-08 09:45:59 +07:00
parent d9f6e1423a
commit ac1e8f71e9

View file

@ -1,4 +1,5 @@
<script lang="ts" setup>
import { ref } from 'vue';
import AppBox from './app/AppBox.vue';
defineExpose({ browse });
@ -8,7 +9,7 @@ defineProps<{
hiddenFooter?: boolean;
defaultUrl?: string;
}>();
defineEmits<{
const emit = defineEmits<{
(e: 'save', file: File | null, url: string | null): void;
}>();
@ -36,6 +37,7 @@ const inputFile = (() => {
_element.addEventListener('change', change);
return _element;
})();
const headless = ref(false);
reader.addEventListener('load', () => {
if (typeof reader.result === 'string') imageUrl.value = reader.result;
@ -43,6 +45,7 @@ reader.addEventListener('load', () => {
function browse() {
inputFile?.click();
headless.value = true;
}
function change(e: Event) {
@ -52,7 +55,10 @@ function change(e: Event) {
if (_file) {
file.value = _file;
reader.readAsDataURL(_file);
if (headless) emit('save', _file, imageUrl.value);
}
headless.value = false;
}
</script>
<template>