Refactor image loading logic in VndbPanel.vue to enhance screenshot handling

- Updated the logic to locate screenshots using the alt attribute for better accuracy.
- Improved the condition to check if images are loaded and have valid dimensions before setting the screenshotsReady state.
This commit is contained in:
AdingApkgg
2025-12-26 15:28:15 +08:00
parent 2a030ea0f7
commit 7038145d09

View File

@@ -772,11 +772,13 @@ watch(() => searchStore.vndbInfo, async (newInfo) => {
nextTick(() => {
// 延迟一帧确保 DOM 已渲染
requestAnimationFrame(() => {
const vndbContent = document.querySelector('.vndb-content')
if (vndbContent) {
const firstScreenshot = vndbContent.querySelector('img[loading="lazy"]') as HTMLImageElement
if (firstScreenshot?.complete && firstScreenshot.naturalHeight > 0) {
// 查找截图区域的图片(通过 alt 属性特征定位)
const screenshotImgs = document.querySelectorAll('img[alt*="截图"]')
for (let i = 0; i < screenshotImgs.length; i++) {
const img = screenshotImgs[i] as HTMLImageElement
if (img.complete && img.naturalHeight > 0) {
screenshotsReady.value = true
break
}
}
})