163 lines
3.7 KiB
Vue
163 lines
3.7 KiB
Vue
<template>
|
|
<div class="app-container">
|
|
<header v-if="isAuthenticated" class="top-bar">
|
|
<div class="user-info-top">
|
|
<span>{{ user.nickname }}</span>
|
|
<span>💰 {{ displayedCoins }}</span>
|
|
<span>✨ {{ displayedExp }}</span>
|
|
<button @click="handleLogout" class="logout-button">Logout</button>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="main-content">
|
|
<slot />
|
|
</main>
|
|
|
|
<footer v-if="isAuthenticated" class="bottom-nav">
|
|
<NuxtLink to="/" class="nav-item">
|
|
<span class="icon">🏠</span>
|
|
<span class="label">Главная</span>
|
|
</NuxtLink>
|
|
<NuxtLink to="/habits" class="nav-item">
|
|
<span class="icon">🎯</span>
|
|
<span class="label">Привычки</span>
|
|
</NuxtLink>
|
|
<NuxtLink to="/village" class="nav-item">
|
|
<span class="icon">🏞️</span>
|
|
<span class="label">Деревня</span>
|
|
</NuxtLink>
|
|
<NuxtLink to="/leaderboard" class="nav-item">
|
|
<span class="icon">🏆</span>
|
|
<span class="label">Лидерборд</span>
|
|
</NuxtLink>
|
|
</footer>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, watch } from 'vue';
|
|
|
|
const { user, isAuthenticated, logout } = useAuth();
|
|
|
|
const handleLogout = async () => {
|
|
await logout();
|
|
};
|
|
|
|
// Refs for the displayed values
|
|
const displayedCoins = ref(user.value?.coins ?? 0);
|
|
const displayedExp = ref(user.value?.exp ?? 0);
|
|
|
|
// Animation function
|
|
const animateValue = (start, end, onUpdate) => {
|
|
if (start === end) return;
|
|
|
|
const range = end - start;
|
|
const increment = range > 0 ? 1 : -1;
|
|
const duration = 500; // Total animation time
|
|
const stepTime = Math.abs(Math.floor(duration / range));
|
|
|
|
let current = start;
|
|
const timer = setInterval(() => {
|
|
current += increment;
|
|
onUpdate(current);
|
|
if (current === end) {
|
|
clearInterval(timer);
|
|
}
|
|
}, stepTime > 0 ? stepTime : 1);
|
|
};
|
|
|
|
// Watch for changes in user's coins and animate
|
|
watch(() => user.value?.coins, (newCoins, oldCoins) => {
|
|
if (newCoins !== undefined && oldCoins !== undefined) {
|
|
animateValue(oldCoins, newCoins, (value) => {
|
|
displayedCoins.value = value;
|
|
});
|
|
} else if (newCoins !== undefined) {
|
|
displayedCoins.value = newCoins;
|
|
}
|
|
});
|
|
|
|
// Watch for changes in user's exp and animate
|
|
watch(() => user.value?.exp, (newExp, oldExp) => {
|
|
if (newExp !== undefined && oldExp !== undefined) {
|
|
animateValue(oldExp, newExp, (value) => {
|
|
displayedExp.value = value;
|
|
});
|
|
} else if (newExp !== undefined) {
|
|
displayedExp.value = newExp;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.app-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.top-bar {
|
|
background-color: #f8f8f8;
|
|
padding: 10px 15px;
|
|
border-bottom: 1px solid #eee;
|
|
display: flex;
|
|
justify-content: flex-end; /* Align user info to the right */
|
|
align-items: center;
|
|
}
|
|
|
|
.user-info-top {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.logout-button {
|
|
background-color: #dc3545;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 0.8em;
|
|
}
|
|
|
|
.main-content {
|
|
flex-grow: 1;
|
|
padding-bottom: 60px; /* Space for bottom nav */
|
|
}
|
|
|
|
.bottom-nav {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
background-color: #fff;
|
|
border-top: 1px solid #eee;
|
|
display: flex;
|
|
justify-content: space-around;
|
|
padding: 5px 0;
|
|
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
|
|
z-index: 1000;
|
|
}
|
|
|
|
.nav-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
text-decoration: none;
|
|
color: #555;
|
|
font-size: 0.7em;
|
|
padding: 5px;
|
|
}
|
|
|
|
.nav-item .icon {
|
|
font-size: 1.5em;
|
|
margin-bottom: 2px;
|
|
}
|
|
|
|
.nav-item.router-link-active {
|
|
color: #007bff;
|
|
}
|
|
</style>
|