jichoi / lms_front star
guntaek 2024-08-09
240809 김건택 내 사진첩 조회
@cad2408eb8e8fede17a3a86535c36b306b0248a4
client/views/pages/main/PhotoBook.vue
--- client/views/pages/main/PhotoBook.vue
+++ client/views/pages/main/PhotoBook.vue
@@ -6,7 +6,9 @@
        <div>
             <div class="title-box flex justify-end mb40">
                 <select name="" id="">
-                    <option value="">A반</option>
+                    <option v-for="classItem in classList" :key="classItem.sclsId" :value="classItem.sclsId" @click="stdPhotoSelectList(classItem.sclsId)">
+                        {{ classItem.sclsNm }}
+                    </option>
                 </select>
             </div>
             <div class="btnGroup">
@@ -15,87 +17,43 @@
                     <img v-else src="../../../resources/img/btn49_15s_click.png" alt="">
                     <p :class="{ 'custom-style': selectedTab === 'tab1' }">1</p>
                 </button>
+                <button @click="selectedTab = 'tab2'" type="button" title="글쓰기" class="tab-btn">
+                    <img v-if="selectedTab !== 'tab2'" src="../../../resources/img/btn49_15s_normal.png" alt="">
+                    <img v-else src="../../../resources/img/btn49_15s_click.png" alt="">
+                    <p :class="{ 'custom-style': selectedTab === 'tab2' }">2</p>
+                </button>
             </div>
             <div v-if="selectedTab === 'tab1'" class="tab-box">
                 <div class="flex justify-between">
-                    <div class="photo" style="transform: rotate(2deg);" @click="buttonSearch">
-                        <div class="class ">
+                    <div v-for="(photo, index) in (photoList?.result || []).slice(0, 3)" :key="index" class="photo" :style="{ transform: getRotation(index) }" @click="buttonSearch(photo)">
+                        <div class="class">
                             <div class="box">
                                 <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
                             </div>
                             <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[0].likeData }}</span>
-                                <p class="title2">{{ photoList.result[0].unitName }}</p>
+                                <span class="member ml30">{{ photo.likeData }}</span>
+                                <p class="title2">{{ photo.unitName }}</p>
                             </div>
-                        </div>
-                    </div>
-                    <div class="photo" style="transform: rotate(-1deg);" @click="buttonSearch">
-                        <div class="class photo">
-                            <div class="box">
-                                <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
-                            </div>
-                            <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[1].likeData }}</span>
-                                <p class="title2">{{ photoList.result[1].unitName }}</p>
-                            </div>
-    
-                        </div>
-                    </div>
-                    <div class="photo" style="transform: rotate(1deg);" @click="buttonSearch">
-                        <div class="class ">
-                            <div class="box">
-                                <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
-                            </div>
-                            <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[2].likeData }}</span>
-                                <p class="title2">{{ photoList.result[2].unitName }}</p>
-                            </div>
-    
                         </div>
                     </div>
                 </div>
                 <div class="flex justify-between mt50">
-                    <div class="photo" style="transform: rotate(-2deg);" @click="buttonSearch">
-                        <div class="class ">
+                    <div v-for="(photo, index) in (photoList?.result || []).slice(3, 6)" :key="index + 3" class="photo" :style="{ transform: getRotation(index + 3) }" @click="buttonSearch(photo)">
+                        <div class="class">
                             <div class="box">
                                 <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
                             </div>
                             <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[3].likeData }}</span>
-                                <p class="title2">{{ photoList.result[3].unitName }}</p>
-                            </div>
-    
-                        </div>
-                    </div>
-                    <div class="photo" style="transform: rotate(1deg);" @click="buttonSearch">
-                        <div class="class ">
-                            <div class="box">
-                                <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
-                            </div>
-                            <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[4].likeData }}</span>
-                                <p class="title2">{{ photoList.result[4].unitName }}</p>
-                            </div>
-    
-                        </div>
-                    </div>
-                    <div class="photo" style="transform: rotate(-1deg);" @click="buttonSearch">
-                        <div class="class ">
-                            <div class="box">
-                                <div><img src="../../../resources/img/img213_15s.png" alt=""></div>
-                            </div>
-                            <div class="text flex justify-between mt20">
-                                <span class="member ml30">{{ photoList.result[5].likeData }}</span>
-                                <p class="title2">{{ photoList.result[5].unitName }}</p>
+                                <span class="member ml30">{{ photo.likeData }}</span>
+                                <p class="title2">{{ photo.unitName }}</p>
                             </div>
                         </div>
                     </div>
                 </div>
