image handling fixes
This commit is contained in:
parent
7aa2ff1d3a
commit
54d814f9b2
2 changed files with 32 additions and 31 deletions
|
|
@ -7,8 +7,10 @@ let refreshPromise = null
|
||||||
|
|
||||||
function createConfig(options = {}) {
|
function createConfig(options = {}) {
|
||||||
const token = localStorage.getItem('accessToken');
|
const token = localStorage.getItem('accessToken');
|
||||||
|
const isFormData = options.body instanceof FormData;
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
...(isFormData ? {} : { 'Content-Type': 'application/json' }),
|
||||||
...options.headers,
|
...options.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,37 +54,21 @@ function onFileInputChange(event) {
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpload({ fileList: newFileList }) {
|
async function fetchImage(bustCache = false) {
|
||||||
const file = newFileList[newFileList.length - 1]
|
|
||||||
try {
|
try {
|
||||||
await uploadImage(props.merchUuid, file.file)
|
let imgUrl = getImageUrl(props.merchUuid, 'full')
|
||||||
|
|
||||||
const { imgUrl } = await getImageUrl(props.merchUuid, 'full')
|
if (bustCache) {
|
||||||
|
const separator = imgUrl.includes('?') ? '&' : '?'
|
||||||
message.success('Image uploaded successfully.')
|
imgUrl += `${separator}_t=${Date.now()}`
|
||||||
|
}
|
||||||
fileList.value = [
|
|
||||||
{
|
|
||||||
name: file.name,
|
|
||||||
url: imgUrl,
|
|
||||||
status: 'finished',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
} catch (error) {
|
|
||||||
message.error('Upload error: ' + (error.message || 'Unknown error.'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
try {
|
|
||||||
const imgUrl = getImageUrl(props.merchUuid, 'full');
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const img = new Image();
|
const img = new Image()
|
||||||
img.src = imgUrl;
|
img.src = imgUrl
|
||||||
img.onload = () => resolve(imgUrl);
|
img.onload = () => resolve(imgUrl)
|
||||||
img.onerror = () => reject(new Error('Image not found'));
|
img.onerror = () => reject(new Error('Image not found'))
|
||||||
});
|
})
|
||||||
|
|
||||||
fileList.value = [
|
fileList.value = [
|
||||||
{
|
{
|
||||||
|
|
@ -92,13 +76,28 @@ onMounted(async () => {
|
||||||
url: imgUrl,
|
url: imgUrl,
|
||||||
status: 'finished',
|
status: 'finished',
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fileList.value = [];
|
fileList.value = []
|
||||||
if (!error.message.includes('404')) {
|
if (!error.message.includes('404')) {
|
||||||
console.error('Error getting image: ', error);
|
console.error('Error getting image:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUpload({ fileList: newFileList }) {
|
||||||
|
const file = newFileList[newFileList.length - 1]
|
||||||
|
try {
|
||||||
|
await uploadImage(props.merchUuid, file.file)
|
||||||
|
message.success('Image uploaded successfully.')
|
||||||
|
await fetchImage(true)
|
||||||
|
} catch (error) {
|
||||||
|
message.error('Upload error: ' + (error.message || 'Unknown error.'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await fetchImage(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
const showConfirmDelete = ref(false)
|
const showConfirmDelete = ref(false)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue