You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaweb/components/uploader.vue

42 lines
902 B
Vue

<template>
<div @click="click">
<input enctype="multipart/form-data" ref="file" name="files" :multiple="multiple" type="file" hidden @change="upload">
<slot></slot>
</div>
</template>
<script lang="ts" setup>
import { oafs } from '@veypi/oaer'
let file = ref<HTMLInputElement>()
let emits = defineEmits<{
(e: 'success', v: string): void
(e: 'failed'): void
}>()
let props = withDefaults(defineProps<{
multiple?: boolean,
renames?: string,
dir?: string,
}>(), {
multiple: false,
renames: ''
})
function click() {
file.value?.dispatchEvent(new MouseEvent('click'))
}
const upload = (evt: Event) => {
evt.preventDefault()
let f = (evt.target as HTMLInputElement).files as FileList
oafs.upload(f, props.dir, props.renames?.split(/[, ]+/)).then((e: any) => {
console.log(e)
emits('success', props.multiple ? e : e[0])
})
}
</script>
<style scoped></style>