🐛 Fix(custom): fix cache issues in gallery image

ISSUES CLOSED: #288
This commit is contained in:
Kuingsmile 2025-02-27 16:47:07 +08:00
parent 58991e3704
commit 9a93314118
2 changed files with 38 additions and 3 deletions

View File

@ -142,7 +142,9 @@ export default [
action: IRPCActionType.REFRESH_SETTING_WINDOW, action: IRPCActionType.REFRESH_SETTING_WINDOW,
handler: async () => { handler: async () => {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)! const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
settingWindow.webContents.reloadIgnoringCache() settingWindow.webContents.session.clearCache().then(() => {
settingWindow.webContents.reloadIgnoringCache()
})
} }
} }
] ]

View File

@ -165,7 +165,7 @@
<el-col :span="22" :offset="1"> <el-col :span="22" :offset="1">
<el-row :gutter="16"> <el-row :gutter="16">
<photo-slider <photo-slider
:items="filterList" :items="filterListWithCacheBust"
:visible="gallerySliderControl.visible" :visible="gallerySliderControl.visible"
:index="gallerySliderControl.index" :index="gallerySliderControl.index"
:should-transition="true" :should-transition="true"
@ -186,7 +186,7 @@
<div class="gallery-list__item" @click="zoomImage(index)"> <div class="gallery-list__item" @click="zoomImage(index)">
<img <img
v-lazy="{ v-lazy="{
src: item.galleryPath || item.imgUrl src: addCacheBustParam(item.galleryPath) || addCacheBustParam(item.imgUrl)
}" }"
class="gallery-list__item-img" class="gallery-list__item-img"
/> />
@ -432,6 +432,39 @@ const filterList = computed(() => {
return res return res
}) })
const addCacheBustParam = (url: string | undefined) => {
if (!url) {
return ''
}
if (!(url.startsWith('http://') || url.startsWith('https://'))) {
return url
}
try {
const separator = url.includes('?') ? '&' : '?'
return `${url}${separator}cbplist=${new Date().getTime()}`
} catch (e) {
return url
}
}
const filterListWithCacheBust = computed(() => {
const newList = filterList.value.map(item => {
const newItem = { ...item }
if (newItem.imgUrl) {
newItem.imgUrl = addCacheBustParam(newItem.imgUrl)
}
if (newItem.galleryPath) {
newItem.galleryPath = addCacheBustParam(newItem.galleryPath)
}
newItem.src = addCacheBustParam(newItem.src || newItem.galleryPath || newItem.imgUrl || '')
return newItem
})
return newList
})
const isAllSelected = computed(() => { const isAllSelected = computed(() => {
return Object.values(choosedList).length > 0 && filterList.value.every(item => choosedList[item.id!]) return Object.values(choosedList).length > 0 && filterList.value.every(item => choosedList[item.id!])
}) })