feat: 계정정보 프로필 사진 — 구글 아바타 우선 + 변경/되돌리기
- 아바타 표시 우선순위: 사용자 지정(profileImage) > 구글(googlePicture) > 이니셜 - 사진 변경: 이미지 선택 → 정사각형 크롭·192px 축소(JPEG) → PUT /auth/profile-image - 되돌리기: 사용자 지정 사진 해제 → 구글 사진(없으면 이니셜)으로 폴백 - authApi.updateProfileImage 추가, utils/avatar.js(표시 소스/이니셜/다운스케일) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,69 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { RouterLink, useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { authApi } from '@/api/authApi'
|
||||
import { useDialog } from '@/composables/dialog'
|
||||
import { avatarSrc, avatarInitial, fileToAvatarDataUrl } from '@/utils/avatar'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
const dialog = useDialog()
|
||||
|
||||
const u = computed(() => auth.user || {})
|
||||
const roleLabel = computed(() => (u.value.role === 'ADMIN' ? '관리자' : '일반회원'))
|
||||
const isPremium = computed(() => auth.isPremium)
|
||||
const planLabel = computed(() => (isPremium.value ? '유료 멤버십' : '무료'))
|
||||
|
||||
// 아바타: 사용자 지정 > 구글 > 이니셜
|
||||
const avatar = computed(() => avatarSrc(u.value))
|
||||
const initial = computed(() => avatarInitial(u.value))
|
||||
const hasCustom = computed(() => !!u.value.profileImage)
|
||||
const hasGoogle = computed(() => !!u.value.googlePicture)
|
||||
|
||||
const fileInput = ref(null)
|
||||
const savingImage = ref(false)
|
||||
const imgError = ref('')
|
||||
|
||||
function pickImage() {
|
||||
imgError.value = ''
|
||||
fileInput.value?.click()
|
||||
}
|
||||
|
||||
async function onImageFile(e) {
|
||||
const file = e.target.files?.[0]
|
||||
e.target.value = '' // 같은 파일 다시 선택 가능하도록 초기화
|
||||
if (!file) return
|
||||
savingImage.value = true
|
||||
imgError.value = ''
|
||||
try {
|
||||
const dataUrl = await fileToAvatarDataUrl(file)
|
||||
const updated = await authApi.updateProfileImage(dataUrl)
|
||||
await auth.applyUser(updated)
|
||||
} catch (err) {
|
||||
imgError.value = err.response?.data?.message || '사진 변경에 실패했습니다.'
|
||||
} finally {
|
||||
savingImage.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function resetImage() {
|
||||
const msg = hasGoogle.value
|
||||
? '사용자 지정 사진을 지우고 구글 사진으로 되돌릴까요?'
|
||||
: '사용자 지정 사진을 지울까요?'
|
||||
if (!(await dialog.confirm(msg, { title: '사진 되돌리기' }))) return
|
||||
savingImage.value = true
|
||||
imgError.value = ''
|
||||
try {
|
||||
const updated = await authApi.updateProfileImage(null)
|
||||
await auth.applyUser(updated)
|
||||
} catch (err) {
|
||||
imgError.value = err.response?.data?.message || '사진 되돌리기에 실패했습니다.'
|
||||
} finally {
|
||||
savingImage.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function goEdit() {
|
||||
router.push('/settings/account/edit')
|
||||
}
|
||||
@@ -19,6 +72,30 @@ function goEdit() {
|
||||
<template>
|
||||
<div class="account-info">
|
||||
|
||||
<!-- 프로필 사진 -->
|
||||
<div class="avatar-block">
|
||||
<button type="button" class="avatar-btn" :disabled="savingImage" @click="pickImage" aria-label="프로필 사진 변경">
|
||||
<img v-if="avatar" :src="avatar" class="avatar-img" alt="프로필 사진" referrerpolicy="no-referrer" />
|
||||
<span v-else class="avatar-fallback">{{ initial }}</span>
|
||||
<span class="avatar-cam" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" />
|
||||
<circle cx="12" cy="13" r="4" />
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="avatar-actions">
|
||||
<button type="button" class="link-btn" :disabled="savingImage" @click="pickImage">
|
||||
{{ savingImage ? '처리 중…' : '사진 변경' }}
|
||||
</button>
|
||||
<button v-if="hasCustom" type="button" class="link-btn muted" :disabled="savingImage" @click="resetImage">
|
||||
{{ hasGoogle ? '구글 사진으로' : '기본으로' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="imgError" class="avatar-err">{{ imgError }}</p>
|
||||
<input ref="fileInput" type="file" accept="image/*" class="hidden-file" @change="onImageFile" />
|
||||
</div>
|
||||
|
||||
<section class="card">
|
||||
<div class="row">
|
||||
<span class="k">이름</span>
|
||||
@@ -110,6 +187,95 @@ function goEdit() {
|
||||
font-weight: 600;
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
}
|
||||
.avatar-block {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
.avatar-btn {
|
||||
position: relative;
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-background-soft);
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
overflow: visible;
|
||||
}
|
||||
.avatar-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: default;
|
||||
}
|
||||
.avatar-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.avatar-fallback {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
font-size: 2.2rem;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
background: hsla(160, 100%, 37%, 1);
|
||||
}
|
||||
.avatar-cam {
|
||||
position: absolute;
|
||||
right: -2px;
|
||||
bottom: -2px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
background: hsla(160, 100%, 37%, 1);
|
||||
border: 2px solid var(--color-background);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
}
|
||||
.avatar-cam svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
.avatar-actions {
|
||||
display: flex;
|
||||
gap: 0.85rem;
|
||||
align-items: center;
|
||||
}
|
||||
.link-btn {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
padding: 0.2rem 0.1rem;
|
||||
}
|
||||
.link-btn.muted {
|
||||
color: var(--color-text);
|
||||
opacity: 0.6;
|
||||
}
|
||||
.link-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
.avatar-err {
|
||||
font-size: 0.82rem;
|
||||
color: #c0392b;
|
||||
margin: 0;
|
||||
}
|
||||
.hidden-file {
|
||||
display: none;
|
||||
}
|
||||
.primary-btn {
|
||||
width: 100%;
|
||||
margin-top: 1.25rem;
|
||||
|
||||
Reference in New Issue
Block a user