11import { defineComponent } from 'vue'
2- import type { EnrichmentResult } from '~/models/enrichment'
2+ import type { EnrichmentImage , EnrichmentResult } from '~/models/enrichment'
33import type { PropType } from 'vue'
44
5+ const IMAGE_FIELDS = [
6+ { key : 'thumbnailImage' , label : '封面图' } ,
7+ { key : 'previewImage' , label : 'OG 预览图' } ,
8+ { key : 'captureImage' , label : '截图' } ,
9+ ] as const
10+
511export const CacheNormalizedSection = defineComponent ( {
612 name : 'CacheNormalizedSection' ,
713 props : {
@@ -11,7 +17,6 @@ export const CacheNormalizedSection = defineComponent({
1117 setup ( props ) {
1218 return ( ) => {
1319 const { result } = props
14- const image = result . thumbnailImage
1520 const attributes = result . attributes ?? [ ]
1621 const links = result . links ?? [ ]
1722 return (
@@ -30,25 +35,15 @@ export const CacheNormalizedSection = defineComponent({
3035 { result . description || '—' }
3136 </ span >
3237 </ Field >
33- < Field label = "封面图" >
34- { image ? (
35- < a
36- href = { image . url }
37- target = "_blank"
38- rel = "noopener noreferrer"
39- class = "block max-w-xs overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
40- >
41- < img
42- src = { image . url }
43- alt = { image . alt || '' }
44- class = "w-full object-cover"
45- loading = "lazy"
46- />
47- </ a >
48- ) : (
49- < span class = "text-xs text-neutral-400" > 无</ span >
50- ) }
51- </ Field >
38+ { IMAGE_FIELDS . map ( ( { key, label } ) => {
39+ const img = result [ key ]
40+ if ( ! img ?. url ) return null
41+ return (
42+ < Field key = { key } label = { label } >
43+ < ImagePreview image = { img } />
44+ </ Field >
45+ )
46+ } ) }
5247 { attributes . length > 0 && (
5348 < Field label = "属性" >
5449 < div class = "overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800" >
@@ -113,3 +108,27 @@ const Field = defineComponent({
113108 )
114109 } ,
115110} )
111+
112+ const ImagePreview = defineComponent ( {
113+ name : 'ImagePreview' ,
114+ props : {
115+ image : { type : Object as PropType < EnrichmentImage > , required : true } ,
116+ } ,
117+ setup ( props ) {
118+ return ( ) => (
119+ < a
120+ href = { props . image . url }
121+ target = "_blank"
122+ rel = "noopener noreferrer"
123+ class = "block max-w-xs overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
124+ >
125+ < img
126+ src = { props . image . url }
127+ alt = { props . image . alt || '' }
128+ class = "w-full object-cover"
129+ loading = "lazy"
130+ />
131+ </ a >
132+ )
133+ } ,
134+ } )
0 commit comments