add get team method

This commit is contained in:
2026-03-22 00:52:12 +07:00
parent ccad38799f
commit 614ec9e059
5 changed files with 115 additions and 92 deletions
+31 -40
View File
@@ -1,12 +1,13 @@
<script setup lang="ts">
import { ref, nextTick, watch, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { encodeUTF8ToBase64, getApiUrl } from './utils';
import VueQrcode from '@chenfengyuan/vue-qrcode';
import BeltBlock from './BeltBlock.vue';
import MetalPlate from './MetalPlate.vue';
import GameHeader from './GameHeader.vue';
import type { Action, Door, Team } from './models';
import { apiGetTeam, encodeUTF8ToBase64, getApiUrl } from './client';
import { UnauthorizedError } from './UnauthorizedError';
const router = useRouter();
const route = useRoute();
@@ -39,47 +40,37 @@ const qrOptions = ref<QROptions>({
}
});
function getTeam() {
fetch(
getApiUrl("/team"),
{
method: "GET",
headers: {
"X-Id": encodeUTF8ToBase64(login.value),
"X-Password": password.value
},
async function getTeam() {
let data: Team
try {
data = await apiGetTeam(login.value, password.value)
} catch (error: unknown) {
if (error instanceof UnauthorizedError) {
// Действия при 401:
// Сделать редирект на страницу логина
router.push('/login');
} else {
console.error('Неизвестная ошибка:', error);
}
)
.then(response => {
if (response.status == 401) {
router.push('/login');
return
}
const res = response.json()
return res
})
.then(data => {
const oldActions = team.value.actions
return
}
team.value = data
const newActions = team.value?.actions
newActions.forEach(item => {
item.isOpen = true
})
for (let i = 0; i < actions.value.length; i++) {
newActions[i].isOpen = oldActions[i].isOpen
}
if (actions.value.length !== newActions?.length) {
actions.value = newActions
}
for (let i = 0; i < team.value.actions.length; i++) {
const element = team.value.actions[i];
team.value.actions[i].buttons = element.doors.filter((door: Door) => { return door.show })
}
})
.catch(error => {
console.error('Ошибка:', error)
});
const oldActions = team.value.actions
team.value = data
const newActions = team.value?.actions
newActions.forEach(item => {
item.isOpen = true
})
for (let i = 0; i < actions.value.length; i++) {
newActions[i].isOpen = oldActions[i].isOpen
}
if (actions.value.length !== newActions?.length) {
actions.value = newActions
}
for (let i = 0; i < team.value.actions.length; i++) {
const element = team.value.actions[i];
team.value.actions[i].buttons = element.doors.filter((door: Door) => { return door.show })
}
}
function addAction() {