fix bug 4
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
<template v-else>
|
||||
<BaseIcon icon="vuesax-linear:gallery-add" size="40" class="index-image-uploader__icon" />
|
||||
<span class="index-image-uploader__cta">افزودن تصویر شاخص</span>
|
||||
<span class="index-image-uploader__hint">JPG، PNG یا WEBP — حداکثر ۲۰۰ کیلوبایت</span>
|
||||
<span class="index-image-uploader__hint">JPG، PNG یا WEBP — حداکثر ۱ مگابایت (تبدیل خودکار به WebP)</span>
|
||||
<span class="index-image-uploader__hint">نسبت مربعی برای نمایش بهتر توصیه میشود</span>
|
||||
</template>
|
||||
</div>
|
||||
@@ -84,13 +84,14 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { UploadChangeParam, UploadProps } from 'ant-design-vue'
|
||||
import { Upload, message } from 'ant-design-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||
import { usePrefix } from '@core/composable/usePrefix'
|
||||
import { uploadURL } from '@root/config'
|
||||
import { getToken } from '@/utils'
|
||||
import { fixFileCapture } from '@/utils/fixFileCapture'
|
||||
import { normalizeUploadFileResponse } from '@/utils/file'
|
||||
import { createWebpBeforeUpload } from '@/utils/prepareImageForUpload'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
const { prefixCls } = usePrefix('index-image-uploader')
|
||||
@@ -150,42 +151,38 @@ function removeImage() {
|
||||
}
|
||||
}
|
||||
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||
if (!file.size || file.size < 1) {
|
||||
message.error('فایل خالی است')
|
||||
return Upload.LIST_IGNORE
|
||||
}
|
||||
|
||||
const isLt200k = file.size / 1024 < 200
|
||||
if (!isLt200k) {
|
||||
message.error('حداکثر حجم بارگذاری ۲۰۰ کیلوبایت میباشد')
|
||||
return Upload.LIST_IGNORE
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
const beforeUpload: UploadProps['beforeUpload'] = createWebpBeforeUpload((msg) =>
|
||||
message.error(msg)
|
||||
)
|
||||
|
||||
function handleChange(info: UploadChangeParam) {
|
||||
fixFileCapture()
|
||||
|
||||
if (info.file.status === 'uploading') {
|
||||
const status = info.file.status
|
||||
|
||||
if (status === 'uploading') {
|
||||
loading.value = true
|
||||
return
|
||||
}
|
||||
|
||||
if (info.file.status === 'error') {
|
||||
loading.value = false
|
||||
// هر وضعیت غیر از uploading باید اسپینر را ببندد (error/done/removed/undefined)
|
||||
loading.value = false
|
||||
|
||||
if (status === 'error') {
|
||||
fileList.value = []
|
||||
message.error('خطا در بارگذاری')
|
||||
const serverMsg =
|
||||
(info.file.response as { message?: string } | undefined)?.message ||
|
||||
(info.file.error as { message?: string } | undefined)?.message
|
||||
message.error(serverMsg || 'خطا در بارگذاری تصویر')
|
||||
return
|
||||
}
|
||||
|
||||
if (info.file.status === 'done') {
|
||||
loading.value = false
|
||||
if (status === 'done') {
|
||||
const fileResource = normalizeUploadFileResponse(info.file.response)
|
||||
|
||||
if (!fileResource?.id || !fileResource.full_src) {
|
||||
fileList.value = []
|
||||
message.error('خطا در ساخت آدرس تصویر')
|
||||
message.error('آپلود انجام شد ولی آدرس تصویر ساخته نشد')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -200,8 +197,10 @@ function handleChange(info: UploadChangeParam) {
|
||||
]
|
||||
message.success('تصویر شاخص با موفقیت بارگذاری شد')
|
||||
emits('ok', fileResource.id, info.file.response)
|
||||
return
|
||||
}
|
||||
if (info.file.status === 'removed') {
|
||||
|
||||
if (status === 'removed') {
|
||||
emits('delete', info.file.uid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type {UploadChangeParam, UploadProps} from 'ant-design-vue'
|
||||
import {Upload, message} from 'ant-design-vue'
|
||||
import {message} from 'ant-design-vue'
|
||||
import {uploadURL} from '@root/config'
|
||||
import {getToken} from '@/utils'
|
||||
import {fixFileCapture} from '@/utils/fixFileCapture'
|
||||
import {normalizeUploadFileResponse} from '@/utils/file'
|
||||
import {createWebpBeforeUpload} from '@/utils/prepareImageForUpload'
|
||||
import {usePrefix} from '@core/composable/usePrefix'
|
||||
import {computed, onMounted, ref} from 'vue'
|
||||
|
||||
@@ -59,20 +60,9 @@ const fileList = computed({
|
||||
}
|
||||
})
|
||||
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||
if (!file.size || file.size < 1) {
|
||||
message.error('فایل خالی است')
|
||||
return Upload.LIST_IGNORE
|
||||
}
|
||||
|
||||
const isLt240k = file.size / 1024 < 240
|
||||
if (!isLt240k) {
|
||||
message.error('حداکثر حجم بارگذاری ۲۴۰ کیلوبایت میباشد')
|
||||
return Upload.LIST_IGNORE
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
const beforeUpload: UploadProps['beforeUpload'] = createWebpBeforeUpload((msg) =>
|
||||
message.error(msg)
|
||||
)
|
||||
|
||||
function handleChange(info: UploadChangeParam) {
|
||||
fixFileCapture()
|
||||
|
||||
Reference in New Issue
Block a user