clear
This commit is contained in:
parent
440e0c2314
commit
417284c7f0
@ -3,20 +3,14 @@ import { onMounted, ref } from 'vue';
|
||||
import { getApiUrl } from './net';
|
||||
import router from '@/router';
|
||||
import VueQrcode from '@chenfengyuan/vue-qrcode';
|
||||
import type { Teams } from './models';
|
||||
import { getTeams } from './client';
|
||||
|
||||
type Game = {
|
||||
state: string
|
||||
startAt: string
|
||||
endAt: string
|
||||
}
|
||||
import type { Game, Teams } from './models';
|
||||
import { apiGetTeams, apiAddTeam, apiGetGame, apiStartGame, apiStopGame } from './client';
|
||||
|
||||
const qrurl = ref("-")
|
||||
const qrteam = ref("-")
|
||||
|
||||
const gameState = ref("")
|
||||
const game = ref<Game>()
|
||||
const game = ref<Game | undefined>()
|
||||
|
||||
const teams = ref<Teams>({ teams: [] })
|
||||
|
||||
@ -38,19 +32,7 @@ function gaveApplication(teamId: number, id: number) {
|
||||
|
||||
const teamName = ref("")
|
||||
function addTeam() {
|
||||
fetch(
|
||||
getApiUrl("/teams"),
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"teams": [{ "name": teamName.value }]
|
||||
})
|
||||
}
|
||||
)
|
||||
.then(() => { teamName.value = "" })
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
apiAddTeam(teamName)
|
||||
}
|
||||
|
||||
interface QROptions {
|
||||
@ -71,47 +53,15 @@ const qrOptions = ref<QROptions>({
|
||||
});
|
||||
|
||||
function getGame() {
|
||||
fetch(
|
||||
getApiUrl("/game")
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
game.value = data
|
||||
if (data.state === "NEW") {
|
||||
gameState.value = "Игра ещё не началась"
|
||||
}
|
||||
if (data.state === "RUN") {
|
||||
gameState.value = "Игра идет с " + game.value?.startAt.substring(11)
|
||||
}
|
||||
if (data.state === "STOP") {
|
||||
gameState.value = "Игра остановлена " + game.value?.startAt.substring(11) + " - " + game.value?.endAt.substring(11)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
apiGetGame(game, gameState)
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
gameState.value = "Загрузка..."
|
||||
fetch(
|
||||
getApiUrl("/game/start"),
|
||||
{ method: "POST" }
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
apiStartGame(gameState)
|
||||
}
|
||||
|
||||
function stopGame() {
|
||||
gameState.value = "Загрузка..."
|
||||
fetch(
|
||||
getApiUrl("/game/stop"),
|
||||
{ method: "POST" }
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
apiStopGame(gameState)
|
||||
}
|
||||
|
||||
function base64ToBytes(base64: string): Uint8Array {
|
||||
@ -149,10 +99,10 @@ function downloadFile(bytes: Uint8Array, fileName: string, mimeType: string) {
|
||||
|
||||
let intervalId = 0
|
||||
onMounted(() => {
|
||||
getTeams(teams)
|
||||
apiGetTeams(teams)
|
||||
|
||||
intervalId = setInterval(() => {
|
||||
getTeams(teams)
|
||||
apiGetTeams(teams)
|
||||
getGame()
|
||||
}, 2000);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type { Ref } from 'vue';
|
||||
import { getApiUrl } from './net';
|
||||
import type { Teams } from './models';
|
||||
import type { Game, Teams } from './models';
|
||||
|
||||
export const getTeams = (teams : Ref<Teams>) => {
|
||||
export const apiGetTeams = (teams: Ref<Teams>) => {
|
||||
fetch(
|
||||
getApiUrl("/teams")
|
||||
)
|
||||
@ -14,3 +14,63 @@ export const getTeams = (teams : Ref<Teams>) => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
}
|
||||
|
||||
export const apiAddTeam = (teamName: Ref<string>) => {
|
||||
fetch(
|
||||
getApiUrl("/teams"),
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"teams": [{ "name": teamName.value }]
|
||||
})
|
||||
}
|
||||
)
|
||||
.then(() => { teamName.value = "" })
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
}
|
||||
|
||||
export const apiGetGame = (game: Ref<Game | undefined>, gameState: Ref<string>) => {
|
||||
fetch(
|
||||
getApiUrl("/game")
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
game.value = data
|
||||
if (data.state === "NEW") {
|
||||
gameState.value = "Игра ещё не началась"
|
||||
}
|
||||
if (data.state === "RUN") {
|
||||
gameState.value = "Игра идет с " + game.value?.startAt.substring(11)
|
||||
}
|
||||
if (data.state === "STOP") {
|
||||
gameState.value = "Игра остановлена " + game.value?.startAt.substring(11) + " - " + game.value?.endAt.substring(11)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
}
|
||||
|
||||
export const apiStartGame = (gameState: Ref<string>) => {
|
||||
gameState.value = "Загрузка..."
|
||||
fetch(
|
||||
getApiUrl("/game/start"),
|
||||
{ method: "POST" }
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
}
|
||||
|
||||
export const apiStopGame = (gameState: Ref<string>) => {
|
||||
gameState.value = "Загрузка..."
|
||||
fetch(
|
||||
getApiUrl("/game/stop"),
|
||||
{ method: "POST" }
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('Ошибка:', error)
|
||||
});
|
||||
}
|
||||
|
@ -15,3 +15,9 @@ export type Team = {
|
||||
export type Teams = {
|
||||
teams: Team[]
|
||||
}
|
||||
|
||||
export type Game = {
|
||||
state: string
|
||||
startAt: string
|
||||
endAt: string
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user