list.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="admin--field-list">
  3. <!-- 상단 검색/액션 영역 -->
  4. <div class="admin--search-box">
  5. <div class="admin--search-form">
  6. <select v-model="searchField" class="admin--form-select admin--search-select">
  7. <option value="">전체</option>
  8. <option value="username">아이디</option>
  9. <option value="name">이름</option>
  10. <option value="email">이메일</option>
  11. </select>
  12. <input
  13. v-model="searchQuery"
  14. type="text"
  15. placeholder="검색어 입력"
  16. @keyup.enter="onSearch"
  17. class="admin--form-input admin--search-input"
  18. />
  19. <select v-model="filterPartnership" @change="onSearch" class="admin--form-select admin--search-select">
  20. <option value="">전체</option>
  21. <option value="N">슈퍼 관리자</option>
  22. <option value="N">관리자 관리</option>
  23. <option value="Y">아이템 관리</option>
  24. <option value="Y">퀘스트 관리</option>
  25. <option value="Y">챌린지 관리</option>
  26. </select>
  27. <select v-model="filterStatus" @change="onSearch" class="admin--form-select admin--search-select">
  28. <option value="">전체</option>
  29. <option value="Y">활성</option>
  30. <option value="N">휴면</option>
  31. <option value="N">정지</option>
  32. </select>
  33. <button @click="onSearch" class="admin--btn-small admin--btn-small-primary">검색</button>
  34. <button @click="resetSearch" class="admin--btn-small admin--btn-small-secondary">초기화</button>
  35. </div>
  36. <div class="admin--search-actions">
  37. <button class="admin--btn-add" @click="goToCreate">+ 관리자 추가</button>
  38. </div>
  39. </div>
  40. <!-- 테이블 -->
  41. <div class="admin--table-wrapper">
  42. <table class="admin--table">
  43. <thead>
  44. <tr>
  45. <th style="width: 80px;"></th>
  46. <th style="width: 140px;">아이디</th>
  47. <th style="width: 140px;">이름</th>
  48. <th>핸드폰</th>
  49. <th style="width: 100px;">이메일</th>
  50. <th style="width: 100px;">권한</th>
  51. <th style="width: 120px;">최근 로그인</th>
  52. <th>상태</th>
  53. <th style="width: 120px;">관리</th>
  54. </tr>
  55. </thead>
  56. <tbody>
  57. <tr v-if="isLoading">
  58. <td colspan="8" class="admin--table-loading">데이터를 불러오는 중...</td>
  59. </tr>
  60. <tr v-else-if="!onboards || onboards.length === 0">
  61. <td colspan="8" class="admin--table-empty">등록된 관리자가 없습니다.</td>
  62. </tr>
  63. <tr
  64. v-else
  65. v-for="(item, index) in onboards"
  66. :key="item.id"
  67. class="admin--table-row-clickable"
  68. @click="goToDetail(item.id)"
  69. >
  70. <td class="date">{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  71. <td>{{ item.field_name || "-" }}</td>
  72. <td>{{ item.area_name || "-" }}</td>
  73. <td class="admin--table-title">{{ item.name }}</td>
  74. <td>
  75. <span :class="['admin--badge', item.partnership_YN === 'Y' ? 'admin--badge-active' : 'admin--badge-ended']">
  76. {{ item.partnership_YN === "Y" ? "제휴" : "비제휴" }}
  77. </span>
  78. </td>
  79. <td>
  80. <span :class="['admin--badge', getStatusBadgeClass(item.status_YN)]">
  81. {{ getStatusLabel(item.status_YN) }}
  82. </span>
  83. </td>
  84. <td class="date">{{ formatDate(item.created_at) }}</td>
  85. <td>
  86. <div class="admin--table-actions">
  87. <button class="admin--btn-small admin--btn-blue" @click.stop="goToEdit(item.id)">
  88. 수정
  89. </button>
  90. </div>
  91. </td>
  92. </tr>
  93. </tbody>
  94. </table>
  95. </div>
  96. <!-- 페이지네이션 -->
  97. <div v-if="totalPages > 1" class="admin--pagination">
  98. <button
  99. v-if="totalPages > 2"
  100. class="admin--pagination-btn"
  101. :disabled="currentPage === 1"
  102. @click="changePage(1)"
  103. title="처음"
  104. >
  105. ◀◀
  106. </button>
  107. <button
  108. class="admin--pagination-btn"
  109. :disabled="currentPage === 1"
  110. @click="changePage(currentPage - 1)"
  111. title="이전"
  112. >
  113. </button>
  114. <button
  115. v-for="page in visiblePages"
  116. :key="page"
  117. class="admin--pagination-btn"
  118. :class="{ 'is-active': page === currentPage }"
  119. @click="changePage(page)"
  120. >
  121. {{ page }}
  122. </button>
  123. <button
  124. class="admin--pagination-btn"
  125. :disabled="currentPage === totalPages"
  126. @click="changePage(currentPage + 1)"
  127. title="다음"
  128. >
  129. </button>
  130. <button
  131. v-if="totalPages > 2"
  132. class="admin--pagination-btn"
  133. :disabled="currentPage === totalPages"
  134. @click="changePage(totalPages)"
  135. title="끝"
  136. >
  137. ▶▶
  138. </button>
  139. </div>
  140. </div>
  141. </template>
  142. <script setup>
  143. import { ref, computed, onMounted } from "vue";
  144. import { useRouter } from "vue-router";
  145. import DatePicker from "~/components/admin/DatePicker.vue";
  146. definePageMeta({
  147. layout: "admin",
  148. middleware: ["auth"],
  149. });
  150. const router = useRouter();
  151. const { get } = useApi();
  152. const isLoading = ref(false);
  153. const onboards = ref([]);
  154. const currentPage = ref(1);
  155. const perPage = ref(10);
  156. const totalCount = ref(0);
  157. const totalPages = ref(0);
  158. const searchField = ref(""); // '', field, area, name
  159. const searchQuery = ref("");
  160. const filterPartnership = ref(""); // '', Y, N
  161. const filterStatus = ref(""); // '', Y, N
  162. const startDate = ref(""); // YYYY-MM-DD
  163. const endDate = ref(""); // YYYY-MM-DD
  164. // YYYY-MM-DD 포맷터
  165. const toYMD = (d) => {
  166. const y = d.getFullYear();
  167. const m = String(d.getMonth() + 1).padStart(2, "0");
  168. const day = String(d.getDate()).padStart(2, "0");
  169. return `${y}-${m}-${day}`;
  170. };
  171. // 빠른 기간 선택 (오늘 기준)
  172. const setRange = (kind) => {
  173. const today = new Date();
  174. const end = toYMD(today);
  175. const startDt = new Date();
  176. switch (kind) {
  177. case "today":
  178. break;
  179. case "7d":
  180. startDt.setDate(startDt.getDate() - 7);
  181. break;
  182. case "15d":
  183. startDt.setDate(startDt.getDate() - 15);
  184. break;
  185. case "1m":
  186. startDt.setMonth(startDt.getMonth() - 1);
  187. break;
  188. case "3m":
  189. startDt.setMonth(startDt.getMonth() - 3);
  190. break;
  191. case "1y":
  192. startDt.setFullYear(startDt.getFullYear() - 1);
  193. break;
  194. }
  195. startDate.value = toYMD(startDt);
  196. endDate.value = end;
  197. onSearch();
  198. };
  199. // 보이는 페이지 번호 계산
  200. const visiblePages = computed(() => {
  201. const pages = [];
  202. const maxVisible = 5;
  203. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  204. let end = Math.min(totalPages.value, start + maxVisible - 1);
  205. if (end - start < maxVisible - 1) {
  206. start = Math.max(1, end - maxVisible + 1);
  207. }
  208. for (let i = start; i <= end; i++) {
  209. pages.push(i);
  210. }
  211. return pages;
  212. });
  213. // 데이터 로드
  214. const loadOnboards = async () => {
  215. isLoading.value = true;
  216. const params = {
  217. page: currentPage.value,
  218. per_page: perPage.value,
  219. };
  220. if (searchQuery.value) {
  221. params.search = searchQuery.value;
  222. if (searchField.value) params.search_field = searchField.value;
  223. }
  224. if (filterPartnership.value) params.partnership = filterPartnership.value;
  225. if (filterStatus.value) params.status = filterStatus.value;
  226. if (startDate.value) params.start_date = startDate.value;
  227. if (endDate.value) params.end_date = endDate.value;
  228. const { data, error } = await get("/admin", { params });
  229. if (error) {
  230. console.error("[OnboardList] 목록 로드 실패:", error);
  231. onboards.value = [];
  232. totalCount.value = 0;
  233. totalPages.value = 0;
  234. } else if (data?.success && data?.data) {
  235. onboards.value = data.data.items || [];
  236. totalCount.value = data.data.total || 0;
  237. totalPages.value = data.data.total_pages || 0;
  238. }
  239. isLoading.value = false;
  240. };
  241. // 검색
  242. const onSearch = () => {
  243. currentPage.value = 1;
  244. loadOnboards();
  245. };
  246. // 검색 초기화
  247. const resetSearch = () => {
  248. searchField.value = "";
  249. searchQuery.value = "";
  250. filterPartnership.value = "";
  251. filterStatus.value = "";
  252. startDate.value = "";
  253. endDate.value = "";
  254. currentPage.value = 1;
  255. loadOnboards();
  256. };
  257. // 페이지 변경
  258. const changePage = (page) => {
  259. if (page < 1 || page > totalPages.value) return;
  260. currentPage.value = page;
  261. loadOnboards();
  262. window.scrollTo({ top: 0, behavior: "smooth" });
  263. };
  264. // 이동
  265. const goToCreate = () => router.push("/site-manager/onboard/create");
  266. const goToDetail = (id) => router.push(`/site-manager/onboard/detail/${id}`);
  267. const goToEdit = (id) => router.push(`/site-manager/onboard/edit/${id}`);
  268. // 상태 라벨 / 뱃지 클래스
  269. const getStatusLabel = (status) => (status === "Y" ? "사용중" : "미사용");
  270. const getStatusBadgeClass = (status) =>
  271. status === "Y" ? "admin--badge-active" : "admin--badge-ended";
  272. // 날짜 포맷
  273. const formatDate = (dateString) => {
  274. if (!dateString) return "-";
  275. const date = new Date(dateString.replace(" ", "T"));
  276. if (isNaN(date.getTime())) return dateString;
  277. return date.toLocaleDateString("ko-KR", {
  278. year: "numeric",
  279. month: "2-digit",
  280. day: "2-digit",
  281. });
  282. };
  283. onMounted(() => {
  284. loadOnboards();
  285. });
  286. </script>