mirror of
https://github.com/Spythere/srjp-td2.git
synced 2026-05-03 21:48:13 +00:00
init: almost production-ready app
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import httpClient from '../utils/http';
|
||||
import type { ActiveDataResponse, SceneriesDataResponse } from '../types/api.types';
|
||||
import type { ActiveData, SceneryData } from '../types/common.types';
|
||||
|
||||
export const useGlobalStore = defineStore('global', {
|
||||
state: () => ({
|
||||
activeData: null as ActiveData | null,
|
||||
sceneryData: null as SceneryData[] | null,
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async _fetchActiveData() {
|
||||
try {
|
||||
const response = (await httpClient.get<ActiveDataResponse>('/api/getActiveData')).data;
|
||||
|
||||
this.activeData = response;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
async _fetchSceneriesData() {
|
||||
try {
|
||||
const response = (await httpClient.get<SceneriesDataResponse>('/api/getSceneries')).data;
|
||||
|
||||
this.sceneryData = response;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
setupData() {
|
||||
this._fetchActiveData();
|
||||
this._fetchSceneriesData();
|
||||
|
||||
setInterval(() => {
|
||||
this._fetchActiveData();
|
||||
}, 20000);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user