init
This commit is contained in:
@@ -0,0 +1,718 @@
|
||||
<template>
|
||||
<div class="club-management">
|
||||
<div class="header">
|
||||
<h2>클럽 관리</h2>
|
||||
<Button label="새 클럽 추가" icon="pi pi-plus" @click="openNewClubDialog" />
|
||||
</div>
|
||||
|
||||
<DataTable :value="clubs" :paginator="true" :rows="10"
|
||||
:rowsPerPageOptions="[5, 10, 20]"
|
||||
stripedRows responsiveLayout="scroll"
|
||||
:loading="loading">
|
||||
<Column field="id" header="ID" sortable style="width: 5%"></Column>
|
||||
<Column field="name" header="클럽명" sortable style="width: 20%">
|
||||
<template #body="slotProps">
|
||||
<div>
|
||||
<div class="club-name">{{ slotProps.data.name }}</div>
|
||||
<div class="club-location">{{ slotProps.data.location }}</div>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="owner.name" header="모임장" sortable style="width: 15%">
|
||||
<template #body="slotProps">
|
||||
{{ slotProps.data.owner?.name || '-' }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="memberCount" header="회원 수" sortable style="width: 10%"></Column>
|
||||
<Column field="createdAt" header="생성일" sortable style="width: 15%">
|
||||
<template #body="slotProps">
|
||||
{{ formatDate(slotProps.data.createdAt) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="관리" style="width: 20%">
|
||||
<template #body="slotProps">
|
||||
<Button icon="pi pi-pencil" class="p-button-rounded p-button-success mr-2"
|
||||
@click="editClub(slotProps.data)" />
|
||||
<Button icon="pi pi-cog" class="p-button-rounded p-button-info mr-2"
|
||||
@click="manageFeatures(slotProps.data)" />
|
||||
<Button icon="pi pi-users" class="p-button-rounded p-button-warning mr-2"
|
||||
@click="manageMembers(slotProps.data)" />
|
||||
<Button icon="pi pi-trash" class="p-button-rounded p-button-danger"
|
||||
@click="confirmDeleteClub(slotProps.data)" />
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
|
||||
<!-- 새 클럽 추가/수정 다이얼로그 -->
|
||||
<Dialog v-model:visible="clubDialog" :style="{width: '450px'}"
|
||||
:header="dialogMode === 'new' ? '새 클럽 추가' : '클럽 수정'"
|
||||
:modal="true" class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="name">클럽명</label>
|
||||
<InputText id="name" v-model="club.name" required autofocus :class="{'p-invalid': submitted && !club.name}" />
|
||||
<small class="p-error" v-if="submitted && !club.name">클럽명은 필수입니다.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="description">클럽 설명</label>
|
||||
<Textarea id="description" v-model="club.description" rows="3" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="ownerEmail">모임장 이메일</label>
|
||||
<InputText id="ownerEmail" v-model="club.ownerEmail" required :class="{'p-invalid': submitted && !club.ownerEmail}" />
|
||||
<small class="p-error" v-if="submitted && !club.ownerEmail">모임장 이메일은 필수입니다.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="location">볼링장</label>
|
||||
<InputText id="location" v-model="club.location" />
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="취소" icon="pi pi-times" class="p-button-text" @click="hideDialog" />
|
||||
<Button label="저장" icon="pi pi-check" class="p-button-text" @click="saveClub" :loading="saving" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 기능 관리 다이얼로그 -->
|
||||
<Dialog v-model:visible="featureDialog" :style="{width: '500px'}"
|
||||
header="클럽 기능 관리" :modal="true">
|
||||
<div v-if="selectedClub">
|
||||
<h3>{{ selectedClub.name }} - 기능 관리</h3>
|
||||
|
||||
<div v-for="feature in clubFeatures" :key="feature.id" class="feature-item">
|
||||
<div class="feature-header">
|
||||
<h4>{{ feature.name }}</h4>
|
||||
<div class="feature-toggle">
|
||||
<span>{{ feature.enabled ? '활성화됨' : '비활성화됨' }}</span>
|
||||
<Button :icon="feature.enabled ? 'pi pi-check' : 'pi pi-times'"
|
||||
:class="feature.enabled ? 'p-button-success' : 'p-button-secondary'"
|
||||
@click="toggleFeature(feature)" />
|
||||
</div>
|
||||
</div>
|
||||
<p>{{ feature.description }}</p>
|
||||
<p class="feature-price">월 {{ feature.price.toLocaleString() }}원</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="닫기" icon="pi pi-times" class="p-button-text" @click="featureDialog = false" />
|
||||
<Button label="저장" icon="pi pi-check" @click="saveFeatures" :loading="savingFeatures" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 회원 관리 다이얼로그 -->
|
||||
<Dialog v-model:visible="memberDialog" :style="{width: '800px'}"
|
||||
header="회원 관리" :modal="true">
|
||||
<div v-if="selectedClub">
|
||||
<h3>{{ selectedClub.name }} - 회원 관리</h3>
|
||||
|
||||
<div class="mb-3">
|
||||
<Button label="새 회원 추가" icon="pi pi-plus" @click="openNewMemberDialog" />
|
||||
</div>
|
||||
|
||||
<DataTable :value="clubMembers" :paginator="true" :rows="10"
|
||||
:rowsPerPageOptions="[5, 10, 20]"
|
||||
stripedRows
|
||||
scrollable scrollHeight="400px"
|
||||
:loading="loadingMembers">
|
||||
<Column field="name" header="이름" sortable style="min-width: 12rem">
|
||||
<template #body="slotProps">
|
||||
<div>
|
||||
<div class="member-name">{{ slotProps.data.name }}</div>
|
||||
<div class="member-contact">
|
||||
<div>{{ slotProps.data.phone }}</div>
|
||||
<div>{{ slotProps.data.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="gender" header="성별" sortable style="min-width: 6rem"></Column>
|
||||
<Column field="memberType" header="회원 유형" sortable style="min-width: 8rem">
|
||||
<template #body="slotProps">
|
||||
<Dropdown v-model="slotProps.data.memberType"
|
||||
:options="memberTypes"
|
||||
@change="updateMemberType(slotProps.data)"
|
||||
:disabled="slotProps.data.memberType === '모임장' && !canChangeOwner" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="handicap" header="핸디캡" sortable style="min-width: 6rem"></Column>
|
||||
<Column field="average" header="평균" sortable style="min-width: 6rem">
|
||||
<template #body="slotProps">
|
||||
{{ slotProps.data.average.toFixed(1) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="games" header="게임 수" sortable style="min-width: 6rem"></Column>
|
||||
<Column field="joinDate" header="가입일" sortable style="min-width: 8rem">
|
||||
<template #body="slotProps">
|
||||
{{ formatDate(slotProps.data.joinDate) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="관리" style="min-width: 8rem">
|
||||
<template #body="slotProps">
|
||||
<Button icon="pi pi-pencil"
|
||||
class="p-button-rounded p-button-success mr-2"
|
||||
@click="editMember(slotProps.data)" />
|
||||
<Button icon="pi pi-trash"
|
||||
class="p-button-rounded p-button-danger"
|
||||
@click="confirmDeleteMember(slotProps.data)"
|
||||
:disabled="slotProps.data.memberType === '모임장'" />
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<!-- 회원 추가/수정 다이얼로그 -->
|
||||
<Dialog v-model:visible="memberFormDialog" :style="{width: '450px'}"
|
||||
:header="memberDialogMode === 'new' ? '새 회원 추가' : '회원 정보 수정'"
|
||||
:modal="true" class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="name">이름</label>
|
||||
<InputText id="name" v-model="member.name" required autofocus :class="{'p-invalid': memberSubmitted && !member.name}" />
|
||||
<small class="p-error" v-if="memberSubmitted && !member.name">이름은 필수입니다.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="gender">성별</label>
|
||||
<Dropdown id="gender" v-model="member.gender"
|
||||
:options="['남성', '여성']" placeholder="성별 선택"
|
||||
:class="{'p-invalid': memberSubmitted && !member.gender}" />
|
||||
<small class="p-error" v-if="memberSubmitted && !member.gender">성별은 필수입니다.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="memberType">회원 유형</label>
|
||||
<Dropdown id="memberType" v-model="member.memberType"
|
||||
:options="memberTypes" placeholder="회원 유형 선택"
|
||||
:class="{'p-invalid': memberSubmitted && !member.memberType}" />
|
||||
<small class="p-error" v-if="memberSubmitted && !member.memberType">회원 유형은 필수입니다.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="handicap">핸디캡</label>
|
||||
<InputNumber id="handicap" v-model="member.handicap" :min="0" :max="300" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="phone">연락처</label>
|
||||
<InputText id="phone" v-model="member.phone" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="email">이메일</label>
|
||||
<InputText id="email" v-model="member.email" type="email" />
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="취소" icon="pi pi-times" class="p-button-text" @click="memberFormDialog = false" />
|
||||
<Button label="저장" icon="pi pi-check" class="p-button-text" @click="saveMember" :loading="savingMember" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 삭제 확인 다이얼로그 -->
|
||||
<Dialog v-model:visible="deleteDialog" :style="{width: '450px'}"
|
||||
header="클럽 삭제" :modal="true">
|
||||
<div class="confirmation-content">
|
||||
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
|
||||
<span v-if="selectedClub">정말로 <b>{{ selectedClub.name }}</b> 클럽을 삭제하시겠습니까?</span>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="아니오" icon="pi pi-times" class="p-button-text" @click="deleteDialog = false" />
|
||||
<Button label="예" icon="pi pi-check" class="p-button-text" @click="deleteClub" :loading="deleting" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 회원 삭제 확인 다이얼로그 -->
|
||||
<Dialog v-model:visible="deleteMemberDialog" :style="{width: '450px'}"
|
||||
header="회원 삭제" :modal="true">
|
||||
<div class="confirmation-content">
|
||||
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
|
||||
<span v-if="selectedMember">정말로 <b>{{ selectedMember.name }}</b> 회원을 삭제하시겠습니까?</span>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="아니오" icon="pi pi-times" class="p-button-text" @click="deleteMemberDialog = false" />
|
||||
<Button label="예" icon="pi pi-check" class="p-button-text" @click="deleteMember" :loading="deletingMember" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<Toast />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import dayjs from 'dayjs';
|
||||
import adminService from '@/services/adminService';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
// 상태 변수
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const savingFeatures = ref(false);
|
||||
const deleting = ref(false);
|
||||
const loadingMembers = ref(false);
|
||||
const deletingMember = ref(false);
|
||||
const savingMember = ref(false);
|
||||
const submitted = ref(false);
|
||||
const memberSubmitted = ref(false);
|
||||
|
||||
// 클럽 목록
|
||||
const clubs = ref([]);
|
||||
const clubMembers = ref([]);
|
||||
|
||||
// 회원 유형 목록
|
||||
const memberTypes = ref(['모임장', '정회원', '준회원', '운영진']);
|
||||
|
||||
// 기능 목록
|
||||
const allFeatures = ref([
|
||||
{ id: 1, name: '회원 관리', description: '클럽 회원 목록 관리 및 회원 정보 수정', price: 5000 },
|
||||
{ id: 2, name: '정기 모임 관리', description: '정기 모임 일정 및 참석자 관리', price: 8000 },
|
||||
{ id: 3, name: '점수 관리', description: '게임별 점수 기록 및 통계', price: 10000 },
|
||||
{ id: 4, name: '팀 관리', description: '팀 구성 및 팀별 점수 관리', price: 7000 },
|
||||
{ id: 5, name: '통계 대시보드', description: '상세한 통계 및 분석 대시보드', price: 12000 }
|
||||
]);
|
||||
|
||||
// 현재 클럽의 기능 목록
|
||||
const clubFeatures = ref([]);
|
||||
|
||||
// 다이얼로그 상태
|
||||
const clubDialog = ref(false);
|
||||
const featureDialog = ref(false);
|
||||
const deleteDialog = ref(false);
|
||||
const memberDialog = ref(false);
|
||||
const memberFormDialog = ref(false);
|
||||
const deleteMemberDialog = ref(false);
|
||||
const dialogMode = ref('new');
|
||||
const memberDialogMode = ref('new');
|
||||
|
||||
// 선택된 클럽 및 편집중인 클럽 데이터
|
||||
const selectedClub = ref(null);
|
||||
const selectedMember = ref(null);
|
||||
const club = reactive({
|
||||
id: null,
|
||||
name: '',
|
||||
description: '',
|
||||
ownerEmail: '',
|
||||
location: '',
|
||||
memberCount: 0,
|
||||
createdAt: ''
|
||||
});
|
||||
|
||||
// 편집중인 회원 데이터
|
||||
const member = reactive({
|
||||
id: null,
|
||||
name: '',
|
||||
gender: null,
|
||||
memberType: null,
|
||||
handicap: 0,
|
||||
phone: '',
|
||||
email: ''
|
||||
});
|
||||
|
||||
// 모임장 변경 권한
|
||||
const canChangeOwner = ref(true);
|
||||
|
||||
// 페이지 로드 시 클럽 목록 가져오기
|
||||
onMounted(async () => {
|
||||
await fetchClubs();
|
||||
});
|
||||
|
||||
// 클럽 목록 가져오기
|
||||
const fetchClubs = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await adminService.getAllClubs();
|
||||
clubs.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('클럽 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 날짜 포맷팅
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '';
|
||||
return dayjs(date).format('YYYY-MM-DD');
|
||||
};
|
||||
|
||||
// 새 클럽 추가 다이얼로그 열기
|
||||
const openNewClubDialog = () => {
|
||||
club.id = null;
|
||||
club.name = '';
|
||||
club.description = '';
|
||||
club.ownerEmail = '';
|
||||
club.location = '';
|
||||
submitted.value = false;
|
||||
dialogMode.value = 'new';
|
||||
clubDialog.value = true;
|
||||
};
|
||||
|
||||
// 클럽 수정 다이얼로그 열기
|
||||
const editClub = async (data) => {
|
||||
dialogMode.value = 'edit';
|
||||
selectedClub.value = { ...data };
|
||||
|
||||
try {
|
||||
// 클럽 상세 정보 가져오기
|
||||
const response = await adminService.getClubById(data.id);
|
||||
const clubData = response.data;
|
||||
|
||||
club.id = clubData.id;
|
||||
club.name = clubData.name;
|
||||
club.description = clubData.description;
|
||||
club.ownerEmail = clubData.owner?.email; // owner 객체에서 이메일 가져오기
|
||||
club.location = clubData.location;
|
||||
club.memberCount = clubData.memberCount;
|
||||
club.createdAt = clubData.createdAt;
|
||||
|
||||
clubDialog.value = true;
|
||||
} catch (error) {
|
||||
console.error('클럽 정보를 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 정보를 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 다이얼로그 닫기
|
||||
const hideDialog = () => {
|
||||
clubDialog.value = false;
|
||||
submitted.value = false;
|
||||
};
|
||||
|
||||
// 클럽 저장
|
||||
const saveClub = async () => {
|
||||
submitted.value = true;
|
||||
|
||||
if (!club.name || !club.ownerEmail) {
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '필수 항목을 모두 입력해주세요.', life: 3000 });
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
|
||||
try {
|
||||
if (dialogMode.value === 'new') {
|
||||
// 새 클럽 추가
|
||||
const clubData = {
|
||||
name: club.name,
|
||||
description: club.description,
|
||||
ownerEmail: club.ownerEmail,
|
||||
location: club.location
|
||||
};
|
||||
|
||||
await adminService.createClub(clubData);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '클럽이 추가되었습니다.', life: 3000 });
|
||||
} else {
|
||||
// 클럽 수정
|
||||
await adminService.updateClub(club.id, club);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '클럽이 수정되었습니다.', life: 3000 });
|
||||
}
|
||||
|
||||
clubDialog.value = false;
|
||||
await fetchClubs();
|
||||
} catch (error) {
|
||||
console.error('클럽 저장 중 오류 발생:', error);
|
||||
let errorMessage = '클럽 저장 중 오류가 발생했습니다.';
|
||||
|
||||
if (error.response && error.response.data && error.response.data.message) {
|
||||
errorMessage = error.response.data.message;
|
||||
}
|
||||
|
||||
toast.add({ severity: 'error', summary: '오류', detail: errorMessage, life: 3000 });
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 기능 관리 다이얼로그 열기
|
||||
const manageFeatures = async (data) => {
|
||||
selectedClub.value = { ...data };
|
||||
|
||||
try {
|
||||
// 클럽의 현재 기능 목록 가져오기
|
||||
const response = await adminService.getClubById(data.id);
|
||||
const clubData = response.data;
|
||||
|
||||
// 모든 기능을 복사하고 활성화 상태 설정
|
||||
clubFeatures.value = allFeatures.value.map(feature => {
|
||||
const isEnabled = clubData.features && clubData.features.some(f => f.id === feature.id);
|
||||
return { ...feature, enabled: isEnabled };
|
||||
});
|
||||
|
||||
featureDialog.value = true;
|
||||
} catch (error) {
|
||||
console.error('클럽 기능 정보를 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 기능 정보를 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 기능 토글
|
||||
const toggleFeature = (feature) => {
|
||||
feature.enabled = !feature.enabled;
|
||||
};
|
||||
|
||||
// 기능 설정 저장
|
||||
const saveFeatures = async () => {
|
||||
if (!selectedClub.value) return;
|
||||
|
||||
savingFeatures.value = true;
|
||||
|
||||
try {
|
||||
// 활성화된 기능만 필터링
|
||||
const enabledFeatures = clubFeatures.value
|
||||
.filter(feature => feature.enabled)
|
||||
.map(feature => ({ id: feature.id, name: feature.name }));
|
||||
|
||||
// 기능 업데이트 API 호출
|
||||
await adminService.manageClubFeatures(selectedClub.value.id, enabledFeatures);
|
||||
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '클럽 기능이 업데이트되었습니다.', life: 3000 });
|
||||
featureDialog.value = false;
|
||||
|
||||
// 클럽 목록 새로고침
|
||||
await fetchClubs();
|
||||
} catch (error) {
|
||||
console.error('클럽 기능 저장 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 기능 저장 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
savingFeatures.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 회원 관리 다이얼로그 열기
|
||||
const manageMembers = async (data) => {
|
||||
selectedClub.value = data;
|
||||
loadingMembers.value = true;
|
||||
memberDialog.value = true;
|
||||
|
||||
try {
|
||||
const response = await adminService.getClubMembers(data.id);
|
||||
clubMembers.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('회원 목록 조회 오류:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '회원 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
loadingMembers.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 회원 유형 업데이트
|
||||
const updateMemberType = async (member) => {
|
||||
try {
|
||||
if (!selectedClub.value || !selectedClub.value.id) {
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '선택된 클럽 정보가 없습니다.', life: 3000 });
|
||||
return;
|
||||
}
|
||||
|
||||
const clubId = parseInt(selectedClub.value.id);
|
||||
const memberId = parseInt(member.id);
|
||||
|
||||
const response = await adminService.updateClubMember(clubId, memberId, {
|
||||
memberType: member.memberType
|
||||
});
|
||||
|
||||
// 응답 데이터로 회원 정보 업데이트
|
||||
const index = clubMembers.value.findIndex(m => m.id === memberId);
|
||||
if (index !== -1) {
|
||||
clubMembers.value[index] = response.data;
|
||||
}
|
||||
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '회원 유형이 업데이트되었습니다.', life: 3000 });
|
||||
} catch (error) {
|
||||
console.error('회원 유형 업데이트 오류:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '회원 유형을 업데이트하는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 회원 삭제 확인
|
||||
const confirmDeleteMember = (member) => {
|
||||
selectedMember.value = member;
|
||||
deleteMemberDialog.value = true;
|
||||
};
|
||||
|
||||
// 회원 삭제
|
||||
const deleteMember = async () => {
|
||||
if (!selectedMember.value || !selectedClub.value) return;
|
||||
|
||||
deletingMember.value = true;
|
||||
try {
|
||||
await adminService.deleteClubMember(selectedClub.value.id, selectedMember.value.id);
|
||||
|
||||
// 회원 목록에서 삭제된 회원 제거
|
||||
clubMembers.value = clubMembers.value.filter(m => m.id !== selectedMember.value.id);
|
||||
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '회원이 삭제되었습니다.', life: 3000 });
|
||||
deleteMemberDialog.value = false;
|
||||
} catch (error) {
|
||||
console.error('회원 삭제 오류:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '회원을 삭제하는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
deletingMember.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 클럽 삭제 확인 다이얼로그 열기
|
||||
const confirmDeleteClub = (data) => {
|
||||
selectedClub.value = data;
|
||||
deleteDialog.value = true;
|
||||
};
|
||||
|
||||
// 클럽 삭제
|
||||
const deleteClub = async () => {
|
||||
if (!selectedClub.value) return;
|
||||
|
||||
deleting.value = true;
|
||||
|
||||
try {
|
||||
// 클럽 삭제 API 호출
|
||||
await adminService.deleteClub(selectedClub.value.id);
|
||||
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '클럽이 삭제되었습니다.', life: 3000 });
|
||||
deleteDialog.value = false;
|
||||
|
||||
// 클럽 목록 새로고침
|
||||
await fetchClubs();
|
||||
} catch (error) {
|
||||
console.error('클럽 삭제 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 삭제 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 새 회원 추가 다이얼로그 열기
|
||||
const openNewMemberDialog = () => {
|
||||
memberDialogMode.value = 'new';
|
||||
memberSubmitted.value = false;
|
||||
Object.assign(member, {
|
||||
id: null,
|
||||
name: '',
|
||||
gender: null,
|
||||
memberType: '준회원',
|
||||
handicap: 0,
|
||||
phone: '',
|
||||
email: ''
|
||||
});
|
||||
memberFormDialog.value = true;
|
||||
};
|
||||
|
||||
// 회원 수정 다이얼로그 열기
|
||||
const editMember = (data) => {
|
||||
memberDialogMode.value = 'edit';
|
||||
memberSubmitted.value = false;
|
||||
Object.assign(member, {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
gender: data.gender,
|
||||
memberType: data.memberType,
|
||||
handicap: data.handicap,
|
||||
phone: data.phone,
|
||||
email: data.email
|
||||
});
|
||||
memberFormDialog.value = true;
|
||||
};
|
||||
|
||||
// 회원 저장
|
||||
const saveMember = async () => {
|
||||
memberSubmitted.value = true;
|
||||
|
||||
if (!member.name || !member.gender || !member.memberType) {
|
||||
return;
|
||||
}
|
||||
|
||||
savingMember.value = true;
|
||||
try {
|
||||
let response;
|
||||
if (memberDialogMode.value === 'new') {
|
||||
response = await adminService.addClubMember(selectedClub.value.id, member);
|
||||
clubMembers.value.push(response.data);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '새 회원이 추가되었습니다.', life: 3000 });
|
||||
} else {
|
||||
response = await adminService.updateClubMember(selectedClub.value.id, member.id, member);
|
||||
const index = clubMembers.value.findIndex(m => m.id === member.id);
|
||||
if (index !== -1) {
|
||||
clubMembers.value[index] = response.data;
|
||||
}
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '회원 정보가 수정되었습니다.', life: 3000 });
|
||||
}
|
||||
memberFormDialog.value = false;
|
||||
} catch (error) {
|
||||
console.error('회원 저장 오류:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '회원 정보를 저장하는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
savingMember.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.club-management {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.feature-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.feature-header h4 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.feature-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.feature-price {
|
||||
font-weight: bold;
|
||||
color: #6366f1;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.confirmation-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.mr-2 {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.club-name {
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
|
||||
.club-location {
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.member-name {
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
|
||||
.member-contact {
|
||||
font-size: 0.75rem;
|
||||
color: #666;
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,291 @@
|
||||
<template>
|
||||
<div class="admin-dashboard">
|
||||
<h2>관리자 대시보드</h2>
|
||||
|
||||
<div v-if="loading" class="loading-spinner">
|
||||
<ProgressSpinner />
|
||||
</div>
|
||||
|
||||
<div v-else class="grid">
|
||||
<!-- 요약 카드 -->
|
||||
<div class="col-12 md:col-6 lg:col-3">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-users"></i>
|
||||
<h3>사용자</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p>총 사용자 수: {{ summary.totalUsers }}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<Button label="사용자 관리" icon="pi pi-arrow-right" @click="navigateTo('/admin/users')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 md:col-6 lg:col-3">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-building"></i>
|
||||
<h3>클럽</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p>총 클럽 수: {{ summary.totalClubs }}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<Button label="클럽 관리" icon="pi pi-arrow-right" @click="navigateTo('/admin/clubs')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 md:col-6 lg:col-3">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-credit-card"></i>
|
||||
<h3>구독</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p>활성 구독: {{ summary.activeSubscriptions }}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<Button label="구독 관리" icon="pi pi-arrow-right" @click="navigateTo('/admin/subscriptions')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 최근 데이터 -->
|
||||
<div class="col-12 md:col-6">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-users"></i>
|
||||
<h3>최근 가입한 사용자</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<DataTable :value="recent.users" :rows="5" stripedRows>
|
||||
<Column field="name" header="이름"></Column>
|
||||
<Column field="email" header="이메일"></Column>
|
||||
<Column field="role" header="권한"></Column>
|
||||
<Column field="createdAt" header="가입일">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.createdAt) }}
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 md:col-6">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-building"></i>
|
||||
<h3>최근 생성된 클럽</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<DataTable :value="recent.clubs" :rows="5" stripedRows>
|
||||
<Column field="name" header="클럽명"></Column>
|
||||
<Column field="memberCount" header="회원 수"></Column>
|
||||
<Column field="owner.name" header="모임장"></Column>
|
||||
<Column field="createdAt" header="생성일">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.createdAt) }}
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 월별 통계 차트 -->
|
||||
<div class="col-12">
|
||||
<div class="dashboard-card">
|
||||
<div class="card-header">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
<h3>월별 통계</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<Chart type="line" :data="chartData" :options="chartOptions" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import dayjs from 'dayjs';
|
||||
import adminService from '@/services/adminService';
|
||||
|
||||
// 컴포넌트들은 main.js에서 전역으로 등록되어 있으므로 import 불필요
|
||||
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
|
||||
// 데이터 상태
|
||||
const loading = ref(true);
|
||||
const summary = ref({
|
||||
totalUsers: 0,
|
||||
totalClubs: 0,
|
||||
activeSubscriptions: 0
|
||||
});
|
||||
const recent = ref({
|
||||
users: [],
|
||||
clubs: [],
|
||||
subscriptions: []
|
||||
});
|
||||
const stats = ref({
|
||||
users: [],
|
||||
clubs: [],
|
||||
subscriptions: []
|
||||
});
|
||||
|
||||
// 차트 데이터 계산
|
||||
const chartData = computed(() => {
|
||||
const months = stats.value.users.map(item => item.month);
|
||||
|
||||
return {
|
||||
labels: months,
|
||||
datasets: [
|
||||
{
|
||||
label: '사용자',
|
||||
data: stats.value.users.map(item => item.count),
|
||||
borderColor: '#42A5F5',
|
||||
tension: 0.4
|
||||
},
|
||||
{
|
||||
label: '클럽',
|
||||
data: stats.value.clubs.map(item => item.count),
|
||||
borderColor: '#66BB6A',
|
||||
tension: 0.4
|
||||
},
|
||||
{
|
||||
label: '구독',
|
||||
data: stats.value.subscriptions.map(item => item.count),
|
||||
borderColor: '#FFA726',
|
||||
tension: 0.4
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
// 차트 옵션
|
||||
const chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'top'
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
stepSize: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 컴포넌트 마운트 시 데이터 로드
|
||||
onMounted(async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
await loadDashboardData();
|
||||
} catch (error) {
|
||||
console.error('관리자 대시보드 데이터 로딩 오류:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 대시보드 데이터 로드 함수
|
||||
const loadDashboardData = async () => {
|
||||
try {
|
||||
const response = await adminService.getDashboardData();
|
||||
const data = response.data;
|
||||
|
||||
summary.value = data.summary;
|
||||
recent.value = data.recent;
|
||||
stats.value = data.stats;
|
||||
} catch (error) {
|
||||
console.error('관리자 대시보드 데이터 로딩 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '관리자 대시보드 데이터를 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 날짜 포맷 함수
|
||||
const formatDate = (date) => {
|
||||
return dayjs(date).format('YYYY-MM-DD');
|
||||
};
|
||||
|
||||
const navigateTo = (path) => {
|
||||
router.push(path);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-dashboard {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.dashboard-card {
|
||||
background-color: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
padding: 1.5rem;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.card-header i {
|
||||
font-size: 1.5rem;
|
||||
margin-right: 0.5rem;
|
||||
color: #3B82F6;
|
||||
}
|
||||
|
||||
.card-header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
flex: 1;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
:deep(.p-datatable) {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:deep(.p-datatable .p-datatable-thead > tr > th) {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
:deep(.p-datatable .p-datatable-tbody > tr) {
|
||||
background-color: transparent;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,655 @@
|
||||
<template>
|
||||
<div class="subscription-management-container">
|
||||
<div class="header">
|
||||
<h2>구독 플랜 관리</h2>
|
||||
<Button label="플랜 추가" icon="pi pi-plus" @click="openNewPlanDialog" />
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
:value="plans"
|
||||
:loading="loading"
|
||||
:paginator="true"
|
||||
:rows="10"
|
||||
stripedRows
|
||||
responsiveLayout="scroll"
|
||||
v-model:expandedRows="expandedRows"
|
||||
dataKey="id"
|
||||
@row-expand="onPlanExpand"
|
||||
>
|
||||
<Column :expander="true" style="width: 3%"/>
|
||||
<Column field="id" header="ID" sortable style="width: 5%"></Column>
|
||||
<Column field="name" header="플랜명" sortable style="width: 15%"></Column>
|
||||
<Column field="description" header="설명" style="width: 25%"></Column>
|
||||
<Column field="maxMembers" header="최대 회원수" sortable style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
{{ slotProps.data.maxMembers }}명
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="price" header="가격" sortable style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
{{ formatCurrency(slotProps.data.price) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="status" header="상태" sortable style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
<Badge :value="getStatusName(slotProps.data.status)" :severity="getStatusSeverity(slotProps.data.status)" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="작업" style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
<div class="action-buttons">
|
||||
<Button icon="pi pi-pencil" class="p-button-rounded p-button-text p-button-sm" @click="editPlan(slotProps.data)" />
|
||||
<Button icon="pi pi-trash" class="p-button-rounded p-button-text p-button-danger p-button-sm" @click="confirmDeletePlan(slotProps.data)" />
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<template #expansion="slotProps">
|
||||
<div class="plan-details">
|
||||
<div class="plan-features">
|
||||
<h4>포함된 기능</h4>
|
||||
<div class="features-grid">
|
||||
<div v-for="feature in slotProps.data.Features" :key="feature.id" class="feature-item">
|
||||
<i class="pi pi-check-circle" style="color: var(--green-500)"></i>
|
||||
<div class="feature-details">
|
||||
<h5>{{ feature.name }}</h5>
|
||||
<p>{{ feature.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="plan-subscriptions">
|
||||
<div class="subscriptions-header">
|
||||
<h4>구독 중인 클럽</h4>
|
||||
<Button label="클럽 구독 추가" icon="pi pi-plus" @click="openNewSubscriptionDialog(slotProps.data)" />
|
||||
</div>
|
||||
<DataTable :value="planSubscriptions[slotProps.data.id] || []" :loading="subscriptionsLoading[slotProps.data.id]">
|
||||
<Column field="Club.name" header="클럽명"></Column>
|
||||
<Column field="startDate" header="시작일">
|
||||
<template #body="subProps">
|
||||
{{ formatDate(subProps.data.startDate) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="expiryDate" header="만료일">
|
||||
<template #body="subProps">
|
||||
{{ formatDate(subProps.data.expiryDate) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="status" header="상태">
|
||||
<template #body="subProps">
|
||||
<Badge :value="getStatusName(subProps.data.status)" :severity="getStatusSeverity(subProps.data.status)" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="작업">
|
||||
<template #body="subProps">
|
||||
<div class="action-buttons">
|
||||
<Button icon="pi pi-pencil" class="p-button-rounded p-button-text p-button-sm" @click="editSubscription(subProps.data)" />
|
||||
<Button icon="pi pi-trash" class="p-button-rounded p-button-text p-button-danger p-button-sm" @click="confirmDeleteSubscription(subProps.data)" />
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</DataTable>
|
||||
|
||||
<!-- 구독 플랜 추가/수정 다이얼로그 -->
|
||||
<Dialog v-model:visible="planDialog" :header="dialogTitle" :style="{ width: '600px' }" :modal="true" class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="name">플랜명</label>
|
||||
<InputText id="name" v-model="plan.name" :class="{'p-invalid': submitted && !plan.name}" />
|
||||
<small class="p-error" v-if="submitted && !plan.name">플랜명은 필수입니다.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="description">설명</label>
|
||||
<Textarea id="description" v-model="plan.description" rows="3" />
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="maxMembers">최대 회원수</label>
|
||||
<InputNumber id="maxMembers" v-model="plan.maxMembers" :min="1" />
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="price">가격</label>
|
||||
<InputNumber id="price" v-model="plan.price" mode="currency" currency="KRW" locale="ko-KR" />
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="features">기능</label>
|
||||
<MultiSelect id="features" v-model="plan.features" :options="availableFeatures"
|
||||
optionLabel="name" optionValue="id" display="chip" :class="{'p-invalid': submitted && !plan.features?.length}" />
|
||||
<small class="p-error" v-if="submitted && !plan.features?.length">하나 이상의 기능을 선택해주세요.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="status">상태</label>
|
||||
<Dropdown id="status" v-model="plan.status" :options="statusOptions" optionLabel="name" optionValue="value" />
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="취소" icon="pi pi-times" class="p-button-text" @click="hidePlanDialog" />
|
||||
<Button label="저장" icon="pi pi-check" class="p-button-text" @click="savePlan" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 클럽 구독 추가/수정 다이얼로그 -->
|
||||
<Dialog v-model:visible="subscriptionDialog" :header="subscriptionDialogTitle" :style="{ width: '500px' }" :modal="true" class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="club">클럽</label>
|
||||
<Dropdown id="club" v-model="subscription.clubId" :options="availableClubs" optionLabel="name" optionValue="id"
|
||||
:class="{'p-invalid': subscriptionSubmitted && !subscription.clubId}" placeholder="클럽 선택" />
|
||||
<small class="p-error" v-if="subscriptionSubmitted && !subscription.clubId">클럽을 선택해주세요.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="startDate">시작일</label>
|
||||
<Calendar id="startDate" v-model="subscription.startDate" :showIcon="true" dateFormat="yy-mm-dd"
|
||||
:class="{'p-invalid': subscriptionSubmitted && !subscription.startDate}" />
|
||||
<small class="p-error" v-if="subscriptionSubmitted && !subscription.startDate">시작일을 선택해주세요.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="expiryDate">만료일</label>
|
||||
<Calendar id="expiryDate" v-model="subscription.expiryDate" :showIcon="true" dateFormat="yy-mm-dd"
|
||||
:class="{'p-invalid': subscriptionSubmitted && !subscription.expiryDate}" :minDate="subscription.startDate" />
|
||||
<small class="p-error" v-if="subscriptionSubmitted && !subscription.expiryDate">만료일을 선택해주세요.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="status">상태</label>
|
||||
<Dropdown id="status" v-model="subscription.status" :options="subscriptionStatusOptions" optionLabel="name" optionValue="value" />
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="취소" icon="pi pi-times" class="p-button-text" @click="hideSubscriptionDialog" />
|
||||
<Button label="저장" icon="pi pi-check" class="p-button-text" @click="saveSubscription" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 삭제 확인 다이얼로그 -->
|
||||
<Dialog v-model:visible="deletePlanDialog" :style="{ width: '450px' }" header="확인" :modal="true">
|
||||
<div class="confirmation-content">
|
||||
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
|
||||
<span v-if="plan">이 구독 플랜을 삭제하시겠습니까?</span>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="아니오" icon="pi pi-times" class="p-button-text" @click="deletePlanDialog = false" />
|
||||
<Button label="예" icon="pi pi-check" class="p-button-text" @click="deletePlan" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 구독 삭제 확인 다이얼로그 -->
|
||||
<Dialog v-model:visible="deleteSubscriptionDialog" :style="{ width: '450px' }" header="확인" :modal="true">
|
||||
<div class="confirmation-content">
|
||||
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
|
||||
<span v-if="subscription">이 구독을 삭제하시겠습니까?</span>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="아니오" icon="pi pi-times" class="p-button-text" @click="deleteSubscriptionDialog = false" />
|
||||
<Button label="예" icon="pi pi-check" class="p-button-text" @click="deleteSubscription" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<Toast />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import axios from 'axios';
|
||||
import adminService from '@/services/adminService';
|
||||
|
||||
// PrimeVue 컴포넌트
|
||||
import MultiSelect from 'primevue/multiselect';
|
||||
import InputNumber from 'primevue/inputnumber';
|
||||
import Textarea from 'primevue/textarea';
|
||||
import InputText from 'primevue/inputtext';
|
||||
import Button from 'primevue/button';
|
||||
import Dialog from 'primevue/dialog';
|
||||
import DataTable from 'primevue/datatable';
|
||||
import Column from 'primevue/column';
|
||||
import Dropdown from 'primevue/dropdown';
|
||||
import Badge from 'primevue/badge';
|
||||
import Toast from 'primevue/toast';
|
||||
import Calendar from 'primevue/calendar';
|
||||
|
||||
const toast = useToast();
|
||||
const API_URL = 'http://localhost:3030/api';
|
||||
|
||||
// 데이터 정의
|
||||
const plans = ref([]);
|
||||
const clubs = ref([]);
|
||||
const features = ref([]);
|
||||
const subscriptions = ref([]);
|
||||
const planSubscriptions = ref({});
|
||||
const loading = ref(false);
|
||||
const subscriptionsLoading = ref({});
|
||||
|
||||
// 상태 변수
|
||||
const plan = ref({});
|
||||
const planDialog = ref(false);
|
||||
const deletePlanDialog = ref(false);
|
||||
const submitted = ref(false);
|
||||
const isNewPlan = ref(false);
|
||||
const expandedRows = ref([]);
|
||||
const availableFeatures = ref([]);
|
||||
const subscription = ref({});
|
||||
const subscriptionDialog = ref(false);
|
||||
const deleteSubscriptionDialog = ref(false);
|
||||
const subscriptionSubmitted = ref(false);
|
||||
const availableClubs = ref([]);
|
||||
const selectedPlan = ref(null);
|
||||
|
||||
// 상태 옵션
|
||||
const statusOptions = [
|
||||
{ name: '활성', value: 'active' },
|
||||
{ name: '비활성', value: 'inactive' }
|
||||
];
|
||||
|
||||
const subscriptionStatusOptions = [
|
||||
{ name: '활성', value: 'active' },
|
||||
{ name: '만료', value: 'expired' },
|
||||
{ name: '일시중지', value: 'paused' }
|
||||
];
|
||||
|
||||
// 다이얼로그 제목
|
||||
const dialogTitle = computed(() => {
|
||||
return isNewPlan.value ? '구독 플랜 추가' : '구독 플랜 수정';
|
||||
});
|
||||
|
||||
const subscriptionDialogTitle = computed(() => {
|
||||
return !subscription.value.id ? '클럽 구독 추가' : '클럽 구독 수정';
|
||||
});
|
||||
|
||||
// 구독 목록 가져오기
|
||||
const fetchSubscriptions = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await adminService.getSubscriptions();
|
||||
subscriptions.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('구독 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 플랜별 구독 목록 가져오기
|
||||
const fetchPlanSubscriptions = async (planId) => {
|
||||
subscriptionsLoading.value[planId] = true;
|
||||
try {
|
||||
const response = await adminService.getPlanSubscriptions(planId);
|
||||
planSubscriptions.value[planId] = response.data;
|
||||
} catch (error) {
|
||||
console.error('구독 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
subscriptionsLoading.value[planId] = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 컴포넌트 마운트 시 데이터 로드
|
||||
onMounted(async () => {
|
||||
await fetchPlans();
|
||||
await fetchFeatures();
|
||||
await fetchClubs();
|
||||
await fetchSubscriptions();
|
||||
});
|
||||
|
||||
// 플랜 확장 시 구독 목록 로드
|
||||
const onPlanExpand = (event) => {
|
||||
const planId = event.data.id;
|
||||
fetchPlanSubscriptions(planId);
|
||||
};
|
||||
|
||||
// 구독 플랜 목록 가져오기
|
||||
const fetchPlans = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await adminService.getPlans();
|
||||
plans.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('구독 플랜 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 플랜 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 기능 목록 가져오기
|
||||
const fetchFeatures = async () => {
|
||||
try {
|
||||
const response = await adminService.getFeatures();
|
||||
availableFeatures.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('기능 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '기능 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 클럽 목록 가져오기
|
||||
const fetchClubs = async () => {
|
||||
try {
|
||||
const response = await adminService.getClubs();
|
||||
availableClubs.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('클럽 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '클럽 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 새 구독 플랜 다이얼로그 열기
|
||||
const openNewPlanDialog = () => {
|
||||
plan.value = {
|
||||
name: '',
|
||||
description: '',
|
||||
maxMembers: 30,
|
||||
price: 30000,
|
||||
features: [],
|
||||
status: 'active'
|
||||
};
|
||||
submitted.value = false;
|
||||
planDialog.value = true;
|
||||
isNewPlan.value = true;
|
||||
};
|
||||
|
||||
// 구독 플랜 수정 다이얼로그 열기
|
||||
const editPlan = (planData) => {
|
||||
plan.value = { ...planData };
|
||||
plan.value.features = planData.Features.map(f => f.id);
|
||||
submitted.value = false;
|
||||
planDialog.value = true;
|
||||
isNewPlan.value = false;
|
||||
};
|
||||
|
||||
// 다이얼로그 닫기
|
||||
const hidePlanDialog = () => {
|
||||
planDialog.value = false;
|
||||
submitted.value = false;
|
||||
};
|
||||
|
||||
// 구독 플랜 저장
|
||||
const savePlan = async () => {
|
||||
submitted.value = true;
|
||||
|
||||
if (!plan.value.name || !plan.value.features?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNewPlan.value) {
|
||||
await adminService.createPlan(plan.value);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독 플랜이 생성되었습니다.', life: 3000 });
|
||||
} else {
|
||||
await adminService.updatePlan(plan.value.id, plan.value);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독 플랜이 수정되었습니다.', life: 3000 });
|
||||
}
|
||||
|
||||
planDialog.value = false;
|
||||
await fetchPlans();
|
||||
} catch (error) {
|
||||
console.error('구독 플랜 저장 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 플랜 저장 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 구독 플랜 삭제 확인
|
||||
const confirmDeletePlan = (planData) => {
|
||||
plan.value = planData;
|
||||
deletePlanDialog.value = true;
|
||||
};
|
||||
|
||||
// 구독 플랜 삭제
|
||||
const deletePlan = async () => {
|
||||
try {
|
||||
await adminService.deletePlan(plan.value.id);
|
||||
|
||||
deletePlanDialog.value = false;
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독 플랜이 삭제되었습니다.', life: 3000 });
|
||||
await fetchPlans();
|
||||
} catch (error) {
|
||||
console.error('구독 플랜 삭제 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 플랜 삭제 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 새 구독 다이얼로그 열기
|
||||
const openNewSubscriptionDialog = (plan) => {
|
||||
selectedPlan.value = plan;
|
||||
subscription.value = {
|
||||
planId: plan.id,
|
||||
clubId: null,
|
||||
startDate: new Date(),
|
||||
expiryDate: new Date(new Date().setFullYear(new Date().getFullYear() + 1)),
|
||||
status: 'active'
|
||||
};
|
||||
subscriptionSubmitted.value = false;
|
||||
subscriptionDialog.value = true;
|
||||
};
|
||||
|
||||
// 구독 수정 다이얼로그 열기
|
||||
const editSubscription = (subscriptionData) => {
|
||||
subscription.value = {
|
||||
id: subscriptionData.id,
|
||||
planId: subscriptionData.planId,
|
||||
clubId: subscriptionData.Club.id,
|
||||
startDate: new Date(subscriptionData.startDate),
|
||||
expiryDate: new Date(subscriptionData.expiryDate),
|
||||
status: subscriptionData.status
|
||||
};
|
||||
subscriptionSubmitted.value = false;
|
||||
subscriptionDialog.value = true;
|
||||
};
|
||||
|
||||
// 구독 다이얼로그 닫기
|
||||
const hideSubscriptionDialog = () => {
|
||||
subscriptionDialog.value = false;
|
||||
subscriptionSubmitted.value = false;
|
||||
};
|
||||
|
||||
// 구독 저장
|
||||
const saveSubscription = async () => {
|
||||
subscriptionSubmitted.value = true;
|
||||
|
||||
if (!subscription.value.clubId || !subscription.value.startDate || !subscription.value.expiryDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!subscription.value.id) {
|
||||
await adminService.createSubscription(subscription.value);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독이 추가되었습니다.', life: 3000 });
|
||||
} else {
|
||||
await adminService.updateSubscription(subscription.value.id, subscription.value);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독이 수정되었습니다.', life: 3000 });
|
||||
}
|
||||
|
||||
subscriptionDialog.value = false;
|
||||
await fetchPlanSubscriptions(subscription.value.planId);
|
||||
} catch (error) {
|
||||
console.error('구독 저장 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독을 저장하는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 구독 삭제 확인
|
||||
const confirmDeleteSubscription = (subscriptionData) => {
|
||||
subscription.value = subscriptionData;
|
||||
deleteSubscriptionDialog.value = true;
|
||||
};
|
||||
|
||||
// 구독 삭제
|
||||
const deleteSubscription = async () => {
|
||||
try {
|
||||
await adminService.deleteSubscription(subscription.value.id);
|
||||
|
||||
deleteSubscriptionDialog.value = false;
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '구독이 삭제되었습니다.', life: 3000 });
|
||||
await fetchPlanSubscriptions(subscription.value.planId);
|
||||
} catch (error) {
|
||||
console.error('구독 삭제 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '구독 삭제 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 상태 이름 가져오기
|
||||
const getStatusName = (status) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return '활성';
|
||||
case 'inactive':
|
||||
return '비활성';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
// 상태 심각도 가져오기
|
||||
const getStatusSeverity = (status) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return 'success';
|
||||
case 'inactive':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
};
|
||||
|
||||
// 금액 포맷팅
|
||||
const formatCurrency = (amount) => {
|
||||
return new Intl.NumberFormat('ko-KR', {
|
||||
style: 'currency',
|
||||
currency: 'KRW'
|
||||
}).format(amount);
|
||||
};
|
||||
|
||||
// 날짜 포맷팅
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '-';
|
||||
const d = new Date(date);
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.subscription-management-container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.header h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.plan-features {
|
||||
padding: 1rem;
|
||||
background-color: var(--surface-ground);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.plan-features h4 {
|
||||
margin: 0 0 1rem 0;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.features-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.feature-details h5 {
|
||||
margin: 0 0 0.25rem 0;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.feature-details p {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
.plan-details {
|
||||
padding: 1rem;
|
||||
background-color: var(--surface-ground);
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.plan-subscriptions {
|
||||
background-color: var(--surface-card);
|
||||
padding: 1rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.subscriptions-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.subscriptions-header h4 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.field {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.field label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.confirmation-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.mr-3 {
|
||||
margin-right: 0.75rem;
|
||||
}
|
||||
|
||||
:deep(.p-inputnumber),
|
||||
:deep(.p-calendar),
|
||||
:deep(.p-dropdown),
|
||||
:deep(.p-multiselect) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.p-badge) {
|
||||
font-size: 0.8rem;
|
||||
padding: 0.3rem 0.5rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,360 @@
|
||||
<template>
|
||||
<div class="user-management-container">
|
||||
<div class="header">
|
||||
<h2>사용자 관리</h2>
|
||||
<Button label="사용자 추가" icon="pi pi-plus" @click="openNewUserDialog" />
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
:value="users"
|
||||
:loading="loading"
|
||||
:paginator="true"
|
||||
:rows="10"
|
||||
:rowsPerPageOptions="[5, 10, 20, 50]"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="{first}에서 {last}까지 {totalRecords} 중"
|
||||
responsiveLayout="scroll"
|
||||
stripedRows
|
||||
filterDisplay="menu"
|
||||
v-model:filters="filters"
|
||||
scrollable
|
||||
scrollHeight="calc(100vh - 200px)"
|
||||
>
|
||||
<Column field="id" header="ID" sortable style="width: 5%"></Column>
|
||||
<Column field="name" header="이름" sortable style="width: 15%">
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<InputText v-model="filterModel.value" @input="filterCallback()" class="p-column-filter" placeholder="이름으로 검색" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="email" header="이메일" sortable style="width: 20%">
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<InputText v-model="filterModel.value" @input="filterCallback()" class="p-column-filter" placeholder="이메일로 검색" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="role" header="역할" sortable style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
<Badge :value="getRoleName(slotProps.data.role)" :severity="getRoleSeverity(slotProps.data.role)" />
|
||||
</template>
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<Dropdown v-model="filterModel.value" @change="filterCallback()" :options="roleOptions" optionLabel="name" optionValue="value" placeholder="역할 선택" class="p-column-filter" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="status" header="상태" sortable style="width: 10%">
|
||||
<template #body="slotProps">
|
||||
<Badge :value="getStatusName(slotProps.data.status)" :severity="getStatusSeverity(slotProps.data.status)" />
|
||||
</template>
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<Dropdown v-model="filterModel.value" @change="filterCallback()" :options="statusOptions" optionLabel="name" optionValue="value" placeholder="상태 선택" class="p-column-filter" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="createdAt" header="가입일" sortable style="width: 12%">
|
||||
<template #body="slotProps">
|
||||
{{ formatDate(slotProps.data.createdAt) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="lastLoginAt" header="최근 로그인" sortable style="width: 12%">
|
||||
<template #body="slotProps">
|
||||
{{ slotProps.data.lastLoginAt ? formatDate(slotProps.data.lastLoginAt) : '-' }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="작업" style="width: 8%">
|
||||
<template #body="slotProps">
|
||||
<div class="action-buttons">
|
||||
<Button icon="pi pi-pencil" class="p-button-rounded p-button-text p-button-sm" @click="editUser(slotProps.data)" />
|
||||
<Button icon="pi pi-trash" class="p-button-rounded p-button-text p-button-danger p-button-sm" @click="confirmDeleteUser(slotProps.data)" />
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
|
||||
<!-- 사용자 추가/수정 다이얼로그 -->
|
||||
<Dialog v-model:visible="userDialog" :header="dialogTitle" :style="{ width: '450px' }" :modal="true" class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="name">이름</label>
|
||||
<InputText id="name" v-model="user.name" :class="{'p-invalid': submitted && !user.name}" required autofocus />
|
||||
<small class="p-error" v-if="submitted && !user.name">이름은 필수입니다.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="email">이메일</label>
|
||||
<InputText id="email" v-model="user.email" :class="{'p-invalid': submitted && !user.email}" required />
|
||||
<small class="p-error" v-if="submitted && !user.email">이메일은 필수입니다.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="password">비밀번호</label>
|
||||
<Password id="password" v-model="user.password" :class="{'p-invalid': submitted && isNewUser && !user.password}" toggleMask :feedback="isNewUser" />
|
||||
<small class="p-error" v-if="submitted && isNewUser && !user.password">비밀번호는 필수입니다.</small>
|
||||
<small v-if="!isNewUser">비밀번호를 변경하지 않으려면 비워두세요.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="role">역할</label>
|
||||
<Dropdown id="role" v-model="user.role" :options="roleOptions" optionLabel="name" optionValue="value" placeholder="역할 선택" required />
|
||||
<small class="p-error" v-if="submitted && !user.role">역할은 필수입니다.</small>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="status">상태</label>
|
||||
<Dropdown id="status" v-model="user.status" :options="statusOptions" optionLabel="name" optionValue="value" placeholder="상태 선택" required />
|
||||
<small class="p-error" v-if="submitted && !user.status">상태는 필수입니다.</small>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<Button label="취소" icon="pi pi-times" class="p-button-text" @click="hideDialog" />
|
||||
<Button label="저장" icon="pi pi-check" class="p-button-text" @click="saveUser" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<!-- 삭제 확인 다이얼로그 -->
|
||||
<Dialog v-model:visible="deleteUserDialog" :style="{ width: '450px' }" header="확인" :modal="true">
|
||||
<div class="confirmation-content">
|
||||
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
|
||||
<span v-if="user">{{ user.name }} 사용자를 삭제하시겠습니까?</span>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="아니오" icon="pi pi-times" class="p-button-text" @click="deleteUserDialog = false" />
|
||||
<Button label="예" icon="pi pi-check" class="p-button-text" @click="deleteUser" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<Toast />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, reactive, computed } from 'vue';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import { FilterMatchMode } from 'primevue/api';
|
||||
import Badge from 'primevue/badge';
|
||||
import dayjs from 'dayjs';
|
||||
import adminService from '@/services/adminService';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
// 상태 변수
|
||||
const users = ref([]);
|
||||
const user = ref({});
|
||||
const userDialog = ref(false);
|
||||
const deleteUserDialog = ref(false);
|
||||
const submitted = ref(false);
|
||||
const loading = ref(false);
|
||||
const isNewUser = ref(false);
|
||||
|
||||
// 필터 설정
|
||||
const filters = ref({
|
||||
name: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
email: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
role: { value: null, matchMode: FilterMatchMode.EQUALS },
|
||||
status: { value: null, matchMode: FilterMatchMode.EQUALS }
|
||||
});
|
||||
|
||||
// 역할 옵션
|
||||
const roleOptions = [
|
||||
{ name: '관리자', value: 'admin' },
|
||||
{ name: '클럽 관리자', value: 'clubadmin' },
|
||||
{ name: '일반 사용자', value: 'user' }
|
||||
];
|
||||
|
||||
// 상태 옵션
|
||||
const statusOptions = [
|
||||
{ name: '활성', value: 'active' },
|
||||
{ name: '비활성', value: 'inactive' },
|
||||
{ name: '정지', value: 'suspended' }
|
||||
];
|
||||
|
||||
// 다이얼로그 제목
|
||||
const dialogTitle = computed(() => {
|
||||
return isNewUser.value ? '사용자 추가' : '사용자 수정';
|
||||
});
|
||||
|
||||
// 페이지 로드 시 사용자 목록 가져오기
|
||||
onMounted(async () => {
|
||||
await fetchUsers();
|
||||
});
|
||||
|
||||
// 사용자 목록 가져오기
|
||||
const fetchUsers = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await adminService.getAllUsers();
|
||||
users.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('사용자 목록을 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '사용자 목록을 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 새 사용자 다이얼로그 열기
|
||||
const openNewUserDialog = () => {
|
||||
user.value = {
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
role: 'user',
|
||||
status: 'active'
|
||||
};
|
||||
submitted.value = false;
|
||||
isNewUser.value = true;
|
||||
userDialog.value = true;
|
||||
};
|
||||
|
||||
// 사용자 수정 다이얼로그 열기
|
||||
const editUser = async (userData) => {
|
||||
try {
|
||||
const response = await adminService.getUserById(userData.id);
|
||||
user.value = { ...response.data, password: '' };
|
||||
isNewUser.value = false;
|
||||
submitted.value = false;
|
||||
userDialog.value = true;
|
||||
} catch (error) {
|
||||
console.error('사용자 정보를 가져오는 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '사용자 정보를 가져오는 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 다이얼로그 닫기
|
||||
const hideDialog = () => {
|
||||
userDialog.value = false;
|
||||
submitted.value = false;
|
||||
};
|
||||
|
||||
// 사용자 저장 (추가 또는 수정)
|
||||
const saveUser = async () => {
|
||||
submitted.value = true;
|
||||
|
||||
if (!user.value.name || !user.value.email || !user.value.role || !user.value.status || (isNewUser.value && !user.value.password)) {
|
||||
toast.add({ severity: 'warn', summary: '입력 오류', detail: '모든 필수 항목을 입력해주세요.', life: 3000 });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNewUser.value) {
|
||||
await adminService.createUser(user.value);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '사용자가 생성되었습니다.', life: 3000 });
|
||||
} else {
|
||||
const userData = { ...user.value };
|
||||
if (!userData.password) {
|
||||
delete userData.password;
|
||||
}
|
||||
await adminService.updateUser(userData.id, userData);
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '사용자 정보가 수정되었습니다.', life: 3000 });
|
||||
}
|
||||
|
||||
userDialog.value = false;
|
||||
await fetchUsers();
|
||||
} catch (error) {
|
||||
console.error('사용자 저장 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '사용자 저장 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 사용자 삭제 확인 다이얼로그 열기
|
||||
const confirmDeleteUser = (userData) => {
|
||||
user.value = userData;
|
||||
deleteUserDialog.value = true;
|
||||
};
|
||||
|
||||
// 사용자 삭제
|
||||
const deleteUser = async () => {
|
||||
try {
|
||||
await adminService.deleteUser(user.value.id);
|
||||
deleteUserDialog.value = false;
|
||||
toast.add({ severity: 'success', summary: '성공', detail: '사용자가 삭제되었습니다.', life: 3000 });
|
||||
await fetchUsers();
|
||||
} catch (error) {
|
||||
console.error('사용자 삭제 중 오류 발생:', error);
|
||||
toast.add({ severity: 'error', summary: '오류', detail: '사용자 삭제 중 오류가 발생했습니다.', life: 3000 });
|
||||
}
|
||||
};
|
||||
|
||||
// 역할 이름 가져오기
|
||||
const getRoleName = (role) => {
|
||||
switch (role) {
|
||||
case 'admin':
|
||||
return '관리자';
|
||||
case 'clubadmin':
|
||||
return '클럽 관리자';
|
||||
case 'user':
|
||||
return '일반 사용자';
|
||||
default:
|
||||
return role;
|
||||
}
|
||||
};
|
||||
|
||||
// 역할 심각도 가져오기
|
||||
const getRoleSeverity = (role) => {
|
||||
switch (role) {
|
||||
case 'admin':
|
||||
return 'danger';
|
||||
case 'clubadmin':
|
||||
return 'warning';
|
||||
case 'user':
|
||||
return 'info';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
};
|
||||
|
||||
// 상태 이름 가져오기
|
||||
const getStatusName = (status) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return '활성';
|
||||
case 'inactive':
|
||||
return '비활성';
|
||||
case 'suspended':
|
||||
return '정지';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
// 상태 심각도 가져오기
|
||||
const getStatusSeverity = (status) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return 'success';
|
||||
case 'inactive':
|
||||
return 'secondary';
|
||||
case 'suspended':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
};
|
||||
|
||||
// 날짜 포맷팅
|
||||
const formatDate = (date) => {
|
||||
return date ? dayjs(date).format('YYYY-MM-DD') : '-';
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.user-management-container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.confirmation-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mr-3 {
|
||||
margin-right: 0.75rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user