列表页增加图片自动下载到本地
This commit is contained in:
parent
86635c26c4
commit
f8a1c82394
@ -287,12 +287,13 @@ import { usePageTypeSlug } from '@/shared/utils/slug'
|
||||
import { isSinglePageType } from '@/shared/utils/pagetype'
|
||||
import SinglePageDetail from './SinglePageDetail.vue'
|
||||
import FilterBar from '@/core/components/FilterBar.vue'
|
||||
import {
|
||||
resolvePagetypeListOverride,
|
||||
import {
|
||||
resolvePagetypeListOverride,
|
||||
resolvePagetypeListToolbarOverride,
|
||||
resolvePagetypeListFilterBarOverride,
|
||||
resolvePagetypeListActionsOverride
|
||||
} from '@/core/registry/pagetypeOverride'
|
||||
import { downloadImageToLocal } from '@/shared/api/common'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@ -455,6 +456,26 @@ function handleCardImageLoad(_event: Event, rowName: string) {
|
||||
cardImageLoadErrors.value.delete(rowName)
|
||||
}
|
||||
|
||||
// 自动下载图片的函数(与详情页一致)
|
||||
async function autoDownloadImages(imageUrls: string[]) {
|
||||
const downloadPromises = imageUrls.map(async (url) => {
|
||||
const filename = url.split('/').pop() || 'image.jpg'
|
||||
|
||||
try {
|
||||
const result = await downloadImageToLocal(url, filename)
|
||||
if (result.success) {
|
||||
// 返回是否是新下载的图片(非缓存)
|
||||
return !(result as any).data?.cached
|
||||
}
|
||||
} catch (error) {
|
||||
// 静默失败,不影响界面
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
await Promise.all(downloadPromises)
|
||||
}
|
||||
|
||||
const metaFields = ref<any[]>([])
|
||||
const pageMeta = ref<any>({})
|
||||
const linkTitleCache = ref<Record<string, string>>({})
|
||||
@ -791,6 +812,24 @@ async function loadData() {
|
||||
|
||||
// 预加载Link字段的title_field值(在loading期间同步执行,避免抖动)
|
||||
await preloadLinkTitles()
|
||||
|
||||
// 自动下载图片到本地(异步执行,不阻塞界面渲染)
|
||||
if (imageFieldName.value && rows.value.length > 0) {
|
||||
const imageUrls: string[] = []
|
||||
rows.value.forEach((row: any) => {
|
||||
const imageUrl = getImageUrl(row)
|
||||
if (imageUrl && imageUrl.startsWith('/files/')) {
|
||||
imageUrls.push(imageUrl)
|
||||
}
|
||||
})
|
||||
|
||||
if (imageUrls.length > 0) {
|
||||
// 异步下载,不阻塞界面渲染
|
||||
autoDownloadImages(imageUrls).catch((error: any) => {
|
||||
console.warn('列表页图片下载失败:', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Load data error:', error)
|
||||
message.error(t('Load failed'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user