|
| 1 | +<script setup> |
| 2 | +import {defineProps, onMounted, onUnmounted, ref} from "vue"; |
| 3 | +import {useRoute} from "vue-router"; |
| 4 | +import {useSQLite} from "@/composables/useSQLite.js"; |
| 5 | +
|
| 6 | +const route = useRoute() |
| 7 | +
|
| 8 | +const {isLoading, |
| 9 | + error, |
| 10 | + status, |
| 11 | + openDatabase, |
| 12 | + executeQuery} = useSQLite() |
| 13 | +
|
| 14 | +const props = defineProps({ |
| 15 | + title: String, |
| 16 | +}); |
| 17 | +
|
| 18 | +const emit = defineEmits(['update:title']); |
| 19 | +let oldTitle = null; |
| 20 | +const coinData = ref([]) |
| 21 | +
|
| 22 | +const infoFields = ['coins.title', 'obverseimg.image', 'reverseimg.image', |
| 23 | + 'status', 'region', 'country', 'period', 'ruler', 'value', 'unit', 'type', |
| 24 | + 'series', 'subjectshort', 'issuedate', 'year', 'mintage', 'material', |
| 25 | + 'mint', 'mintmark', 'features', 'subject', 'grade', 'paydate', 'payprice', |
| 26 | + 'storage', 'condition', 'quantity']; |
| 27 | +function infoFieldIndex(field) { |
| 28 | + return infoFields.findIndex(element => element === field); |
| 29 | +} |
| 30 | +
|
| 31 | +onMounted(async () => { |
| 32 | + const id = route.params['id'] |
| 33 | + const sql = `SELECT ${ infoFields.join(',') } FROM coins |
| 34 | + LEFT JOIN photos AS obverseimg ON coins.obverseimg = obverseimg.id |
| 35 | + LEFT JOIN photos AS reverseimg ON coins.reverseimg = reverseimg.id |
| 36 | + WHERE coins.id=?` |
| 37 | + const results = await executeQuery(sql, [id,]) |
| 38 | + coinData.value = results[0] |
| 39 | +
|
| 40 | + oldTitle = props.title; |
| 41 | + emit('update:title', coinData.value[0]); |
| 42 | +}) |
| 43 | +onUnmounted(async () => { |
| 44 | + emit('update:title', oldTitle); |
| 45 | +}) |
| 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 | +} |
| 57 | +</script> |
| 58 | + |
| 59 | +<template> |
| 60 | + <v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('obverseimg.image')])" :width="200" /> |
| 61 | + <v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('reverseimg.image')])" :width="200" /> |
| 62 | + {{ coinData[infoFieldIndex('status')] }} |
| 63 | + {{ coinData[infoFieldIndex('country')] }} |
| 64 | + {{ coinData[infoFieldIndex('type')] }} |
| 65 | + |
| 66 | + {{ coinData[infoFieldIndex('features')] }} |
| 67 | + {{ coinData[infoFieldIndex('subject')] }} |
| 68 | +</template> |
| 69 | + |
| 70 | +<style scoped> |
| 71 | +
|
| 72 | +</style> |
0 commit comments