patents.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <main>
  3. <TopVisual :className="className" :title="title" :navigation="navigation" />
  4. <section class="title--section">
  5. <div class="sub--container type2">
  6. <div class="title--wrap">
  7. <h2 class="title">
  8. 그린웨일글로벌은 까다롭기로 유명한 <br />
  9. <strong>친환경 플라스틱 관련 미국 특허 및 유럽 인증을 획득</strong>하여
  10. <br />그 기술력을 입증받았습니다.
  11. </h2>
  12. </div>
  13. <div class="tab--wrap">
  14. <a @click="filterByCategory('all')" :class="{ active: selectedCategory === 'all' }" href="javascript:void(0)">전체</a>
  15. <a @click="filterByCategory('technology1')" :class="{ active: selectedCategory === 'technology1' }" href="javascript:void(0)">특허증</a>
  16. <a @click="filterByCategory('technology2')" :class="{ active: selectedCategory === 'technology2' }" href="javascript:void(0)">인증서</a>
  17. <a @click="filterByCategory('technology3')" :class="{ active: selectedCategory === 'technology3' }" href="javascript:void(0)">성적서</a>
  18. <a @click="filterByCategory('technology4')" :class="{ active: selectedCategory === 'technology4' }" href="javascript:void(0)">MSD&TDS</a>
  19. </div>
  20. <div class="patents--wrap">
  21. <div class="patents--list">
  22. <UModal
  23. v-for="patent in paginatedPatents"
  24. :key="patent.id"
  25. v-model:open="isModalOpen"
  26. title="특허 / 인증 크게보기"
  27. :close="false"
  28. >
  29. <UButton @click="openModal(patent.image)" class="patents">
  30. <div class="img--wrap">
  31. <img :src="patent.image" alt="" />
  32. </div>
  33. <h4>{{ patent.title }}</h4>
  34. </UButton>
  35. <template #content>
  36. <UButton @click="isModalOpen = false" class="modal--close--btn"></UButton>
  37. <div class="modal--img--container">
  38. <img :src="selectedImage" alt="" />
  39. </div>
  40. </template>
  41. </UModal>
  42. </div>
  43. <div class="pagination--wrap">
  44. <UButton
  45. @click="prevPage"
  46. class="prev--btn"
  47. :disabled="currentPage === 1"
  48. ></UButton>
  49. <div class="numbs">
  50. <UButton
  51. v-for="page in totalPages"
  52. :key="page"
  53. @click="goToPage(page)"
  54. :class="{ active: currentPage === page }"
  55. >
  56. {{ page }}
  57. </UButton>
  58. </div>
  59. <UButton
  60. @click="nextPage"
  61. class="next--btn"
  62. :disabled="currentPage === totalPages"
  63. ></UButton>
  64. </div>
  65. </div>
  66. </div>
  67. </section>
  68. </main>
  69. </template>
  70. <script setup>
  71. import { ref, computed, onMounted } from "vue";
  72. import TopVisual from "~/components/topVisual.vue";
  73. const className = ref("technology");
  74. const title = ref("Technology");
  75. const isModalOpen = ref(false);
  76. const loading = ref(true);
  77. const patentsData = ref([]);
  78. const totalCount = ref(0);
  79. const selectedCategory = ref('all');
  80. const allPatentsData = ref([]); // 전체 데이터 저장용
  81. const navigation = ref([
  82. {
  83. name: "Technology",
  84. link: "/technology/patents",
  85. gnbList: [
  86. { name: "Company", link: "/company/intro" },
  87. { name: "Product", link: "/products/materials" },
  88. { name: "Technology", link: "/technology/facilities" },
  89. { name: "Media", link: "/media/news" },
  90. { name: "Contact", link: "/contact/notice" },
  91. ],
  92. },
  93. {
  94. name: "특허 / 인증",
  95. link: "/technology/patents",
  96. gnbList: [
  97. { name: "시설", link: "/technology/facilities" },
  98. { name: "특허 / 인증", link: "/technology/patents" },
  99. ],
  100. },
  101. ]);
  102. const selectedImage = ref("/img/img--patents.png");
  103. // 전체 데이터 가져오기 (4개 API 합쳐서)
  104. const fetchAllPatents = async () => {
  105. try {
  106. loading.value = true;
  107. const apis = ['technology1', 'technology2', 'technology3', 'technology4'];
  108. let allData = [];
  109. for (const api of apis) {
  110. const response = await $postForm(`/board_list/${api}`, {
  111. boardId: api,
  112. page: 1,
  113. searchKind: "",
  114. searchKeyword: "",
  115. });
  116. if (response && response.success && response.list) {
  117. const categoryName = getCategoryName(api);
  118. const categoryData = response.list.map((item, index) => ({
  119. id: `${api}_${item.board_idx || index}`,
  120. title: item.title,
  121. category: categoryName,
  122. image: item.main_file1
  123. ? `http://green.interscope.co.kr/backend${item.main_file1}`
  124. : "/img/img--patents.png",
  125. }));
  126. allData = [...allData, ...categoryData];
  127. }
  128. }
  129. patentsData.value = allData;
  130. totalCount.value = allData.length;
  131. } catch (error) {
  132. console.error("전체 데이터 로드 실패:", error);
  133. setDefaultPatentsData();
  134. } finally {
  135. loading.value = false;
  136. }
  137. };
  138. // 카테고리별 데이터 가져오기
  139. const fetchPatentsByCategory = async (category) => {
  140. try {
  141. loading.value = true;
  142. const response = await $postForm(`/board_list/${category}`, {
  143. boardId: category,
  144. page: 1,
  145. searchKind: "",
  146. searchKeyword: "",
  147. });
  148. if (response && typeof response === "object") {
  149. if (response.success && response.list) {
  150. totalCount.value = response.totalCount || response.list.length;
  151. const categoryName = getCategoryName(category);
  152. patentsData.value = response.list.map((item, index) => ({
  153. id: `${category}_${item.board_idx || index}`,
  154. title: item.title,
  155. category: categoryName,
  156. image: item.main_file1
  157. ? `http://green.interscope.co.kr/backend${item.main_file1}`
  158. : "/img/img--patents.png",
  159. }));
  160. } else {
  161. console.error("JSON 응답 형식이 올바르지 않습니다:", response);
  162. setDefaultPatentsData();
  163. }
  164. } else {
  165. console.error("예상하지 못한 응답 형식:", typeof response, response);
  166. setDefaultPatentsData();
  167. }
  168. } catch (error) {
  169. console.error("특허/인증 데이터 로드 실패:", error);
  170. setDefaultPatentsData();
  171. } finally {
  172. loading.value = false;
  173. }
  174. };
  175. // 카테고리 이름 맵핑
  176. const getCategoryName = (apiName) => {
  177. const categoryMap = {
  178. 'technology1': '특허증',
  179. 'technology2': '인증서',
  180. 'technology3': '성적서',
  181. 'technology4': 'MSD&TDS'
  182. };
  183. return categoryMap[apiName] || '기타';
  184. };
  185. // 기본 더미 데이터 설정
  186. const setDefaultPatentsData = () => {
  187. patentsData.value = [
  188. {
  189. id: 1,
  190. title: "플라스틱 감축 소재 인증서",
  191. image: "/img/img--patents.png",
  192. },
  193. {
  194. id: 2,
  195. title: "플라스틱 감축 소재 인증서",
  196. image: "/img/top_ban_technology.jpg",
  197. },
  198. ];
  199. };
  200. // 카테고리별 필터링 함수
  201. const filterByCategory = async (category) => {
  202. selectedCategory.value = category;
  203. currentPage.value = 1;
  204. if (category === 'all') {
  205. await fetchAllPatents();
  206. } else {
  207. await fetchPatentsByCategory(category);
  208. }
  209. };
  210. // 페이지네이션 로직
  211. const currentPage = ref(1);
  212. const itemsPerPage = 8;
  213. const backendPageSize = 20;
  214. const totalPages = computed(() => Math.ceil(totalCount.value / itemsPerPage));
  215. const paginatedPatents = computed(() => {
  216. const start = (currentPage.value - 1) * itemsPerPage;
  217. const end = start + itemsPerPage;
  218. return patentsData.value.slice(start, end);
  219. });
  220. const needToFetchData = (targetPage) => {
  221. const startIndex = (targetPage - 1) * itemsPerPage;
  222. const endIndex = startIndex + itemsPerPage - 1;
  223. return endIndex >= patentsData.value.length && patentsData.value.length < totalCount.value;
  224. };
  225. const goToPage = (page) => {
  226. if (page >= 1 && page <= totalPages.value) {
  227. currentPage.value = page;
  228. }
  229. };
  230. const nextPage = async () => {
  231. if (currentPage.value < totalPages.value) {
  232. await goToPage(currentPage.value + 1);
  233. }
  234. };
  235. const prevPage = async () => {
  236. if (currentPage.value > 1) {
  237. await goToPage(currentPage.value - 1);
  238. }
  239. };
  240. const openModal = (imagePath) => {
  241. selectedImage.value = imagePath;
  242. isModalOpen.value = true;
  243. };
  244. // 컴포넌트 마운트 시 데이터 로드
  245. onMounted(() => {
  246. fetchAllPatents(); // 초기에는 전체 데이터 로드
  247. });
  248. </script>