@@ -3,8 +3,17 @@ import {onMounted, onUnmounted, ref} from "vue";
33import {useRouter } from " vue-router" ;
44import {arrayBufferToBase64 } from " @/utils/bytes2img.js"
55import StatusItem from " ./StatusItem.vue"
6+ import {useSQLite } from " @/composables/useSQLite.js"
7+ import { useImageViewStore } from ' @/stores/imageView'
68
79const router = useRouter ()
10+ const imageViewStore = useImageViewStore ()
11+
12+ const {isLoading ,
13+ error ,
14+ status ,
15+ openDatabase ,
16+ executeQuery } = useSQLite ()
817
918const props = defineProps ({
1019 coins_list: {
@@ -23,6 +32,7 @@ onUnmounted(async () => {
2332})
2433
2534const onOpenFile = () => {
35+ images .value = new Array (props .coins_list .length ).fill (' ' )
2636}
2737
2838defineExpose ({
@@ -47,20 +57,100 @@ function generateDescription( coin_data ) {
4757
4858 return desc;
4959}
60+
61+ const images = ref ([])
62+
63+ const loadImage = async (index , coinId ) => {
64+ let sql
65+ if (imageViewStore .currentImageView === ' obverse' ) {
66+ sql = ` SELECT obverseimg.image FROM coins
67+ LEFT JOIN photos AS obverseimg ON coins.obverseimg = obverseimg.id
68+ WHERE coins.id=?`
69+ }
70+ else if (imageViewStore .currentImageView === ' reverse' ) {
71+ sql = ` SELECT reverseimg.image FROM coins
72+ LEFT JOIN photos AS reverseimg ON coins.reverseimg = reverseimg.id
73+ WHERE coins.id=?`
74+ }
75+ else {
76+ sql = ` SELECT obverseimg.image, reverseimg.image FROM coins
77+ LEFT JOIN photos AS obverseimg ON coins.obverseimg = obverseimg.id
78+ LEFT JOIN photos AS reverseimg ON coins.reverseimg = reverseimg.id
79+ WHERE coins.id=?`
80+ }
81+
82+ const results = await executeQuery (sql, [coinId,])
83+ let img
84+ if (imageViewStore .currentImageView === ' both' ) {
85+ const maxHeight = 100 // Step-down scaling for better quality
86+ let aspectRatio
87+ let img1 = null , img2 = null
88+ let newWidth1 = 0 , newWidth2 = 0
89+
90+ if (results[0 ][0 ]) {
91+ const b64_img1 = arrayBufferToBase64 (results[0 ][0 ])
92+ img1 = new Image ()
93+ img1 .src = b64_img1
94+ await img1 .decode ()
95+ aspectRatio = img1 .naturalWidth / img1 .naturalHeight
96+ newWidth1 = maxHeight * aspectRatio
97+ }
98+
99+ if (results[0 ][1 ]) {
100+ const b64_img2 = arrayBufferToBase64 (results[0 ][1 ])
101+ img2 = new Image ()
102+ img2 .src = b64_img2
103+ await img2 .decode ()
104+ aspectRatio = img2 .naturalWidth / img2 .naturalHeight
105+ newWidth2 = maxHeight * aspectRatio
106+ }
107+
108+ const canvas = document .createElement (' canvas' )
109+ const ctx = canvas .getContext (' 2d' )
110+
111+ canvas .width = newWidth1 + newWidth2
112+ canvas .height = maxHeight
113+ if (img1)
114+ ctx .drawImage (img1, 0 , 0 , newWidth1, maxHeight)
115+ if (img2)
116+ ctx .drawImage (img2, newWidth1, 0 , newWidth2, maxHeight)
117+ img = canvas .toDataURL (' image/png' )
118+ }
119+ else {
120+ img = arrayBufferToBase64 (results[0 ][0 ])
121+ }
122+
123+ images .value [index] = img
124+ }
50125 </script >
51126
52127<template >
53128 <v-container class =" pa-0 ma-0" >
54129 <v-list lines =" two" >
55130 <v-list-item
56- v-for =" coin in coins_list"
131+ v-for =" ( coin, index) in coins_list"
57132 :key =" coin[0]"
58133 :subtitle =" generateDescription(coin).join(', ')"
59134 :title =" coin[2]"
60135 @click =" router.push('/coin/' + coin[0])"
61136 class =" pa-1"
62137 >
63- <template v-slot :prepend >
138+ <template v-slot :prepend v-if =" imageViewStore .currentImageView === ' obverse' " >
139+ <v-lazy :width =" 56" >
140+ <v-img :src =" images[index]" :width =" 56" max-height =" 56" :tmp =" loadImage(index, coin[0])" />
141+ </v-lazy >
142+ </template >
143+ <template v-slot :prepend v-else-if =" imageViewStore .currentImageView === ' reverse' " >
144+ <v-lazy :width =" 56" >
145+ <v-img :src =" images[index]" :width =" 56" max-height =" 56" :tmp =" loadImage(index, coin[0])" />
146+ </v-lazy >
147+ </template >
148+ <template v-slot :prepend v-else-if =" imageViewStore .currentImageView === ' both' " >
149+ <v-lazy :width =" 100" >
150+ <v-img :src =" images[index]" :width =" 100" max-height =" 56" :tmp =" loadImage(index, coin[0])" />
151+ </v-lazy >
152+ </template >
153+ <template v-slot :prepend v-else >
64154 <v-img :src =" arrayBufferToBase64(coin[1])" :width =" 100" max-height =" 56" />
65155 </template >
66156 <template v-slot :append >
0 commit comments