|
|
@@ -0,0 +1,58 @@
|
|
|
+<script setup lang='ts'>
|
|
|
+import {toRefs} from 'vue';
|
|
|
+import placeholder from '@assets/images/register/imgPlaceholder.webp';
|
|
|
+import {useI18n} from 'vue-i18n';
|
|
|
+import {useDropFile, useUpload} from './hooks';
|
|
|
+import {useField} from 'vee-validate';
|
|
|
+import {ElImage} from 'element-plus';
|
|
|
+
|
|
|
+defineOptions({name: 'LoginUpload'});
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ title: string;
|
|
|
+ name: string;
|
|
|
+};
|
|
|
+const props = defineProps<Props>();
|
|
|
+const {title, name} = toRefs(props);
|
|
|
+
|
|
|
+const {t} = useI18n();
|
|
|
+
|
|
|
+const {value, setValue, errorMessage} = useField<string>(name);
|
|
|
+const [{uploadRef}, {onUpload, onUploadClick}] = useUpload(setValue);
|
|
|
+const {zoneRef, isOverDropZone} = useDropFile(onUpload);
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <div
|
|
|
+ ref="zoneRef"
|
|
|
+ :class="['upload-wrapper', {'drop-active': isOverDropZone}]"
|
|
|
+ >
|
|
|
+ <p class="title">{{title}}</p>
|
|
|
+ <ElImage
|
|
|
+ fit="cover"
|
|
|
+ :src="value ? value : placeholder"
|
|
|
+ :class="[
|
|
|
+ 'placeholder',
|
|
|
+ {'preview-img': !!value}
|
|
|
+ ]"
|
|
|
+ :preview-src-list="value ? [value] : void 0"
|
|
|
+/>
|
|
|
+ <p class="drap-tip">
|
|
|
+ {{t('register.uploadTip')}}<span @click="onUploadClick">
|
|
|
+ {{t('register.upload')}}
|
|
|
+ </span>
|
|
|
+ </p>
|
|
|
+ <p
|
|
|
+ v-show="!value"
|
|
|
+ :class="['max-size-tip', {'upload-error-tip': !!errorMessage}]"
|
|
|
+ >
|
|
|
+ {{t(errorMessage || 'register.maxSizeTip')}}
|
|
|
+ </p>
|
|
|
+
|
|
|
+ <input v-show="false" ref="uploadRef" type="file" accept="image/*" />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped lang='css'>
|
|
|
+@import './index.css';
|
|
|
+</style>
|