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:
@@ -6,13 +6,30 @@
|
||||
|
||||
<div v-else-if="user" class="profile-content">
|
||||
<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>
|
||||
<p>Участник с {{ joinDate }}</p>
|
||||
<p class="user-email">{{ user.email }}</p>
|
||||
<p v-if="user.phone" class="user-phone">📱 {{ user.phone }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Остальной код остается без изменений -->
|
||||
<div class="profile-info">
|
||||
<h3>📋 Информация о пользователе</h3>
|
||||
<div class="info-grid">
|
||||
@@ -117,7 +134,8 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
authLoading: false,
|
||||
statsLoading: false
|
||||
statsLoading: false,
|
||||
avatarLoadError: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -139,6 +157,19 @@ export default {
|
||||
statsError() {
|
||||
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() {
|
||||
if (!this.user?.createdAt) return 'января 2024';
|
||||
|
||||
@@ -172,74 +203,103 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async onAvatarUpdated() {
|
||||
// Сбрасываем флаг ошибки при обновлении аватара
|
||||
this.avatarLoadError = false;
|
||||
// Принудительно обновляем профиль
|
||||
await this.authStore.fetchProfile()
|
||||
console.log('Avatar updated, user data:', this.authStore.user)
|
||||
await this.authStore.fetchProfile();
|
||||
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() {
|
||||
this.authLoading = true
|
||||
this.authLoading = true;
|
||||
this.avatarLoadError = false;
|
||||
try {
|
||||
await this.authStore.fetchProfile()
|
||||
await this.loadStats()
|
||||
await this.authStore.fetchProfile();
|
||||
await this.loadStats();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки данных:', error)
|
||||
console.error('Ошибка загрузки данных:', error);
|
||||
} finally {
|
||||
this.authLoading = false
|
||||
this.authLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadStats() {
|
||||
this.statsLoading = true
|
||||
this.statsLoading = true;
|
||||
try {
|
||||
const [statsResult, achievementsResult] = await Promise.all([
|
||||
this.userStore.fetchUserStats(),
|
||||
this.userStore.fetchUserAchievements()
|
||||
])
|
||||
]);
|
||||
|
||||
// Проверяем результаты
|
||||
if (!statsResult.success) {
|
||||
console.error('Ошибка загрузки статистики:', statsResult.error)
|
||||
console.error('Ошибка загрузки статистики:', statsResult.error);
|
||||
}
|
||||
if (!achievementsResult.success) {
|
||||
console.error('Ошибка загрузки достижений:', achievementsResult.error)
|
||||
console.error('Ошибка загрузки достижений:', achievementsResult.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки статистики:', error)
|
||||
console.error('Ошибка загрузки статистики:', error);
|
||||
} finally {
|
||||
this.statsLoading = false
|
||||
this.statsLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async refreshStats() {
|
||||
await this.loadStats();
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
await this.authStore.logout()
|
||||
this.$router.push('/')
|
||||
await this.authStore.logout();
|
||||
this.$router.push('/');
|
||||
},
|
||||
|
||||
editProfile() {
|
||||
this.$router.push('/profile/edit')
|
||||
this.$router.push('/profile/edit');
|
||||
},
|
||||
|
||||
viewDetailedStats() {
|
||||
// TODO: Переход на страницу детальной статистики
|
||||
alert('Функция в разработке')
|
||||
alert('Функция в разработке');
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
if (!this.user) {
|
||||
await this.loadUserData()
|
||||
await this.loadUserData();
|
||||
} else {
|
||||
await this.loadStats()
|
||||
await this.loadStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<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 {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.avatar-preview {
|
||||
@@ -249,13 +309,19 @@ export default {
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
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 {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.avatar-image:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.avatar-placeholder {
|
||||
@@ -265,7 +331,62 @@ export default {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
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 {
|
||||
@@ -280,13 +401,16 @@ export default {
|
||||
border: none;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
padding: 5px;
|
||||
padding: 8px;
|
||||
border-radius: 50%;
|
||||
transition: background-color 0.3s;
|
||||
transition: all 0.3s ease;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.btn-refresh:hover:not(:disabled) {
|
||||
background-color: #f0f0f0;
|
||||
background-color: #2e8b57;
|
||||
color: white;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.btn-refresh:disabled {
|
||||
@@ -294,12 +418,42 @@ export default {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -308,25 +462,63 @@ export default {
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin: 1rem 0;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
flex: 1;
|
||||
height: 8px;
|
||||
max-width: 300px;
|
||||
height: 12px;
|
||||
background-color: #e0e0e0;
|
||||
border-radius: 4px;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #2e8b57;
|
||||
transition: width 0.3s ease;
|
||||
background: linear-gradient(90deg, #2e8b57, #3cb371);
|
||||
transition: width 0.5s ease;
|
||||
}
|
||||
|
||||
.achievements-count {
|
||||
margin: 1rem 0;
|
||||
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 {
|
||||
@@ -340,33 +532,8 @@ export default {
|
||||
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 {
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
@@ -374,9 +541,13 @@ export default {
|
||||
background-color: #c82333;
|
||||
}
|
||||
|
||||
.btn-logout:disabled {
|
||||
background-color: #ccc;
|
||||
cursor: not-allowed;
|
||||
.btn-secondary {
|
||||
background-color: #6c757d;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: #545b62;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
@@ -396,8 +567,22 @@ export default {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #2e8b57;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Адаптивность */
|
||||
@media (max-width: 768px) {
|
||||
.page {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
@@ -414,11 +599,24 @@ export default {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.avatar-preview {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.stats-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.profile-header {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.profile-header h2 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -39,7 +39,7 @@ func (h *UserHandler) Routes() chi.Router {
|
||||
|
||||
r.Get("/profile", h.GetProfile)
|
||||
r.Post("/editProfile", h.UpdateProfile)
|
||||
r.Get("/avatar/{filename}", h.ServeAvatar)
|
||||
r.Get("/avatars/{filename}", h.ServeAvatar)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
||||
|
||||
r.Mount("/", allHandler.UserHandler().Routes())
|
||||
|
||||
r.Mount("/avatar", allHandler.AvatarHandler().Routes())
|
||||
r.Mount("/avatars", allHandler.AvatarHandler().Routes())
|
||||
|
||||
// Здесь будут другие защищенные маршруты пользователя
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user