Skip to content

Commit 044bfaa

Browse files
committed
Add images page
1 parent 45d9604 commit 044bfaa

6 files changed

Lines changed: 69 additions & 25 deletions

File tree

frontend/src/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FileUploaderView from '@/components/FileUploaderView.vue'
66
import CoinListView from "@/components/CoinListView.vue";
77
import AboutView from "@/components/AboutView.vue";
88
import CoinView from "@/components/CoinView.vue";
9+
import ImagesView from "@/components/ImagesView.vue";
910
1011
const {isLoading,
1112
error,
@@ -84,6 +85,9 @@ const handleFileUpload = async (file) => {
8485
<div v-if="route.name === 'coin' && isOpened">
8586
<CoinView v-model:title="title" />
8687
</div>
88+
<div v-if="route.name === 'images' && isOpened">
89+
<ImagesView />
90+
</div>
8791
<div v-if="route.name === 'about'">
8892
<AboutView v-model:title="title" />
8993
</div>

frontend/src/components/CoinListView.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup>
22
import {defineProps, onMounted, onUnmounted} from "vue";
33
import {useRouter} from "vue-router";
4+
import {arrayBufferToBase64} from "@/utils/bytes2img.js"
45
56
const router = useRouter()
67
@@ -27,17 +28,6 @@ onUnmounted(async () => {
2728
emit('update:title', oldTitle);
2829
})
2930
30-
function arrayBufferToBase64( buffer ) {
31-
let binary = '';
32-
const bytes = new Uint8Array( buffer );
33-
const len = bytes.byteLength;
34-
for (let i = 0; i < len; i++) {
35-
binary += String.fromCharCode( bytes[ i ] );
36-
}
37-
const base64String = window.btoa( binary );
38-
return `data:image/png;base64,${base64String}`;
39-
}
40-
4131
function generateDescription( coin_data ) {
4232
let desc = [];
4333
if (coin_data[4])

frontend/src/components/CoinView.vue

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script setup>
22
import {defineProps, onMounted, onUnmounted, ref} from "vue";
3-
import {useRoute} from "vue-router";
3+
import {useRoute, useRouter} from "vue-router";
44
import {useSQLite} from "@/composables/useSQLite.js";
5+
import {arrayBufferToBase64} from "@/utils/bytes2img.js"
56
7+
const router = useRouter()
68
const route = useRoute()
79
810
const {isLoading,
@@ -43,22 +45,15 @@ onMounted(async () => {
4345
onUnmounted(async () => {
4446
emit('update:title', oldTitle);
4547
})
46-
47-
function arrayBufferToBase64( buffer ) {
48-
let binary = '';
49-
const bytes = new Uint8Array( buffer );
50-
const len = bytes.byteLength;
51-
for (let i = 0; i < len; i++) {
52-
binary += String.fromCharCode( bytes[ i ] );
53-
}
54-
const base64String = window.btoa( binary );
55-
return `data:image/png;base64,${base64String}`;
56-
}
5748
</script>
5849

5950
<template>
60-
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('obverseimg.image')])" :width="200" />
61-
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('reverseimg.image')])" :width="200" />
51+
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('obverseimg.image')])"
52+
:width="200"
53+
@click="router.push('/images/' + route.params['id'])" />
54+
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('reverseimg.image')])"
55+
:width="200"
56+
@click="router.push('/images/' + route.params['id'])" />
6257
{{ coinData[infoFieldIndex('status')] }}
6358
{{ coinData[infoFieldIndex('country')] }}
6459
{{ coinData[infoFieldIndex('type')] }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script setup>
2+
import { onMounted, ref} from "vue";
3+
import {useRoute} from "vue-router";
4+
import {useSQLite} from "@/composables/useSQLite.js";
5+
import {arrayBufferToBase64} from "@/utils/bytes2img.js"
6+
7+
const route = useRoute()
8+
9+
const {isLoading,
10+
error,
11+
status,
12+
openDatabase,
13+
executeQuery} = useSQLite()
14+
15+
const images = ref([])
16+
17+
onMounted(async () => {
18+
const id = route.params['id']
19+
const sql = `SELECT obverseimg.image, reverseimg.image, edgeimg.image, photo1.image, photo2.image, photo3.image, photo4.image FROM coins
20+
LEFT JOIN photos AS obverseimg ON coins.obverseimg = obverseimg.id
21+
LEFT JOIN photos AS reverseimg ON coins.reverseimg = reverseimg.id
22+
LEFT JOIN photos AS edgeimg ON coins.edgeimg = edgeimg.id
23+
LEFT JOIN photos AS photo1 ON coins.photo1 = photo1.id
24+
LEFT JOIN photos AS photo2 ON coins.photo2 = photo2.id
25+
LEFT JOIN photos AS photo3 ON coins.photo3 = photo3.id
26+
LEFT JOIN photos AS photo4 ON coins.photo4 = photo4.id
27+
WHERE coins.id=?`
28+
const results = await executeQuery(sql, [id,])
29+
images.value = results[0]
30+
})
31+
</script>
32+
33+
<template>
34+
<div v-for="image in images">
35+
<v-img :src="arrayBufferToBase64(image)" width="100%" />
36+
</div>
37+
</template>
38+
39+
<style scoped>
40+
41+
</style>

frontend/src/router/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const routes = [
99
path: '/coin/:id',
1010
name: 'coin',
1111
},
12+
{
13+
path: '/images/:id',
14+
name: 'images',
15+
},
1216
{
1317
path: '/open',
1418
name: 'open',

frontend/src/utils/bytes2img.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function arrayBufferToBase64( buffer ) {
2+
let binary = '';
3+
const bytes = new Uint8Array( buffer );
4+
const len = bytes.byteLength;
5+
for (let i = 0; i < len; i++) {
6+
binary += String.fromCharCode( bytes[ i ] );
7+
}
8+
const base64String = window.btoa( binary );
9+
return `data:image/png;base64,${base64String}`;
10+
}

0 commit comments

Comments
 (0)