mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
axios: baseURL
This commit is contained in:
+68
-1
@@ -1,5 +1,8 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { AuthState, IStore } from './types/types';
|
||||
import { AuthState, ILoginResponse, IStore, IUser, SceneryRowItem } from './types/types';
|
||||
import axios from 'axios';
|
||||
|
||||
const baseURL = import.meta.env[`VITE_API_URL${import.meta.env.DEV ? '_DEV' : ''}`];
|
||||
|
||||
export const useStore = defineStore('store', {
|
||||
state: () =>
|
||||
@@ -29,4 +32,68 @@ export const useStore = defineStore('store', {
|
||||
|
||||
changesResponse: [],
|
||||
} as IStore),
|
||||
actions: {
|
||||
fetchSceneriesData() {
|
||||
this.dataState = 'LOADING';
|
||||
|
||||
const data = axios.get<SceneryRowItem[]>(`api/getSceneries?time=${Date.now()}`, {
|
||||
baseURL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
},
|
||||
});
|
||||
|
||||
data
|
||||
.then((res) => {
|
||||
this.dataState = 'LOADED';
|
||||
this.backupList = JSON.parse(JSON.stringify(res.data));
|
||||
this.stationList = res.data;
|
||||
this.unsavedChanges = false;
|
||||
this.changeList = [];
|
||||
})
|
||||
.catch(() => {
|
||||
this.dataState = 'ERROR';
|
||||
this.token = '';
|
||||
this.isAuthorized = false;
|
||||
});
|
||||
},
|
||||
|
||||
updateSceneriesData(mappedChangeList: any[]) {
|
||||
const response = axios.post(
|
||||
'/manager/updateSceneryList',
|
||||
{
|
||||
changeList: mappedChangeList,
|
||||
token: this.token,
|
||||
notify: this.notifyDiscord,
|
||||
},
|
||||
{
|
||||
baseURL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
login(name: string, pwd: string) {
|
||||
return axios.post<ILoginResponse>(
|
||||
'auth/login',
|
||||
{ username: name, password: pwd },
|
||||
{
|
||||
baseURL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
fetchTokenData() {
|
||||
return axios.post<{ user: IUser }>('auth/token', { token: this.token }, { baseURL });
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user