funkcjonalności listy pojazdów

This commit is contained in:
2023-07-10 17:47:44 +02:00
parent 073288c8a9
commit dda67ad993
3 changed files with 134 additions and 23 deletions
+1
View File
@@ -8,6 +8,7 @@
:data-selected="store.stockSectionMode == id" :data-selected="store.stockSectionMode == id"
> >
{{ name }} {{ name }}
<span v-if="id == 'stock-list'">({{ store.stockList.length }})</span>
</button> </button>
</div> </div>
+130 -20
View File
@@ -11,32 +11,33 @@
</div> </div>
</div> </div>
<div class="table-wrapper"> <div class="table-wrapper" @scroll="scrollEvent" ref="table-wrapper">
<table> <table>
<thead> <thead>
<tr> <tr>
<th>Zdjęcie</th> <th v-for="header in wikiMode == 'locomotives' ? locoHeaders : carHeaders" @click="toggleSorter(header.id)">
<th>Nazwa</th> {{ header.name }}
<th>Typ</th>
<th>Długość</th> <span v-if="currentModeSorter.id == header.id">
<th>Masa</th> {{ currentModeSorter.direction == 1 ? `&uArr;` : `&dArr;` }}
<th>Prędkość</th> </span>
</th>
</tr> </tr>
</thead> </thead>
<tbody v-if="wikiMode == 'locomotives'"> <tbody v-if="wikiMode == 'locomotives'">
<tr v-for="loco in computedLocoList" @click="previewLocomotive(loco)"> <tr v-for="loco in computedLocoList" @click="previewLocomotive(loco)" @dblclick="addLocomotive(loco)">
<td> <td>
<img <img
:src="`https://spythere.github.io/api/td2/images/${loco.type}--300px.jpg`" :src="`https://spythere.github.io/api/td2/images/${loco.type}--300px.jpg`"
width="170"
loading="lazy" loading="lazy"
:alt="`Lokomotywa ${loco.type}`" :alt="`Lokomotywa ${loco.type}`"
/> />
</td> </td>
<td>{{ loco.type }}</td> <td>{{ loco.type }}</td>
<td>{{ loco.cabinType }}</td> <td>{{ vehicleTypes[loco.power] }}</td>
<td>{{ loco.constructionType }}</td>
<td>{{ loco.length }}m</td> <td>{{ loco.length }}m</td>
<td>{{ loco.mass }}t</td> <td>{{ loco.mass }}t</td>
<td>{{ loco.maxSpeed }}km/h</td> <td>{{ loco.maxSpeed }}km/h</td>
@@ -44,11 +45,10 @@
</tbody> </tbody>
<tbody v-else> <tbody v-else>
<tr v-for="car in computedCarList" @click="previewCarWagon(car)"> <tr v-for="car in computedCarList" @click="previewCarWagon(car)" @dblclick="addCarWagon(car)">
<td> <td>
<img <img
:src="`https://spythere.github.io/api/td2/images/${car.type}--300px.jpg`" :src="`https://spythere.github.io/api/td2/images/${car.type}--300px.jpg`"
width="170"
loading="lazy" loading="lazy"
:alt="`Lokomotywa ${car.type}`" :alt="`Lokomotywa ${car.type}`"
/> />
@@ -59,6 +59,7 @@
<td>{{ car.length }}m</td> <td>{{ car.length }}m</td>
<td>{{ car.mass }}t</td> <td>{{ car.mass }}t</td>
<td>{{ car.maxSpeed }}km/h</td> <td>{{ car.maxSpeed }}km/h</td>
<td>{{ car.cargoList.length == 0 ? '-' : car.cargoList.length }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -70,41 +71,138 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../../store'; import { useStore } from '../../store';
import stockPreviewMixin from '../../mixins/stockPreviewMixin'; import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import { ICarWagon, ILocomotive } from '../../types'; import { Vehicle } from '../../types';
import { isLocomotive } from '../../utils/vehicleUtils';
import stockMixin from '../../mixins/stockMixin';
type WikiMode = 'locomotives' | 'carWagons'; type WikiMode = 'locomotives' | 'carWagons';
type SorterID = 'type' | 'constructionType' | 'image' | 'length' | 'mass' | 'maxSpeed' | 'cargoCount' | 'power';
const locoHeaders: { name: string; id: SorterID }[] = [
{ name: 'Zdjęcie', id: 'image' },
{ name: 'Nazwa', id: 'type' },
{ name: 'Rodzaj', id: 'power' },
{ name: 'Konstrukcja', id: 'constructionType' },
{ name: 'Długość', id: 'length' },
{ name: 'Masa', id: 'mass' },
{ name: 'Prędkość', id: 'maxSpeed' },
];
const carHeaders: { name: string; id: SorterID }[] = [
{ name: 'Zdjęcie', id: 'image' },
{ name: 'Nazwa', id: 'type' },
{ name: 'Konstrukcja', id: 'constructionType' },
{ name: 'Długość', id: 'length' },
{ name: 'Masa', id: 'mass' },
{ name: 'Prędkość', id: 'maxSpeed' },
{ name: 'Ładunki', id: 'cargoCount' },
];
const vehicleTypes: { [key: string]: string } = {
'loco-ezt': 'EZT',
'loco-szt': 'SZT',
'loco-s': 'Spalinowóz',
'loco-e': 'Elektrowóz',
};
export default defineComponent({ export default defineComponent({
mixins: [stockPreviewMixin], mixins: [stockPreviewMixin, stockMixin],
data() { data() {
return { return {
store: useStore(), store: useStore(),
locoHeaders,
carHeaders,
vehicleTypes,
locosScrollTop: 0,
carsScrollTop: 0,
wikiMode: 'locomotives' as WikiMode, wikiMode: 'locomotives' as WikiMode,
searchedVehicleTypeName: '', searchedVehicleTypeName: '',
currentLocoSorter: {
id: 'type' as SorterID,
direction: 1,
},
currentCarSorter: {
id: 'type' as SorterID,
direction: 1,
},
}; };
}, },
activated() {
const tableWrapperRef = this.$refs['table-wrapper'] as HTMLElement;
tableWrapperRef.scrollTo({ top: this.wikiMode == 'locomotives' ? this.locosScrollTop : this.carsScrollTop });
},
methods: { methods: {
scrollEvent(e: Event) {
const tableScrollTop = (e.target as HTMLElement).scrollTop;
if (this.wikiMode == 'locomotives') this.locosScrollTop = tableScrollTop;
else this.carsScrollTop = tableScrollTop;
},
changeWikiMode(wikiMode: WikiMode) { changeWikiMode(wikiMode: WikiMode) {
this.searchedVehicleTypeName = ''; this.searchedVehicleTypeName = '';
this.wikiMode = wikiMode; this.wikiMode = wikiMode;
}, },
toggleSorter(id: SorterID) {
if (id == this.currentModeSorter.id) this.currentModeSorter.direction = -this.currentModeSorter.direction;
this.currentModeSorter.id = id;
},
sortVehicles(vA: Vehicle, vB: Vehicle) {
const { id, direction } = this.currentModeSorter;
// const vehiclesAreLocos = isLocomotive(vA) && isLocomotive(vB);
const vehiclesAreCars = !isLocomotive(vA) && !isLocomotive(vB);
switch (id) {
case 'type':
case 'constructionType':
return direction == 1 ? vA[id].localeCompare(vB[id]) : vB[id].localeCompare(vA[id]);
case 'mass':
case 'length':
case 'maxSpeed':
return Math.sign(vA[id] - vB[id]) * direction;
case 'cargoCount':
if (vehiclesAreCars) return Math.sign((vA.cargoList.length || -1) - (vB.cargoList.length || -1)) * direction;
default:
break;
}
return direction == 1 ? vA.type.localeCompare(vB.type) : vB.type.localeCompare(vA.type);
},
}, },
computed: { computed: {
currentModeSorter() {
console.log(this.wikiMode);
return this.wikiMode == 'carWagons' ? this.currentCarSorter : this.currentLocoSorter;
},
computedLocoList() { computedLocoList() {
const trimmedSearchValue = this.searchedVehicleTypeName.trim(); const trimmedSearchValue = this.searchedVehicleTypeName.trim();
if (trimmedSearchValue == '') return this.store.locoDataList;
return this.store.locoDataList.filter((loco) => new RegExp(`${trimmedSearchValue}`, 'i').test(loco.type)); return this.store.locoDataList
.filter((loco) => new RegExp(`${trimmedSearchValue}`, 'i').test(loco.type))
.sort(this.sortVehicles);
}, },
computedCarList() { computedCarList() {
const trimmedSearchValue = this.searchedVehicleTypeName.trim(); const trimmedSearchValue = this.searchedVehicleTypeName.trim();
if (trimmedSearchValue == '') return this.store.carDataList;
return this.store.carDataList.filter((car) => new RegExp(`${trimmedSearchValue}`, 'i').test(car.type)); return this.store.carDataList
.filter((car) => new RegExp(`${trimmedSearchValue}`, 'i').test(car.type))
.sort(this.sortVehicles);
}, },
}, },
}); });
@@ -150,25 +248,37 @@ export default defineComponent({
th { th {
background-color: #111; background-color: #111;
padding: 0.5em; padding: 0.5em;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
} }
tr { tr {
cursor: pointer;
background-color: #333; background-color: #333;
&:nth-child(odd) { &:nth-child(odd) {
background-color: #444; background-color: #444;
} }
&:hover {
background-color: #666;
}
} }
td { td {
text-align: center; text-align: center;
padding: 0.25em;
height: 100px; height: 100px;
} }
td:first-child {
width: 150px;
}
td img { td img {
display: block; display: block;
margin: 0 auto; width: 150px;
object-fit: cover;
} }
} }
</style> </style>
+3 -3
View File
@@ -135,8 +135,8 @@ button {
select, select,
input { input {
background: none; background: $bgColor;
border: 2px solid white; border: 2px solid #aaa;
outline: none; outline: none;
padding: 0.25em 0.35em; padding: 0.25em 0.35em;
@@ -156,7 +156,7 @@ input {
} }
option { option {
color: black; color: white;
border: none; border: none;
} }