fix(banners): save relative storage paths so admin preview survives refresh
Uploads were stored as host-specific URLs and a force-reload could wipe a just-saved image, leaving a broken dark-theme preview. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,7 +26,15 @@
|
||||
</a-upload>
|
||||
|
||||
<div v-else class="banner-image-upload__filled">
|
||||
<img :src="displayUrl" alt="" class="banner-image-upload__img" />
|
||||
<img
|
||||
:src="displayUrl"
|
||||
alt=""
|
||||
class="banner-image-upload__img"
|
||||
@error="onPreviewError"
|
||||
/>
|
||||
<div v-if="previewFailed" class="banner-image-upload__error">
|
||||
تصویر ذخیره شده ولی فایل روی سرور پیدا نشد
|
||||
</div>
|
||||
<div class="banner-image-upload__bar">
|
||||
<a-upload
|
||||
name="file"
|
||||
@@ -59,7 +67,7 @@ import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { uploadURL } from '@root/config'
|
||||
import { getToken } from '@/utils'
|
||||
import { normalizeUploadFileResponse, toAbsoluteFileUrl } from '@/utils/file'
|
||||
import { fileUrlCandidates, normalizeUploadFileResponse, toAbsoluteFileUrl } from '@/utils/file'
|
||||
import {
|
||||
createImageBeforeUpload,
|
||||
createImageCustomRequest
|
||||
@@ -75,7 +83,19 @@ const emit = defineEmits<{
|
||||
remove: []
|
||||
}>()
|
||||
|
||||
const displayUrl = computed(() => toAbsoluteFileUrl(props.imageUrl) ?? props.imageUrl ?? '')
|
||||
const previewFailed = ref(false)
|
||||
const candidateIndex = ref(0)
|
||||
|
||||
const candidates = computed(() => fileUrlCandidates(props.imageUrl))
|
||||
const displayUrl = computed(() => candidates.value[candidateIndex.value] ?? '')
|
||||
|
||||
watch(
|
||||
() => props.imageUrl,
|
||||
() => {
|
||||
previewFailed.value = false
|
||||
candidateIndex.value = 0
|
||||
},
|
||||
)
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
@@ -114,6 +134,14 @@ function onChange({ file }: { file: { status?: string } }) {
|
||||
loading.value = true
|
||||
}
|
||||
}
|
||||
|
||||
function onPreviewError() {
|
||||
if (candidateIndex.value < candidates.value.length - 1) {
|
||||
candidateIndex.value += 1
|
||||
return
|
||||
}
|
||||
previewFailed.value = true
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -209,6 +237,19 @@ function onChange({ file }: { file: { status?: string } }) {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.banner-image-upload__error {
|
||||
position: absolute;
|
||||
inset: 0 0 3.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0.75rem;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: 0.8125rem;
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.banner-image-upload__bar {
|
||||
position: absolute;
|
||||
inset: auto 0 0 0;
|
||||
|
||||
@@ -161,7 +161,7 @@ watch(
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
void load(true)
|
||||
void load()
|
||||
})
|
||||
|
||||
const typeList = ref([
|
||||
|
||||
Reference in New Issue
Block a user