This commit is contained in:
Владимир Фёдоров 2025-12-07 23:09:35 +07:00
parent 5b3203e5aa
commit 9bde8ff7ee

View File

@ -1,57 +1,57 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, nextTick, watch, onMounted } from 'vue'; import { ref, nextTick, watch, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { encodeUTF8ToBase64, getApiUrl } from './utils'; import { encodeUTF8ToBase64, getApiUrl } from './utils';
import VueQrcode from '@chenfengyuan/vue-qrcode'; import VueQrcode from '@chenfengyuan/vue-qrcode';
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
type Application = { type Application = {
name: string name: string
} }
type Action = { type Action = {
id: string id: string
place: string place: string
name: string name: string
text: string text: string
applications: Application[] applications: Application[]
} }
type Team = { type Team = {
name: string name: string
actions: Action[] actions: Action[]
} }
const login = ref("") const login = ref("")
const password = ref("") const password = ref("")
const place = ref("") const place = ref("")
const team = ref<Team>({name: "", actions: []}) const team = ref<Team>({ name: "", actions: [] })
const actions = ref<Action[]>([]) const actions = ref<Action[]>([])
const scrollContainer = ref<HTMLDivElement | null>(); const scrollContainer = ref<HTMLDivElement | null>();
const gameState = ref("STOP") const gameState = ref("STOP")
const gameStateText = ref("") const gameStateText = ref("")
const qrurl = ref("-") const qrurl = ref("-")
interface QROptions { interface QROptions {
width?: number; width?: number;
margin?: number; margin?: number;
color?: { color?: {
dark: string; dark: string;
light: string; light: string;
}; };
} }
const qrOptions = ref<QROptions>({ const qrOptions = ref<QROptions>({
width: 200, width: 200,
margin: 1, margin: 1,
color: { color: {
dark: '#303030', dark: '#303030',
light: 'f0f0f0' light: 'f0f0f0'
} }
}); });
function getTeam() { function getTeam() {
fetch( fetch(
getApiUrl("/team"), getApiUrl("/team"),
{ {
@ -67,7 +67,9 @@
router.push('/login'); router.push('/login');
return return
} }
return response.json() const res = response.json()
console.log(res)
return res
}) })
.then(data => { .then(data => {
team.value = data team.value = data
@ -79,9 +81,9 @@
.catch(error => { .catch(error => {
console.error('Ошибка:', error) console.error('Ошибка:', error)
}); });
} }
function addAction() { function addAction() {
const placeValue = place.value.trim() const placeValue = place.value.trim()
if (placeValue === "") { if (placeValue === "") {
place.value = "" place.value = ""
@ -100,10 +102,10 @@
}) })
} }
) )
.then(async () => {place.value = ""}) .then(async () => { place.value = "" })
} }
const scrollToBottom = async (behavior: ScrollBehavior = 'smooth'): Promise<void> => { const scrollToBottom = async (behavior: ScrollBehavior = 'smooth'): Promise<void> => {
await nextTick(); await nextTick();
if (scrollContainer.value) { if (scrollContainer.value) {
scrollContainer.value.scrollTo({ scrollContainer.value.scrollTo({
@ -111,9 +113,9 @@
behavior behavior
}); });
} }
}; };
function getGame() { function getGame() {
qrurl.value = location.href qrurl.value = location.href
fetch( fetch(
getApiUrl("/game") getApiUrl("/game")
@ -134,15 +136,15 @@
.catch(error => { .catch(error => {
console.error('Ошибка:', error) console.error('Ошибка:', error)
}); });
} }
// Автоматическая прокрутка при изменении items // Автоматическая прокрутка при изменении items
watch(actions, () => { watch(actions, () => {
scrollToBottom(); scrollToBottom();
}, { deep: true }); }, { deep: true });
let intervalId = 0 let intervalId = 0
onMounted(() => { onMounted(() => {
login.value = sessionStorage.getItem("teamId") || "" login.value = sessionStorage.getItem("teamId") || ""
password.value = sessionStorage.getItem("password") || "" password.value = sessionStorage.getItem("password") || ""
if (login.value == "") { if (login.value == "") {
@ -157,13 +159,17 @@
intervalId = setInterval(() => { intervalId = setInterval(() => {
getTeam() getTeam()
getGame() getGame()
}, 1000); }, 2000);
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
clearInterval(intervalId); clearInterval(intervalId);
next(); next();
}); });
}); });
// function formatText(text: string) {
// return text.replaceAll(' ', '&nbsp;')
// }
</script> </script>
<template> <template>
@ -181,19 +187,12 @@
<div class="center-block-custom"> <div class="center-block-custom">
<form @submit.prevent="addAction"> <form @submit.prevent="addAction">
<div> <div>
<input <input class="input-custom" v-model="place" type="text" placeholder="Место назначения (А-1, а-1, а1)"
class="input-custom"
v-model="place"
type="text"
placeholder="Место назначения (А-1, а-1, а1)"
:disabled="gameState !== 'RUN'"> :disabled="gameState !== 'RUN'">
</div> </div>
<div class="button-container"> <div class="button-container">
<div class="second-color info-custom">{{ gameStateText }}</div> <div class="second-color info-custom">{{ gameStateText }}</div>
<button <button class="button-custom" type="submit" :disabled="gameState !== 'RUN'">Поехали</button>
class="button-custom"
type="submit"
:disabled="gameState !== 'RUN'">Поехали</button>
</div> </div>
</form> </form>
</div> </div>
@ -205,12 +204,7 @@
<div v-if="!team || !team.actions.length"> <div v-if="!team || !team.actions.length">
<div class="center-message"> <div class="center-message">
<div class="qr"> <div class="qr">
<VueQrcode <VueQrcode :value="qrurl" :options="qrOptions" tag="svg" class="qr-code" />
:value="qrurl"
:options="qrOptions"
tag="svg"
class="qr-code"
/>
<div> <div>
Пора решать загадку Пора решать загадку
</div> </div>
@ -223,11 +217,11 @@
<div class="message-header"> <div class="message-header">
{{ action.place }}: {{ action.name }} {{ action.place }}: {{ action.name }}
</div> </div>
<hr class="hr"/> <hr class="hr" />
<div class="message-content"> <div class="message-content">
{{ action.text }} {{ action.text }}
</div> </div>
<hr class="hr" v-if="action.applications.length"/> <hr class="hr" v-if="action.applications.length" />
<div class="message-footer" v-for="application in action.applications" :key="application.name"> <div class="message-footer" v-for="application in action.applications" :key="application.name">
Приложение: {{ application.name }} Приложение: {{ application.name }}
</div> </div>
@ -298,7 +292,8 @@ body {
.message-content { .message-content {
font-weight: 500; font-weight: 500;
white-space: pre-line; /* white-space: pre-line; */
white-space: pre-wrap;
} }
.message-footer { .message-footer {
@ -332,4 +327,3 @@ body {
width: 200px; width: 200px;
} }
</style> </style>