mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
obsługa niezaładowanych miniaturek pojazdów
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<img :src="url" loading="lazy" alt="Loco image not found" @error="onImageError" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import imageMixin from '../../mixins/imageMixin';
|
||||
import { useStore } from '../../store/store';
|
||||
import { RollingStockInfo } from '../../scripts/interfaces/github_api/StockInfoGithubData';
|
||||
|
||||
export default defineComponent({
|
||||
mixins: [imageMixin],
|
||||
|
||||
props: {
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
url() {
|
||||
return `https://rj.td2.info.pl/dist/img/thumbnails/${this.name.split(':')[0]}.png`;
|
||||
},
|
||||
|
||||
stockType() {
|
||||
if (!this.store.rollingStockData) return 'unknown';
|
||||
|
||||
return (
|
||||
Object.keys(this.store.rollingStockData.info).find((type) => {
|
||||
return this.store.rollingStockData?.info[type as keyof RollingStockInfo].find((v) => v[0] === this.name.split(':')[0]);
|
||||
}) || 'unknown'
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
onImageError(e: Event) {
|
||||
const imageEl = e.target as HTMLImageElement;
|
||||
imageEl.src = this.getImage(`icon-${this.stockType}.png`);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
img {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
@@ -60,11 +60,7 @@
|
||||
).split(';')"
|
||||
:key="i"
|
||||
>
|
||||
<img
|
||||
@error="onImageError"
|
||||
:src="`https://rj.td2.info.pl/dist/img/thumbnails/${car.split(':')[0]}.png`"
|
||||
:alt="car"
|
||||
/>
|
||||
<TrainThumbnail :name="car" />
|
||||
<div>{{ car.replace(/_/g, ' ').split(':')[0] }}</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -75,28 +71,25 @@
|
||||
import { PropType, defineComponent } from 'vue';
|
||||
import { TimetableHistory } from '../../../scripts/interfaces/api/TimetablesAPIData';
|
||||
import imageMixin from '../../../mixins/imageMixin';
|
||||
import TrainThumbnail from '../../Global/TrainThumbnail.vue';
|
||||
|
||||
export default defineComponent({
|
||||
mixins: [imageMixin],
|
||||
|
||||
props: {
|
||||
showExtraInfo: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
|
||||
timetable: {
|
||||
type: Object as PropType<TimetableHistory>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
currentHistoryIndex: 0,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
stockHistory() {
|
||||
return this.timetable.stockHistory
|
||||
@@ -116,13 +109,13 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
onImageError(e: Event) {
|
||||
const imageEl = e.target as HTMLImageElement;
|
||||
imageEl.src = this.getImage('unknown.png');
|
||||
},
|
||||
},
|
||||
components: { TrainThumbnail },
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -62,15 +62,13 @@
|
||||
</section>
|
||||
|
||||
<section class="train-stats">
|
||||
<div>
|
||||
<img :src="train.locoURL" loading="lazy" alt="Loco image not found" @error="onImageError" />
|
||||
</div>
|
||||
<TrainThumbnail :name="train.locoType" />
|
||||
|
||||
<div class="text--grayed">
|
||||
{{ train.locoType }}
|
||||
<span v-if="train.cars.length > 0">
|
||||
<span v-if="train.stockList.length > 0">
|
||||
• {{ $t('trains.cars') }}:
|
||||
<span class="count">{{ train.cars.length }}</span>
|
||||
<span class="count">{{ train.stockList.length }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -91,6 +89,7 @@ import styleMixin from '../../mixins/styleMixin';
|
||||
import trainInfoMixin from '../../mixins/trainInfoMixin';
|
||||
import Train from '../../scripts/interfaces/Train';
|
||||
import ProgressBar from '../Global/ProgressBar.vue';
|
||||
import TrainThumbnail from '../Global/TrainThumbnail.vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
@@ -104,7 +103,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
mixins: [trainInfoMixin, imageMixin, styleMixin],
|
||||
components: { ProgressBar },
|
||||
components: { ProgressBar, TrainThumbnail },
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -127,7 +126,7 @@ export default defineComponent({
|
||||
text-align: center;
|
||||
|
||||
img {
|
||||
margin: 0.5em 0;
|
||||
margin: 0.5em auto;
|
||||
width: 12em;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
<div class="train-schedule" @click="toggleShowState">
|
||||
<div class="train-stock">
|
||||
<ul class="stock-list">
|
||||
<li>
|
||||
<!-- <li>
|
||||
<img class="train-image" :src="train.locoURL" alt="loco" @error="onImageError" />
|
||||
<div>{{ train.locoType }}</div>
|
||||
</li>
|
||||
</li> -->
|
||||
|
||||
<li v-if="train.locoType.startsWith('EN')">
|
||||
<!-- <li v-if="train.locoType.startsWith('EN')">
|
||||
<img :src="train.locoURL.replace('rb', 's')" @error="onImageError" alt="" />
|
||||
<div>{{ train.locoType }}S</div>
|
||||
</li>
|
||||
@@ -20,16 +20,17 @@
|
||||
<li v-if="train.locoType.startsWith('EN')">
|
||||
<img :src="train.locoURL.replace('rb', 'ra')" @error="onImageError" alt="" />
|
||||
<div>{{ train.locoType }}RA</div>
|
||||
</li>
|
||||
</li> -->
|
||||
|
||||
<li v-for="(car, i) in train.cars" :key="i">
|
||||
<img
|
||||
<li v-for="(stockName, i) in train.stockList" :key="i">
|
||||
<!-- <img
|
||||
:src="`https://rj.td2.info.pl/dist/img/thumbnails/${car.split(':')[0]}.png`"
|
||||
@error="onImageError"
|
||||
alt="car"
|
||||
/>
|
||||
/> -->
|
||||
|
||||
<div>{{ car.replace(/_/g, ' ').split(':')[0] }}</div>
|
||||
<TrainThumbnail :name="stockName" />
|
||||
<div>{{ stockName.replace(/_/g, ' ').split(':')[0] }}</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -91,9 +92,10 @@ import Train from '../../scripts/interfaces/Train';
|
||||
import TrainStop from '../../scripts/interfaces/TrainStop';
|
||||
import { useStore } from '../../store/store';
|
||||
import StopDate from '../Global/StopDate.vue';
|
||||
import TrainThumbnail from '../Global/TrainThumbnail.vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: { StopDate },
|
||||
components: { StopDate, TrainThumbnail },
|
||||
props: {
|
||||
train: {
|
||||
type: Object as PropType<Train>,
|
||||
@@ -426,4 +428,3 @@ ul.stop_list > li.stop {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user