| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <template>
- <main>
- <TopVisual :className="className" :title="title" :navigation="navigation" />
- <section class="notice--section">
- <div class="sub--container type2">
- <div class="title--wrap">
- <h2 class="title">공지사항</h2>
- </div>
- <div class="search--wrap">
- <USelect v-model="searchValue" :items="searchItems" />
- <UInput v-model="searchKeyword" placeholder="검색어를 입력해주세요." />
- <UButton class="search--btn"></UButton>
- </div>
- <div class="notice--wrap">
- <div class="notice--list">
- <NuxtLink
- v-for="news in paginatedNews"
- :key="news.id"
- :to="news.link"
- class="notice"
- >
- <span class="news--index">{{ news.id }}</span>
- <h4>{{ news.title }}</h4>
- <span class="news--date">{{ news.date }}</span>
- </NuxtLink>
- </div>
- <div class="pagination--wrap">
- <UButton
- @click="prevPage"
- class="prev--btn"
- :disabled="currentPage === 1"
- ></UButton>
- <div class="numbs">
- <UButton
- v-for="page in totalPages"
- :key="page"
- @click="goToPage(page)"
- :class="{ active: currentPage === page }"
- >
- {{ page }}
- </UButton>
- </div>
- <UButton
- @click="nextPage"
- class="next--btn"
- :disabled="currentPage === totalPages"
- ></UButton>
- </div>
- </div>
- </div>
- </section>
- </main>
- </template>
- <script setup>
- import { ref, computed, onMounted } from "vue";
- import TopVisual from "~/components/topVisual.vue";
- const searchItems = ref(["제목"]);
- const searchValue = ref("선택");
- const searchKeyword = ref("");
- const loading = ref(true);
- const className = ref("contact");
- const title = ref("Contact");
- const navigation = ref([
- {
- name: "Contact",
- link: "/contact/notice",
- gnbList: [
- { name: "Company", link: "/company/intro" },
- { name: "Product", link: "/products/materials" },
- { name: "Technology", link: "/technology/facilities" },
- { name: "Media", link: "/media/news" },
- { name: "Contact", link: "/contact/notice" },
- ],
- },
- {
- name: "공지사항",
- link: "/contact/notice",
- gnbList: [
- { name: "공지사항", link: "/contact/notice" },
- { name: "FAQ", link: "/contact/faq" },
- { name: "고객센터", link: "/contact/support" },
- { name: "오시는길", link: "/contact/location" },
- ],
- },
- ]);
- // 뉴스 데이터 배열 - API에서 받아올 것
- const newsData = ref([]);
- // API에서 공지사항 데이터 가져오기
- const fetchNoticeList = async (page = 1) => {
- try {
- loading.value = true;
- // CodeIgniter 방식으로 호출 (/controller/method/param)
- const response = await $get(`/board_list/notice`, {
- page: page,
- searchKind: searchValue.value,
- searchKeyword: searchKeyword.value,
- });
- // 백엔드가 JSON으로 응답하는지 확인
- if (response && typeof response === "object") {
- // JSON 응답인 경우
- if (response.success && response.list) {
- // 전체 개수와 현재 페이지를 기준으로 번호 계산
- const totalCount = response.totalCount || 0;
- const currentPageNum = page || 1;
- const pageSize = 20; // 백엔드의 페이지 사이즈와 동일
- newsData.value = response.list.map((item, index) => {
- // 번호 = 전체개수 - ((현재페이지-1) * 페이지크기 + 인덱스)
- const displayNumber = totalCount - ((currentPageNum - 1) * pageSize + index);
- return {
- id: displayNumber, // 순차적인 번호로 표시
- title: item.title,
- date: item.regdate,
- link: `/contact/noticeView?idx=${item.board_idx}`, // 실제 링크는 board_idx 사용
- };
- });
- } else {
- console.error("JSON 응답 형식이 올바르지 않습니다:", response);
- newsData.value = [];
- }
- } else if (typeof response === "string") {
- // HTML 응답인 경우 (백엔드에서 AJAX 감지 실패시)
- console.warn("HTML 응답을 받았습니다. AJAX 감지가 실패했을 수 있습니다.");
- console.log("HTML 내용:", response.substring(0, 200) + "...");
- newsData.value = [];
- } else {
- console.error("예상하지 못한 응답 형식:", typeof response, response);
- newsData.value = [];
- }
- } catch (error) {
- console.error("공지사항 데이터 로드 실패:", error);
- // 에러시 기본 더미 데이터 사용
- } finally {
- loading.value = false;
- }
- };
- // 페이지네이션 로직
- const currentPage = ref(1);
- const itemsPerPage = 10;
- const totalPages = computed(() => Math.ceil(newsData.value.length / itemsPerPage));
- const paginatedNews = computed(() => {
- const start = (currentPage.value - 1) * itemsPerPage;
- const end = start + itemsPerPage;
- return newsData.value.slice(start, end);
- });
- const goToPage = (page) => {
- if (page >= 1 && page <= totalPages.value) {
- currentPage.value = page;
- fetchNoticeList(page);
- }
- };
- const nextPage = () => {
- if (currentPage.value < totalPages.value) {
- currentPage.value++;
- fetchNoticeList(currentPage.value);
- }
- };
- const prevPage = () => {
- if (currentPage.value > 1) {
- currentPage.value--;
- fetchNoticeList(currentPage.value);
- }
- };
- // 컴포넌트 마운트 시 데이터 로드
- onMounted(() => {
- fetchNoticeList(1);
- });
- </script>
|