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