add architecture
This commit is contained in:
		
							parent
							
								
									901a35f3ab
								
							
						
					
					
						commit
						440e0c2314
					
				@ -3,24 +3,8 @@ 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';
 | 
				
			||||||
type Application = {
 | 
					import { getTeams } from './client';
 | 
				
			||||||
  id: number
 | 
					 | 
				
			||||||
  name: string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Team = {
 | 
					 | 
				
			||||||
  id: number
 | 
					 | 
				
			||||||
  name: string
 | 
					 | 
				
			||||||
  password: string
 | 
					 | 
				
			||||||
  url: string
 | 
					 | 
				
			||||||
  spendTime: number
 | 
					 | 
				
			||||||
  applications: Application[]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Teams = {
 | 
					 | 
				
			||||||
  teams: Team[]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Game = {
 | 
					type Game = {
 | 
				
			||||||
  state: string
 | 
					  state: string
 | 
				
			||||||
@ -36,19 +20,6 @@ const game = ref<Game>()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const teams = ref<Teams>({ teams: [] })
 | 
					const teams = ref<Teams>({ 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) {
 | 
					function gaveApplication(teamId: number, id: number) {
 | 
				
			||||||
  fetch(
 | 
					  fetch(
 | 
				
			||||||
    getApiUrl("/teams/" + teamId + "/applications"),
 | 
					    getApiUrl("/teams/" + teamId + "/applications"),
 | 
				
			||||||
@ -178,10 +149,10 @@ function downloadFile(bytes: Uint8Array, fileName: string, mimeType: string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
let intervalId = 0
 | 
					let intervalId = 0
 | 
				
			||||||
onMounted(() => {
 | 
					onMounted(() => {
 | 
				
			||||||
  getTeams()
 | 
					  getTeams(teams)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  intervalId = setInterval(() => {
 | 
					  intervalId = setInterval(() => {
 | 
				
			||||||
    getTeams()
 | 
					    getTeams(teams)
 | 
				
			||||||
    getGame()
 | 
					    getGame()
 | 
				
			||||||
  }, 2000);
 | 
					  }, 2000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								src/components/client.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/components/client.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import type { Ref } from 'vue';
 | 
				
			||||||
 | 
					import { getApiUrl } from './net';
 | 
				
			||||||
 | 
					import type { Teams } from './models';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getTeams = (teams : Ref<Teams>) => {
 | 
				
			||||||
 | 
					  fetch(
 | 
				
			||||||
 | 
					    getApiUrl("/teams")
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  .then(response => response.json())
 | 
				
			||||||
 | 
					  .then(data => {
 | 
				
			||||||
 | 
					    teams.value = data
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .catch(error => {
 | 
				
			||||||
 | 
					    console.error('Ошибка:', error)
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								src/components/models.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/components/models.ts
									
									
									
									
									
										Normal file
									
								
							@ -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[]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user