-    
             </div>
             <div class="popup-wrap" v-show="searchOpen">
-                <div class="popup-box ">
-                    <div class="flex mb10  justify-between">
+                <div class="popup-box">
+                    <div class="flex mb10 justify-between">
                         <p class="popup-title">알림</p>
                         <button type="button" class="popup-close-btn" @click="closeBtn">
                             <svg-icon type="mdi" :path="mdiWindowClose" class="close-btn"></svg-icon>
@@ -104,12 +62,16 @@
                     <div class="box">
                         <div><img src="../../../resources/img/img184_91t.png" alt=""></div>
                     </div>
-                    <div class="text flex justify-between mt20">
-                        <span class=" title1">1단원을 마친 <em class="yellow">가나다</em>친구</span>
-                        <p class="title2 date">2024-08-06</p>
+                    <div class="text flex justify-between mt20" v-if="photoData.length > 0">
+                        <span class="title1">{{ photoData[0].unitName }}을 마친 <em class="yellow">{{ photoData[0].stdName }}</em>친구</span>
+                        <p class="title2 date">{{ photoData[0].photoDate }}</p>
+                    </div>
+                    <div class="text flex justify-between mt20" v-else>
+                        <span class="title1">데이터를 불러올 수 없습니다.</span>
                     </div>
                 </div>
             </div>
+
        </div>
     </div>
 </template>
@@ -128,9 +90,11 @@
             classList: [],
             photoList: [],
 
-            page: 1,
+            photoData: [],
+
+            currentPage: 1,
             pageSize: 6,
-            totalpages: null,
+            totalPages: 2,
 
             mdiWindowClose: mdiWindowClose,
             selectedTab: 'tab1',
@@ -158,7 +122,8 @@
             })
             .then(function (response) {
                 console.log("classList - response : ", response.data);
-                vm.classList = response.data;
+                vm.classList = response.data.data;
+                vm.currentPage = 1;
             })
             .catch(function (error) {
                 console.log("classList - error : ", error);
@@ -166,7 +131,7 @@
             });
         },
 
-        stdPhotoSelectList: function () {
+        stdPhotoSelectList: function (sclsId) {
             const vm = this;
             axios({
                 url: "/photo/stdPhotoList.json",
@@ -176,14 +141,15 @@
                 },
                 data: {
                         "stdId":"1",
-                        "sclsId":"1",
-                        page: vm.page,
+                        "sclsId":"1", // 여기에 sclsId들어가야함
+                        page: vm.currentPage,
                         pageSize: vm.pageSize
                 }
             })
             .then(function (response) {
                 console.log("photoList - response : ", response.data);
                 vm.photoList = response.data;
+                vm.totalPages = Math.ceil(response.data.length / vm.pageSize);
             })
             .catch(function (error) {
                 console.log("photoList - error : ", error);
@@ -191,15 +157,46 @@
             });
         },
 
+        getRotation(index) {
+            const rotations = [2, -1, 1, -2, 1, -1];
+            return `rotate(${rotations[index]}deg)`;
+        },
+
+        changePage(pageNumber) {
+            this.currentPage = pageNumber;
+            this.stdPhotoSelectList(this.selectedClassId);
+        },
+
         closeModal() {
             this.showModal = false;
         },
-        buttonSearch() {
+        buttonSearch(photo) {
+            if(!photo) return;
+
+            const vm = this;
             this.searchOpen = true;
+            axios({
+                url: "/photo/photoDetail.json",
+                method: "post",
+                headers:{
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                        "photoId":photo.photoId
+                }
+            })
+            .then(function (response) {
+                console.log("photoData - response : ", response.data);
+                vm.photoData = response.data;
+            })
+            .catch(function (error) {
+                console.log("photoData - error : ", error);
+                alert("사진 조회에 오류가 발생했습니다.");
+            });
         },
+
         closeBtn() {
             this.searchOpen = false;
-
         },
         goToPage(page) {
             this.$router.push({ name: page });
@@ -228,7 +225,12 @@
 
     },
     computed: {
-
+        currentPhotos() {
+            // 현재 페이지에 해당하는 사진들만 반환
+            const start = (this.currentPage - 1) * this.pageSize;
+            const end = start + this.pageSize;
+            return this.photoList.result.slice(start, end);
+        }
     },
     components: {
         SvgIcon,
Add a comment
List