fix bug
This commit is contained in:
@@ -33,14 +33,14 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { UploadChangeParam, UploadProps } from 'ant-design-vue'
|
import type { UploadChangeParam, UploadProps } from 'ant-design-vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { Upload, message } from 'ant-design-vue'
|
||||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||||
import { usePrefix } from '@core/composable/usePrefix'
|
import { usePrefix } from '@core/composable/usePrefix'
|
||||||
import { uploadURL } from '@root/config'
|
import { uploadURL } from '@root/config'
|
||||||
import { getToken } from '@/utils'
|
import { getToken } from '@/utils'
|
||||||
import { fixFileCapture } from '@/utils/fixFileCapture'
|
import { fixFileCapture } from '@/utils/fixFileCapture'
|
||||||
import { normalizeUploadFileResponse } from '@/utils/file'
|
import { normalizeUploadFileResponse } from '@/utils/file'
|
||||||
import { onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
const { prefixCls } = usePrefix('index-image-uploader')
|
const { prefixCls } = usePrefix('index-image-uploader')
|
||||||
const previewVisible = ref(false)
|
const previewVisible = ref(false)
|
||||||
@@ -85,12 +85,19 @@ const handleCancel = () => {
|
|||||||
previewTitle.value = ''
|
previewTitle.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const beforeUpload = (file: UploadProps['fileList'][number]) => {
|
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||||
const isLt100k = file.size / 1024 / 1024 < 0.2
|
if (!file.size || file.size < 1) {
|
||||||
if (!isLt100k) {
|
message.error('فایل خالی است')
|
||||||
message.error('حداکثر حجم بارگذاری 200 کیلو بایت میباشد')
|
return Upload.LIST_IGNORE
|
||||||
}
|
}
|
||||||
return isLt100k
|
|
||||||
|
const isLt200k = file.size / 1024 < 200
|
||||||
|
if (!isLt200k) {
|
||||||
|
message.error('حداکثر حجم بارگذاری ۲۰۰ کیلوبایت میباشد')
|
||||||
|
return Upload.LIST_IGNORE
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(info: UploadChangeParam) {
|
function handleChange(info: UploadChangeParam) {
|
||||||
|
|||||||
@@ -27,12 +27,13 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type {UploadChangeParam, UploadProps} from 'ant-design-vue'
|
import type {UploadChangeParam, UploadProps} from 'ant-design-vue'
|
||||||
|
import {Upload, message} from 'ant-design-vue'
|
||||||
import {uploadURL} from '@root/config'
|
import {uploadURL} from '@root/config'
|
||||||
import {getToken} from '@/utils'
|
import {getToken} from '@/utils'
|
||||||
import {fixFileCapture} from '@/utils/fixFileCapture'
|
import {fixFileCapture} from '@/utils/fixFileCapture'
|
||||||
|
import {normalizeUploadFileResponse} from '@/utils/file'
|
||||||
import {usePrefix} from '@core/composable/usePrefix'
|
import {usePrefix} from '@core/composable/usePrefix'
|
||||||
import {message} from 'ant-design-vue'
|
import {computed, onMounted, ref} from 'vue'
|
||||||
import {onMounted} from 'vue'
|
|
||||||
|
|
||||||
const {prefixCls} = usePrefix('product-image-uploader')
|
const {prefixCls} = usePrefix('product-image-uploader')
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
@@ -58,12 +59,19 @@ const fileList = computed({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const beforeUpload = (file: UploadProps['fileList'][number]) => {
|
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||||
const isLt100k = file.size / 1024 / 1024 < 0.24
|
if (!file.size || file.size < 1) {
|
||||||
if (!isLt100k) {
|
message.error('فایل خالی است')
|
||||||
message.error('حداکثر حجم بارگذاری 240 کیلو بایت میباشد')
|
return Upload.LIST_IGNORE
|
||||||
}
|
}
|
||||||
return isLt100k
|
|
||||||
|
const isLt240k = file.size / 1024 < 240
|
||||||
|
if (!isLt240k) {
|
||||||
|
message.error('حداکثر حجم بارگذاری ۲۴۰ کیلوبایت میباشد')
|
||||||
|
return Upload.LIST_IGNORE
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(info: UploadChangeParam) {
|
function handleChange(info: UploadChangeParam) {
|
||||||
@@ -81,8 +89,27 @@ function handleChange(info: UploadChangeParam) {
|
|||||||
|
|
||||||
if (info.file.status === 'done') {
|
if (info.file.status === 'done') {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
const fileResource = normalizeUploadFileResponse(info.file.response)
|
||||||
|
|
||||||
|
if (!fileResource?.id || !fileResource.full_src) {
|
||||||
|
fileList.value = fileList.value.filter((item) => item.uid !== info.file.uid)
|
||||||
|
message.error('خطا در ساخت آدرس تصویر')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fileList.value = fileList.value.map((item) =>
|
||||||
|
item.uid === info.file.uid
|
||||||
|
? {
|
||||||
|
...item,
|
||||||
|
uid: String(fileResource.id),
|
||||||
|
status: 'done',
|
||||||
|
url: fileResource.full_src,
|
||||||
|
thumbUrl: fileResource.full_src,
|
||||||
|
}
|
||||||
|
: item,
|
||||||
|
)
|
||||||
message.success('تصویر با موفقیت بارگذاری شد')
|
message.success('تصویر با موفقیت بارگذاری شد')
|
||||||
emits('ok', info.file.response.id)
|
emits('ok', fileResource.id, info.file.response)
|
||||||
}
|
}
|
||||||
if (info.file.status === 'removed') {
|
if (info.file.status === 'removed') {
|
||||||
emits('delete', info.file.uid)
|
emits('delete', info.file.uid)
|
||||||
|
|||||||
@@ -84,6 +84,18 @@ export function toAbsoluteFileUrl(path?: string | null): string | undefined {
|
|||||||
return trimmed
|
return trimmed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storageMatch = trimmed.match(/(?:^|\/)storage\/(.+)$/i)
|
||||||
|
if (storageMatch) {
|
||||||
|
const base = getFileBaseUrl()
|
||||||
|
if (base) {
|
||||||
|
return `${base}/storage/${storageMatch[1]}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/^[a-z0-9.-]+(?:\/server)?\/storage\//i.test(trimmed)) {
|
||||||
|
return `https://${trimmed.replace(/^\/+/, '')}`
|
||||||
|
}
|
||||||
|
|
||||||
const base = getFileBaseUrl()
|
const base = getFileBaseUrl()
|
||||||
if (!base) return undefined
|
if (!base) return undefined
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user