From 440e0c2314f11ab98fcf6140010edf17cc3d5f8d Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Mon, 30 Jun 2025 22:48:46 +0700 Subject: [PATCH] add architecture --- src/components/AdminWindow.vue | 37 ++++------------------------------ src/components/client.ts | 16 +++++++++++++++ src/components/models.ts | 17 ++++++++++++++++ 3 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 src/components/client.ts create mode 100644 src/components/models.ts diff --git a/src/components/AdminWindow.vue b/src/components/AdminWindow.vue index 7907897..084a798 100644 --- a/src/components/AdminWindow.vue +++ b/src/components/AdminWindow.vue @@ -3,24 +3,8 @@ import { onMounted, ref } from 'vue'; import { getApiUrl } from './net'; import router from '@/router'; import VueQrcode from '@chenfengyuan/vue-qrcode'; - -type Application = { - id: number - name: string -} - -type Team = { - id: number - name: string - password: string - url: string - spendTime: number - applications: Application[] -} - -type Teams = { - teams: Team[] -} +import type { Teams } from './models'; +import { getTeams } from './client'; type Game = { state: string @@ -36,19 +20,6 @@ const game = ref() const teams = ref({ teams: [] }) -function getTeams() { - fetch( - getApiUrl("/teams") - ) - .then(response => response.json()) - .then(data => { - teams.value = data - }) - .catch(error => { - console.error('Ошибка:', error) - }); -} - function gaveApplication(teamId: number, id: number) { fetch( getApiUrl("/teams/" + teamId + "/applications"), @@ -178,10 +149,10 @@ function downloadFile(bytes: Uint8Array, fileName: string, mimeType: string) { let intervalId = 0 onMounted(() => { - getTeams() + getTeams(teams) intervalId = setInterval(() => { - getTeams() + getTeams(teams) getGame() }, 2000); diff --git a/src/components/client.ts b/src/components/client.ts new file mode 100644 index 0000000..4ea4fdc --- /dev/null +++ b/src/components/client.ts @@ -0,0 +1,16 @@ +import type { Ref } from 'vue'; +import { getApiUrl } from './net'; +import type { Teams } from './models'; + +export const getTeams = (teams : Ref) => { + fetch( + getApiUrl("/teams") + ) + .then(response => response.json()) + .then(data => { + teams.value = data + }) + .catch(error => { + console.error('Ошибка:', error) + }); +} diff --git a/src/components/models.ts b/src/components/models.ts new file mode 100644 index 0000000..13da626 --- /dev/null +++ b/src/components/models.ts @@ -0,0 +1,17 @@ +export type Application = { + id: number + name: string +} + +export type Team = { + id: number + name: string + password: string + url: string + spendTime: number + applications: Application[] +} + +export type Teams = { + teams: Team[] +}