modified: begushiybashkir/bbvue/src/views/Profile.vue

modified:   serv_nginx/api_bb/internal/handlers/user.go
	modified:   serv_nginx/api_bb/internal/routes/routes.go
change url path into back to avatars
This commit is contained in:
2025-10-14 22:45:30 +05:00
parent fe8616a032
commit c01ce8a18c
3 changed files with 270 additions and 72 deletions
+268 -70
View File
@@ -6,13 +6,30 @@
<div v-else-if="user" class="profile-content"> <div v-else-if="user" class="profile-content">
<div class="profile-header"> <div class="profile-header">
<AvatarUpload :user="user" @avatar-updated="onAvatarUpdated" /> <!-- Обновленная секция аватара -->
<div class="avatar-section">
<div class="avatar-preview">
<img
v-if="user.avatar"
:src="avatarUrl"
:alt="`Аватар ${user.firstName} ${user.lastName}`"
class="avatar-image"
@error="handleAvatarError"
>
<div v-else class="avatar-placeholder">
👤
</div>
</div>
<AvatarUpload :user="user" @avatar-updated="onAvatarUpdated" />
</div>
<h2>{{ user.firstName }} {{ user.lastName }}</h2> <h2>{{ user.firstName }} {{ user.lastName }}</h2>
<p>Участник с {{ joinDate }}</p> <p>Участник с {{ joinDate }}</p>
<p class="user-email">{{ user.email }}</p> <p class="user-email">{{ user.email }}</p>
<p v-if="user.phone" class="user-phone">📱 {{ user.phone }}</p> <p v-if="user.phone" class="user-phone">📱 {{ user.phone }}</p>
</div> </div>
<!-- Остальной код остается без изменений -->
<div class="profile-info"> <div class="profile-info">
<h3>📋 Информация о пользователе</h3> <h3>📋 Информация о пользователе</h3>
<div class="info-grid"> <div class="info-grid">
@@ -117,7 +134,8 @@ export default {
data() { data() {
return { return {
authLoading: false, authLoading: false,
statsLoading: false statsLoading: false,
avatarLoadError: false
} }
}, },
computed: { computed: {
@@ -139,6 +157,19 @@ export default {
statsError() { statsError() {
return this.userStore.error return this.userStore.error
}, },
// Вычисляем полный URL аватара
avatarUrl() {
if (!this.user?.avatar) return null;
// Если avatar уже содержит полный URL, возвращаем как есть
if (this.user.avatar.startsWith('http')) {
return this.user.avatar;
}
// Иначе формируем полный URL
const baseUrl = 'https://begushiybashkir.ru/api/v1/user';
return baseUrl + this.user.avatar;
},
joinDate() { joinDate() {
if (!this.user?.createdAt) return 'января 2024'; if (!this.user?.createdAt) return 'января 2024';
@@ -172,74 +203,103 @@ export default {
}, },
methods: { methods: {
async onAvatarUpdated() { async onAvatarUpdated() {
// Сбрасываем флаг ошибки при обновлении аватара
this.avatarLoadError = false;
// Принудительно обновляем профиль // Принудительно обновляем профиль
await this.authStore.fetchProfile() await this.authStore.fetchProfile();
console.log('Avatar updated, user data:', this.authStore.user) console.log('Avatar updated, user data:', this.authStore.user);
}, },
getImageUrl(path) {
const baseUrl = import.meta.env.BASE_URL // Обработчик ошибки загрузки изображения
return `${baseUrl}images/${path}` handleAvatarError() {
console.error('Ошибка загрузки аватара:', this.avatarUrl);
this.avatarLoadError = true;
}, },
async loadUserData() { async loadUserData() {
this.authLoading = true this.authLoading = true;
this.avatarLoadError = false;
try { try {
await this.authStore.fetchProfile() await this.authStore.fetchProfile();
await this.loadStats() await this.loadStats();
} catch (error) { } catch (error) {
console.error('Ошибка загрузки данных:', error) console.error('Ошибка загрузки данных:', error);
} finally { } finally {
this.authLoading = false this.authLoading = false;
} }
}, },
async loadStats() { async loadStats() {
this.statsLoading = true this.statsLoading = true;
try { try {
const [statsResult, achievementsResult] = await Promise.all([ const [statsResult, achievementsResult] = await Promise.all([
this.userStore.fetchUserStats(), this.userStore.fetchUserStats(),
this.userStore.fetchUserAchievements() this.userStore.fetchUserAchievements()
]) ]);
// Проверяем результаты
if (!statsResult.success) { if (!statsResult.success) {
console.error('Ошибка загрузки статистики:', statsResult.error) console.error('Ошибка загрузки статистики:', statsResult.error);
} }
if (!achievementsResult.success) { if (!achievementsResult.success) {
console.error('Ошибка загрузки достижений:', achievementsResult.error) console.error('Ошибка загрузки достижений:', achievementsResult.error);
} }
} catch (error) { } catch (error) {
console.error('Ошибка загрузки статистики:', error) console.error('Ошибка загрузки статистики:', error);
} finally { } finally {
this.statsLoading = false this.statsLoading = false;
} }
}, },
async refreshStats() {
await this.loadStats();
},
async handleLogout() { async handleLogout() {
await this.authStore.logout() await this.authStore.logout();
this.$router.push('/') this.$router.push('/');
}, },
editProfile() { editProfile() {
this.$router.push('/profile/edit') this.$router.push('/profile/edit');
}, },
viewDetailedStats() { viewDetailedStats() {
// TODO: Переход на страницу детальной статистики // TODO: Переход на страницу детальной статистики
alert('Функция в разработке') alert('Функция в разработке');
} }
}, },
async mounted() { async mounted() {
if (!this.user) { if (!this.user) {
await this.loadUserData() await this.loadUserData();
} else { } else {
await this.loadStats() await this.loadStats();
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
/* Существующие стили остаются */ .page {
max-width: 800px;
margin: 0 auto;
padding: 2rem;
}
.profile-content {
margin-top: 2rem;
}
.profile-header {
text-align: center;
margin-bottom: 3rem;
padding: 2rem;
background: white;
border-radius: 15px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.avatar-section { .avatar-section {
text-align: center; margin-bottom: 1.5rem;
margin-bottom: 2rem;
} }
.avatar-preview { .avatar-preview {
@@ -249,13 +309,19 @@ export default {
border-radius: 50%; border-radius: 50%;
overflow: hidden; overflow: hidden;
border: 4px solid #2e8b57; border: 4px solid #2e8b57;
background-color: #f5f5f5; background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
} }
.avatar-image { .avatar-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
object-fit: cover; object-fit: cover;
transition: transform 0.3s ease;
}
.avatar-image:hover {
transform: scale(1.05);
} }
.avatar-placeholder { .avatar-placeholder {
@@ -265,7 +331,62 @@ export default {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
font-size: 4rem; font-size: 4rem;
background-color: #e0e0e0; background: linear-gradient(135deg, #2e8b57, #3cb371);
color: white;
}
.profile-header h2 {
margin: 1rem 0 0.5rem;
color: #333;
font-size: 1.8rem;
}
.user-email, .user-phone {
color: #666;
margin: 0.25rem 0;
}
.profile-info, .profile-stats, .achievements-preview {
background: white;
padding: 1.5rem;
border-radius: 15px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 2rem;
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
margin-top: 1rem;
}
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem;
background: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #2e8b57;
}
.info-item label {
font-weight: 600;
color: #555;
}
.info-value {
color: #333;
font-weight: 500;
}
.role-badge {
background: #2e8b57;
color: white;
padding: 0.25rem 0.75rem;
border-radius: 20px;
font-size: 0.85rem;
} }
.stats-header { .stats-header {
@@ -280,13 +401,16 @@ export default {
border: none; border: none;
font-size: 1.2rem; font-size: 1.2rem;
cursor: pointer; cursor: pointer;
padding: 5px; padding: 8px;
border-radius: 50%; border-radius: 50%;
transition: background-color 0.3s; transition: all 0.3s ease;
background-color: #f8f9fa;
} }
.btn-refresh:hover:not(:disabled) { .btn-refresh:hover:not(:disabled) {
background-color: #f0f0f0; background-color: #2e8b57;
color: white;
transform: rotate(90deg);
} }
.btn-refresh:disabled { .btn-refresh:disabled {
@@ -294,12 +418,42 @@ export default {
opacity: 0.5; opacity: 0.5;
} }
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1rem;
margin: 1.5rem 0;
}
.stat-card {
background: linear-gradient(135deg, #f8f9fa, #e9ecef);
padding: 1.5rem 1rem;
border-radius: 12px;
text-align: center;
border: 2px solid #e9ecef;
transition: all 0.3s ease;
}
.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
border-color: #2e8b57;
}
.stat-card h4 {
margin: 0 0 0.5rem;
color: #555;
font-size: 0.9rem;
}
.stat-card p {
margin: 0;
font-size: 1.5rem;
font-weight: bold;
color: #2e8b57;
}
.achievements-preview { .achievements-preview {
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 2rem;
text-align: center; text-align: center;
} }
@@ -308,25 +462,63 @@ export default {
align-items: center; align-items: center;
gap: 1rem; gap: 1rem;
margin: 1rem 0; margin: 1rem 0;
justify-content: center;
} }
.progress-bar { .progress-bar {
flex: 1; flex: 1;
height: 8px; max-width: 300px;
height: 12px;
background-color: #e0e0e0; background-color: #e0e0e0;
border-radius: 4px; border-radius: 6px;
overflow: hidden; overflow: hidden;
} }
.progress-fill { .progress-fill {
height: 100%; height: 100%;
background-color: #2e8b57; background: linear-gradient(90deg, #2e8b57, #3cb371);
transition: width 0.3s ease; transition: width 0.5s ease;
} }
.achievements-count { .achievements-count {
margin: 1rem 0; margin: 1rem 0;
color: #666; color: #666;
font-weight: 500;
}
.profile-actions {
display: flex;
flex-direction: column;
gap: 1rem;
max-width: 300px;
margin: 2rem auto;
}
.btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 8px;
background: #2e8b57;
color: white;
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
text-align: center;
}
.btn:hover:not(:disabled) {
background: #26734d;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(46, 139, 87, 0.3);
}
.btn:disabled {
background-color: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
} }
.btn-outline { .btn-outline {
@@ -340,33 +532,8 @@ export default {
color: white; color: white;
} }
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1rem;
margin: 1.5rem 0;
}
.stat-card {
background: white;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
text-align: center;
border: 1px solid #e0e0e0;
}
.profile-actions {
display: flex;
flex-direction: column;
gap: 1rem;
max-width: 300px;
margin: 2rem auto;
}
.btn-logout { .btn-logout {
background-color: #dc3545; background-color: #dc3545;
color: white;
margin-top: 1rem; margin-top: 1rem;
} }
@@ -374,9 +541,13 @@ export default {
background-color: #c82333; background-color: #c82333;
} }
.btn-logout:disabled { .btn-secondary {
background-color: #ccc; background-color: #6c757d;
cursor: not-allowed; margin-top: 2rem;
}
.btn-secondary:hover {
background-color: #545b62;
} }
.error-message { .error-message {
@@ -396,8 +567,22 @@ export default {
color: #666; color: #666;
} }
.link {
color: #2e8b57;
text-decoration: none;
font-weight: 600;
}
.link:hover {
text-decoration: underline;
}
/* Адаптивность */ /* Адаптивность */
@media (max-width: 768px) { @media (max-width: 768px) {
.page {
padding: 1rem;
}
.info-grid { .info-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
@@ -414,11 +599,24 @@ export default {
flex-direction: column; flex-direction: column;
gap: 0.5rem; gap: 0.5rem;
} }
.avatar-preview {
width: 120px;
height: 120px;
}
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.stats-grid { .stats-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.profile-header {
padding: 1.5rem;
}
.profile-header h2 {
font-size: 1.5rem;
}
} }
</style> </style>
+1 -1
View File
@@ -39,7 +39,7 @@ func (h *UserHandler) Routes() chi.Router {
r.Get("/profile", h.GetProfile) r.Get("/profile", h.GetProfile)
r.Post("/editProfile", h.UpdateProfile) r.Post("/editProfile", h.UpdateProfile)
r.Get("/avatar/{filename}", h.ServeAvatar) r.Get("/avatars/{filename}", h.ServeAvatar)
return r return r
} }
+1 -1
View File
@@ -58,7 +58,7 @@ func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
r.Mount("/", allHandler.UserHandler().Routes()) r.Mount("/", allHandler.UserHandler().Routes())
r.Mount("/avatar", allHandler.AvatarHandler().Routes()) r.Mount("/avatars", allHandler.AvatarHandler().Routes())
// Здесь будут другие защищенные маршруты пользователя // Здесь будут другие защищенные маршруты пользователя
}) })