|
@@ -1,85 +1,95 @@
|
|
|
<template>
|
|
|
- <div class="uploader">
|
|
|
- <div class="add-item-icon scene-sign" v-if="avatarImage">
|
|
|
- <a-image class="avatar" :src="avatarImage" alt="avatar" />
|
|
|
- <span class="delete-scene" @click="deleteAvatar">
|
|
|
+ <a-upload
|
|
|
+ v-model:file-list="avatarFile"
|
|
|
+ name="file"
|
|
|
+ accept=".png,.jpg,.jpeg"
|
|
|
+ :show-upload-list="false"
|
|
|
+ :action="baseURL + '/takelook/upload/file'"
|
|
|
+ :max-count="1"
|
|
|
+ class="uploader"
|
|
|
+ :headers="{
|
|
|
+ authorization: 'authorization-text'
|
|
|
+ }"
|
|
|
+ :disabled="avatarFile.length > 0"
|
|
|
+ @change="handleAvatarChange"
|
|
|
+ :before-upload="handleAvatarBeforeUpload"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ class="add-item-icon scene-sign"
|
|
|
+ v-if="avatarFile.length > 0 && avatarFile[0].response"
|
|
|
+ >
|
|
|
+ <a-image class="avatar" :src="avatarFile[0].response.data" alt="avatar" />
|
|
|
+ <span class="delete-scene" @click="deleteAvatar(avatarFile[0])">
|
|
|
<close-outlined class="delete-scene-icon" />
|
|
|
</span>
|
|
|
</div>
|
|
|
<div class="add-item-icon" v-else>
|
|
|
- <a-button
|
|
|
- shape="circle"
|
|
|
- class="button"
|
|
|
- type="primary"
|
|
|
- @click="showAvatarUploader"
|
|
|
- >
|
|
|
+ <a-button shape="circle" class="button" type="primary">
|
|
|
<plus-outlined class="add-room-icon" />
|
|
|
</a-button>
|
|
|
</div>
|
|
|
-
|
|
|
- <my-upload
|
|
|
- field="file"
|
|
|
- name="file"
|
|
|
- img-format=".png,.jpg,.jpeg"
|
|
|
- :url="baseURL + '/takelook/upload/file'"
|
|
|
- :headers="{
|
|
|
- authorization: 'authorization-text'
|
|
|
- }"
|
|
|
- :disabled="file.length > 0"
|
|
|
- :lang-type="getLocale"
|
|
|
- v-model="isShowAvatarModel"
|
|
|
- @crop-upload-success="handleAvatarUpload"
|
|
|
- @crop-success="cropSuccess"
|
|
|
- >
|
|
|
- </my-upload>
|
|
|
- </div>
|
|
|
+ </a-upload>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
import { ref } from 'vue'
|
|
|
+import { message, type UploadChangeParam } from 'ant-design-vue'
|
|
|
+import type { FileItem } from './album-list.vue'
|
|
|
import { baseURL } from '@/env'
|
|
|
import { watchEffect } from 'vue'
|
|
|
-import myUpload from 'vue-image-crop-upload'
|
|
|
import { useI18n } from '@/hook/useI18n'
|
|
|
-import { useLocale } from '@/locales/useLocale'
|
|
|
-
|
|
|
const emit = defineEmits(['sync'])
|
|
|
-const file = ref<any[]>([])
|
|
|
-const avatarImage = ref('')
|
|
|
+const avatarFile = ref<any[]>([])
|
|
|
const props = defineProps<{ value: string | undefined }>()
|
|
|
const { t } = useI18n()
|
|
|
-const isShowAvatarModel = ref(false)
|
|
|
-const { getLocale } = useLocale()
|
|
|
|
|
|
watchEffect(() => {
|
|
|
if (props.value?.length) {
|
|
|
- debugger
|
|
|
+ const tempData = {} as FileItem
|
|
|
+ tempData.uid = `data-0`
|
|
|
+ tempData.response = {
|
|
|
+ data: props.value,
|
|
|
+ ok: 0
|
|
|
+ }
|
|
|
+ if (!avatarFile.value?.length) {
|
|
|
+ console.log('mapper', tempData)
|
|
|
+ avatarFile.value = [tempData]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ avatarFile.value = []
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-const handleAvatarUpload = (res: any) => {
|
|
|
- const { data } = res
|
|
|
- console.log('avatarImage', data)
|
|
|
- avatarImage.value = data
|
|
|
- // setTimeout(() => {
|
|
|
- // isShowAvatarModel.value = false
|
|
|
- // }, 1500)
|
|
|
-}
|
|
|
-const cropSuccess = (res: any) => {
|
|
|
-
|
|
|
-}
|
|
|
-const cropUploadFail = (res: any) => {
|
|
|
- console.log('cropUploadFail', res)
|
|
|
+const handleAvatarChange = (info: UploadChangeParam) => {
|
|
|
+ if (info.file.status === 'done') {
|
|
|
+ const { code, data } = info.file.response
|
|
|
+ if (code === 0) {
|
|
|
+ emit('sync', data || '')
|
|
|
+ }
|
|
|
+ } else if (info.file.status === 'error') {
|
|
|
+ message.error(`${info.file.name} file upload failed.`)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-const showAvatarUploader = () => {
|
|
|
- isShowAvatarModel.value = true
|
|
|
- console.log('show')
|
|
|
+const deleteAvatar = (item: any) => {
|
|
|
+ const index = avatarFile.value.findIndex(i => i.uid === item.uid)
|
|
|
+ if (index > -1) {
|
|
|
+ avatarFile.value.splice(index, 1)
|
|
|
+ }
|
|
|
+ emit('sync', '')
|
|
|
}
|
|
|
-const deleteAvatar = () => {
|
|
|
- avatarImage.value = ''
|
|
|
+const handleAvatarBeforeUpload = (file: File) => {
|
|
|
+ const max = file.size / 1024 / 1024 <= 1
|
|
|
+ if (!max) {
|
|
|
+ message.error(t('room.oneMPicLimit'))
|
|
|
+ // debugger;
|
|
|
+ setTimeout(() => {
|
|
|
+ avatarFile.value = []
|
|
|
+ }, 50)
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
-<style lang="scss"></style>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.add-item-icon {
|
|
@@ -171,15 +181,4 @@ const deleteAvatar = () => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// .vue-image-crop-upload {
|
|
|
-// .vicp-wrap .vicp-operate {
|
|
|
-// color: #0076f6 !important;
|
|
|
-// }
|
|
|
-// }
|
|
|
-</style>
|
|
|
-<style>
|
|
|
-.vue-image-crop-upload .vicp-wrap .vicp-operate a {
|
|
|
- color: #0076f6;
|
|
|
-}
|
|
|
</style>
|