| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- <template>
- <div class="admin--field-list">
- <!-- 상단 검색/액션 영역 -->
- <div class="admin--search-box type2">
- <div class="admin--search--inner--box">
- <div class="admin--search-form">
- <select v-model="filterStatus" @change="onSearch" class="admin--form-select admin--search-select">
- <option value="">전체</option>
- <option value="recruiting">모집중</option>
- <option value="running">진행중</option>
- <option value="ended">종료</option>
- </select>
- <input
- v-model="searchQuery"
- type="text"
- placeholder="퀘스트명으로 검색"
- @keyup.enter="onSearch"
- class="admin--form-input admin--search-input"
- />
- <button @click="onSearch" class="admin--btn-small admin--btn-small-primary">검색</button>
- <button @click="resetSearch" class="admin--btn-small admin--btn-small-secondary">초기화</button>
- </div>
- <div class="admin--search-actions">
- <button class="admin--btn-add" @click="goToCreate">+ 새 퀘스트 등록</button>
- </div>
- </div>
- <div class="admin--search--inner--box">
- <div class="admin--search-form">
- <DatePicker v-model="startDate" placeholder="📅 YYYY-MM-DD" />
- <span class="admin--date-separator">-</span>
- <DatePicker v-model="endDate" placeholder="📅 YYYY-MM-DD" />
- <div class="admin--quick-range">
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('today')">오늘</button>
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('7d')">7일</button>
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('15d')">15일</button>
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('1m')">1개월</button>
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('3m')">3개월</button>
- <button type="button" class="admin--btn-small admin--btn-small-secondary range--btn" @click="setRange('1y')">1년</button>
- </div>
- </div>
- </div>
- </div>
- <!-- 테이블 -->
- <p class="admin--table--count">전체 {{ counts.all }}ㆍ모집중 {{ counts.recruiting }}ㆍ진행중 {{ counts.running }}ㆍ종료 {{ counts.ended }}</p>
- <div class="admin--table-wrapper">
- <table class="admin--table fishing--table">
- <thead>
- <tr>
- <th style="width: 40px;">번호</th>
- <th>퀘스트명</th>
- <th style="width: 100px;">상태</th>
- <th style="width: 100px;">라운드</th>
- <th style="width: 100px;">모집/전체</th>
- <th style="">기간</th>
- <th style="width: 120px;">관리</th>
- </tr>
- </thead>
- <tbody>
- <tr v-if="isLoading">
- <td colspan="7" class="admin--table-loading">데이터를 불러오는 중...</td>
- </tr>
- <tr v-else-if="!spots || spots.length === 0">
- <td colspan="7" class="admin--table-empty">등록된 퀘스트가 없습니다.</td>
- </tr>
- <tr
- v-else
- v-for="(item, index) in spots"
- :key="item.id"
- class="admin--table-row-clickable"
- @click="goToDetail(item.id)"
- >
- <td class="date">{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
- <td class="admin--table-title">{{ item.name }}</td>
- <td>
- <span :class="['admin--badge', getStatusBadgeClass(item.derived_status)]">
- {{ getStatusLabel(item.derived_status) }}
- </span>
- </td>
- <td>R{{ item.current_round || 1 }}/{{ item.total_rounds }}</td>
- <td>{{ item.max_participants }}</td>
- <td class="date">{{ formatDate(item.start_date) }} ~ {{ formatDate(item.end_date) }}</td>
- <td>
- <div class="admin--table-actions">
- <button class="admin--btn-small admin--btn-blue" @click.stop="goToEdit(item.id)">
- 수정
- </button>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- 페이지네이션 -->
- <div v-if="totalPages > 1" class="admin--pagination">
- <button
- v-if="totalPages > 2"
- class="admin--pagination-btn"
- :disabled="currentPage === 1"
- @click="changePage(1)"
- title="처음"
- >
- ◀◀
- </button>
- <button
- class="admin--pagination-btn"
- :disabled="currentPage === 1"
- @click="changePage(currentPage - 1)"
- title="이전"
- >
- ◀
- </button>
- <button
- v-for="page in visiblePages"
- :key="page"
- class="admin--pagination-btn"
- :class="{ 'is-active': page === currentPage }"
- @click="changePage(page)"
- >
- {{ page }}
- </button>
- <button
- class="admin--pagination-btn"
- :disabled="currentPage === totalPages"
- @click="changePage(currentPage + 1)"
- title="다음"
- >
- ▶
- </button>
- <button
- v-if="totalPages > 2"
- class="admin--pagination-btn"
- :disabled="currentPage === totalPages"
- @click="changePage(totalPages)"
- title="끝"
- >
- ▶▶
- </button>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, computed, onMounted } from "vue";
- import { useRouter } from "vue-router";
- import DatePicker from "~/components/admin/DatePicker.vue";
- definePageMeta({
- layout: "admin",
- middleware: ["auth"],
- });
- const router = useRouter();
- const { get } = useApi();
- const isLoading = ref(false);
- const spots = ref([]);
- const currentPage = ref(1);
- const perPage = ref(10);
- const totalCount = ref(0);
- const totalPages = ref(0);
- const counts = ref({ all: 0, recruiting: 0, running: 0, ended: 0 });
- const searchQuery = ref("");
- const filterStatus = ref(""); // '', recruiting, running, ended
- const startDate = ref(""); // YYYY-MM-DD
- const endDate = ref(""); // YYYY-MM-DD
- // YYYY-MM-DD 포맷터
- const toYMD = (d) => {
- const y = d.getFullYear();
- const m = String(d.getMonth() + 1).padStart(2, "0");
- const day = String(d.getDate()).padStart(2, "0");
- return `${y}-${m}-${day}`;
- };
- // 빠른 기간 선택 (오늘 기준)
- const setRange = (kind) => {
- const today = new Date();
- const end = toYMD(today);
- const startDt = new Date();
- switch (kind) {
- case "today":
- break;
- case "7d":
- startDt.setDate(startDt.getDate() - 7);
- break;
- case "15d":
- startDt.setDate(startDt.getDate() - 15);
- break;
- case "1m":
- startDt.setMonth(startDt.getMonth() - 1);
- break;
- case "3m":
- startDt.setMonth(startDt.getMonth() - 3);
- break;
- case "1y":
- startDt.setFullYear(startDt.getFullYear() - 1);
- break;
- }
- startDate.value = toYMD(startDt);
- endDate.value = end;
- onSearch();
- };
- // 보이는 페이지 번호 계산
- const visiblePages = computed(() => {
- const pages = [];
- const maxVisible = 5;
- let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
- let end = Math.min(totalPages.value, start + maxVisible - 1);
- if (end - start < maxVisible - 1) {
- start = Math.max(1, end - maxVisible + 1);
- }
- for (let i = start; i <= end; i++) {
- pages.push(i);
- }
- return pages;
- });
- // 데이터 로드
- const loadSpots = async () => {
- isLoading.value = true;
- const params = {
- page: currentPage.value,
- per_page: perPage.value,
- };
- if (searchQuery.value) params.search = searchQuery.value;
- if (filterStatus.value) params.status = filterStatus.value;
- if (startDate.value) params.start_date = startDate.value;
- if (endDate.value) params.end_date = endDate.value;
- const { data, error } = await get("/quest/list", { params });
- if (error) {
- console.error("[QuestList] 목록 로드 실패:", error);
- spots.value = [];
- totalCount.value = 0;
- totalPages.value = 0;
- counts.value = { all: 0, recruiting: 0, running: 0, ended: 0 };
- } else if (data?.success && data?.data) {
- spots.value = data.data.items || [];
- totalCount.value = data.data.total || 0;
- totalPages.value = data.data.total_pages || 0;
- counts.value = data.data.counts || { all: 0, recruiting: 0, running: 0, ended: 0 };
- }
- isLoading.value = false;
- };
- // 검색
- const onSearch = () => {
- currentPage.value = 1;
- loadSpots();
- };
- // 검색 초기화
- const resetSearch = () => {
- searchQuery.value = "";
- filterStatus.value = "";
- startDate.value = "";
- endDate.value = "";
- currentPage.value = 1;
- loadSpots();
- };
- // 페이지 변경
- const changePage = (page) => {
- if (page < 1 || page > totalPages.value) return;
- currentPage.value = page;
- loadSpots();
- window.scrollTo({ top: 0, behavior: "smooth" });
- };
- // 이동
- const goToCreate = () => router.push("/site-manager/quest/create");
- const goToDetail = (id) => router.push(`/site-manager/quest/detail/${id}`);
- const goToEdit = (id) => router.push(`/site-manager/quest/edit/${id}`);
- // 상태 라벨 / 뱃지 클래스 (derived_status: hidden/recruiting/running/ended)
- const getStatusLabel = (status) =>
- status === "hidden" ? "미사용"
- : status === "recruiting" ? "모집중"
- : status === "running" ? "진행중"
- : status === "ended" ? "종료"
- : "-";
- const getStatusBadgeClass = (status) =>
- status === "hidden" ? "admin--badge-hidden"
- : status === "recruiting" ? "admin--badge-recruiting"
- : status === "running" ? "admin--badge-running"
- : status === "ended" ? "admin--badge-ended"
- : "";
- // 날짜 포맷
- const formatDate = (dateString) => {
- if (!dateString) return "-";
- const date = new Date(dateString.replace(" ", "T"));
- if (isNaN(date.getTime())) return dateString;
- return date.toLocaleDateString("ko-KR", {
- year: "numeric",
- month: "2-digit",
- day: "2-digit",
- });
- };
- onMounted(() => {
- loadSpots();
- });
- </script>
|