Insert image for product
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
list-type="picture-card"
|
||||
:showUploadList="true"
|
||||
:multiple="false"
|
||||
:max-count="1"
|
||||
:action="uploadURL"
|
||||
:capture="undefined"
|
||||
:headers="fileHeader"
|
||||
@@ -37,6 +38,7 @@ import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||
import { usePrefix } from '@core/composable/usePrefix'
|
||||
import { uploadURL } from '@root/config'
|
||||
import { getToken } from '@/utils'
|
||||
import { normalizeUploadFileResponse } from '@/utils/file'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const { prefixCls } = usePrefix('index-image-uploader')
|
||||
@@ -55,7 +57,11 @@ interface Props {
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {})
|
||||
|
||||
const emits = defineEmits(['update:fileList', 'ok', 'delete'])
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:fileList', value: UploadProps['fileList']): void
|
||||
(e: 'ok', id: number, response?: Record<string, any>): void
|
||||
(e: 'delete', uid: string): void
|
||||
}>()
|
||||
|
||||
const fileList = computed({
|
||||
get() {
|
||||
@@ -67,9 +73,10 @@ const fileList = computed({
|
||||
})
|
||||
|
||||
const handlePreview = async (file: UploadProps['fileList'][number]) => {
|
||||
previewImage.value = file.src
|
||||
previewImage.value = file.url || file.thumbUrl || file.src
|
||||
previewVisible.value = true
|
||||
previewTitle.value = file.name || file.url.substring(file.url.lastIndexOf('/') + 1)
|
||||
previewTitle.value =
|
||||
file.name || (file.url ? file.url.substring(file.url.lastIndexOf('/') + 1) : 'image')
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
@@ -99,8 +106,25 @@ function handleChange(info: UploadChangeParam) {
|
||||
|
||||
if (info.file.status === 'done') {
|
||||
loading.value = false
|
||||
const fileResource = normalizeUploadFileResponse(info.file.response)
|
||||
|
||||
if (!fileResource?.id || !fileResource.full_src) {
|
||||
fileList.value = []
|
||||
message.error('خطا در ساخت آدرس تصویر')
|
||||
return
|
||||
}
|
||||
|
||||
fileList.value = [
|
||||
{
|
||||
...info.file,
|
||||
uid: String(fileResource.id),
|
||||
status: 'done',
|
||||
url: fileResource.full_src,
|
||||
thumbUrl: fileResource.full_src
|
||||
}
|
||||
]
|
||||
message.success('تصویر شاخص با موفقیت بارگذاری شد')
|
||||
emits('ok', info.file.response.id)
|
||||
emits('ok', fileResource.id, info.file.response)
|
||||
}
|
||||
if (info.file.status === 'removed') {
|
||||
emits('delete', info.file.uid)
|
||||
|
||||
Reference in New Issue
Block a user