mirror of
https://github.com/Spythere/srjp-td2.git
synced 2026-05-03 13:38:12 +00:00
feat: journal timetable view mode
This commit is contained in:
+85
-5
@@ -1,8 +1,19 @@
|
||||
import type { AxiosInstance } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { defineStore } from 'pinia';
|
||||
import { DataStatus, type ActiveDataResponse, type SceneriesDataResponse } from '../types/api.types';
|
||||
import type { ActiveData, SceneryData } from '../types/common.types';
|
||||
import {
|
||||
DataStatus,
|
||||
type ActiveDataResponse,
|
||||
type SceneriesDataResponse,
|
||||
type JournalTimetablesShortResponse
|
||||
} from '../types/api.types';
|
||||
import type {
|
||||
ActiveData,
|
||||
JournalTimetableDetailed,
|
||||
JournalTimetableShort,
|
||||
SceneryData
|
||||
} from '../types/common.types';
|
||||
import { useGlobalStore } from './global.store';
|
||||
|
||||
export const useApiStore = defineStore('api', {
|
||||
state() {
|
||||
@@ -11,11 +22,13 @@ export const useApiStore = defineStore('api', {
|
||||
|
||||
activeData: null as ActiveData | null,
|
||||
sceneryData: null as SceneryData[] | null,
|
||||
journalTimetablesData: null as JournalTimetableShort[] | null,
|
||||
|
||||
outdatedTimerId: -1,
|
||||
isActiveDataOutdated: false,
|
||||
|
||||
activeDataStatus: DataStatus.LOADING,
|
||||
journalDataStatus: DataStatus.SUCCESS
|
||||
};
|
||||
},
|
||||
|
||||
@@ -37,13 +50,12 @@ export const useApiStore = defineStore('api', {
|
||||
}
|
||||
|
||||
this.client = axios.create({
|
||||
baseURL,
|
||||
baseURL
|
||||
});
|
||||
|
||||
this.fetchSceneriesData();
|
||||
await this.fetchActiveData();
|
||||
|
||||
|
||||
setInterval(() => {
|
||||
this.fetchActiveData();
|
||||
}, 25000);
|
||||
@@ -76,5 +88,73 @@ export const useApiStore = defineStore('api', {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
async fetchJournalTimetables(searchValue: string) {
|
||||
// if (searchValue.trim().length == 0) {
|
||||
// this.journalDataStatus = DataStatus.SUCCESS;
|
||||
// this.journalTimetablesData = null;
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
let searchObj: Record<string, any> = {};
|
||||
const searchParams = searchValue.split(' ');
|
||||
|
||||
searchParams.forEach((param) => {
|
||||
const [key, value] = param.split(':');
|
||||
|
||||
if (key == 'nick') searchObj['driverName'] = value;
|
||||
else if (key == 'date') {
|
||||
let dateFromStr = new Date(value).toISOString();
|
||||
|
||||
let dateTo = new Date(dateFromStr);
|
||||
dateTo.setDate(dateTo.getDate() + 1);
|
||||
|
||||
searchObj['dateFrom'] = dateFromStr;
|
||||
searchObj['dateTo'] = dateTo.toISOString();
|
||||
} else if (key == 'from') searchObj['issuedFrom'] = value.replace(/_/g, ' ');
|
||||
else if (key == 'to') searchObj['terminatingAt'] = value.replace(/_/g, ' ');
|
||||
});
|
||||
|
||||
searchObj['hasStopsDetails'] = 1;
|
||||
searchObj['returnType'] = 'short';
|
||||
|
||||
try {
|
||||
this.journalDataStatus = DataStatus.LOADING;
|
||||
|
||||
const response = (
|
||||
await this.client!.get<JournalTimetablesShortResponse>('/api/getTimetables', {
|
||||
params: searchObj
|
||||
})
|
||||
).data;
|
||||
|
||||
this.journalDataStatus = DataStatus.SUCCESS;
|
||||
this.journalTimetablesData = response;
|
||||
} catch (error) {
|
||||
this.journalDataStatus = DataStatus.ERROR;
|
||||
this.journalTimetablesData = null;
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
async fetchJournalTimetableDetails(id: number) {
|
||||
const globalStore = useGlobalStore();
|
||||
|
||||
try {
|
||||
const response = (
|
||||
await this.client!.get<JournalTimetableDetailed[]>('/api/getTimetables', {
|
||||
params: {
|
||||
timetableId: id,
|
||||
hasStopsDetails: 1
|
||||
}
|
||||
})
|
||||
).data;
|
||||
|
||||
if (response.length > 0) globalStore.selectedJournalTimetable = response[0];
|
||||
} catch (error) {
|
||||
globalStore.selectedJournalTimetable = null;
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user