jichoi / lms_front star
이은진 이은진 08-21
240821 이은진 사진 좋아요 수정
@753845473f5a02e8043fb4db2273d156a98b4169
client/views/pages/main/Dashboard.vue
--- client/views/pages/main/Dashboard.vue
+++ client/views/pages/main/Dashboard.vue
@@ -232,8 +232,13 @@
                             <span class=" title1 ml30">{{ selectedImage.unit }}을 마친 <em class="yellow">{{
                                 selectedImage.name }}</em>친구</span>
                         </div>
-                        <div class="title2 flex align-center" style="gap: 10px;"><svg-icon type="mdi" :path="mdiHeart"
-                                style="color: #FFBA08;"></svg-icon>
+                        <div class="title2 flex align-center" style="gap: 10px;">
+                            <svg-icon v-if="!isHeartFilled" type="mdi" :path="mdiHeartOutline"
+                                @click="toggleHeart(selectedImage.heart, selectedImage.fileMngId)"
+                                style="color: #FFBA08; cursor: pointer;"></svg-icon>
+                            <svg-icon v-if="isHeartFilled" type="mdi" :path="mdiHeart"
+                                @click="toggleHeart(selectedImage.heart, selectedImage.fileMngId)"
+                                style="color: #FFBA08; cursor: pointer;"></svg-icon>
                             <p><em class="yellow">{{ selectedImage.heart }}</em></p>
                         </div>
                     </div>
@@ -246,7 +251,9 @@
 <script>
 import SvgIcon from '@jamescoyle/vue-icon';
 import { mdiMagnify, mdiHeart, mdiWindowClose } from '@mdi/js';
+import { mdiHeartOutline } from '@mdi/js';
 import axios from 'axios';
+import { call } from 'file-loader';
 import { name } from 'file-loader';
 import { mapGetters } from 'vuex';
 import { mapActions } from "vuex";
@@ -266,6 +273,7 @@
             mdiMagnify: mdiMagnify,
             mdiWindowClose: mdiWindowClose,
             mdiHeart: mdiHeart,
+            mdiHeartOutline: mdiHeartOutline,
             showModal: false,
             searchOpen: false,  // 사진 상세보기 모달창
             searchOpen2: false, // 단원 마친 후, 사진 촬영 여부 선택 모달창
@@ -305,12 +313,33 @@
                     unit: '',
                     date: '',
                     name: '',
-                    heart: ''
+                    heart: '',
+                    fileMngId: '',
                 },
             ],
+
+            isHeartFilled: false, // 하트가 채워졌는지 여부
         }
     },
     methods: {
+        toggleHeart(heart, fileMngId) {
+            this.isHeartFilled = !this.isHeartFilled; // 하트 상태 토글
+
+            if (this.isHeartFilled) var calHeart = heart + 1;
+            else var calHeart = heart - 1
+
+            // 하트 수를 증가시키기 위한 API 요청
+            axios.post('/photo/likeUpdate.json', {
+                "likeData": calHeart,
+                "fileMngId": fileMngId
+            })
+                .then(response => {
+                    this.selectedImage.heart = calHeart;
+                })
+                .catch(error => {
+                    console.error("Error updating heart:", error);
+                });
+        },
         checkAndFetchData() {
             console.log("받은 Book ID:", this.getBookId);
             console.log("받은 Unit ID:", this.getUnitId);
@@ -336,11 +365,13 @@
 
         //은진
         buttonSearch(image) {
+            this.isHeartFilled = false;
             this.selectedImage.name = image.stdId;
             this.selectedImage.image = image.url;
             this.selectedImage.unit = this.titleUnitName;
             this.selectedImage.date = image.fileRegDate.split(" ")[0];
             this.selectedImage.heart = image.likeData;
+            this.selectedImage.fileMngId = image.fileMngId;
             this.searchOpen = true;
         },
         fetchImage(unit_id) {
@@ -365,7 +396,6 @@
                     return Promise.all(findFilePromises);
                 })
                 .then(fileResults => {
-                    // Assuming this.file and fileResults are of the same length
                     this.images = this.file.map((file, index) => {
                         const result = fileResults[index];
                         if (result) {
@@ -374,8 +404,9 @@
                                 fileId: result.fileId,
                                 fileNm: result.fileNm,
                                 fileRegDate: result.regDt,
-                                likeData: file.like_data,  // Add like_data from this.file
-                                stdId: file.user_nm         // Add std_id from this.file
+                                likeData: file.like_data,
+                                stdId: file.user_nm,
+                                fileMngId: result.fileMngId,
                             };
                         }
                         return null;
@@ -555,8 +586,9 @@
                     this.closeModal(); // 모달창을 닫음
                 });
         },
-        closeModal() {  //웹캠 및 모든 팝업 닫기
-            // this.showModal = false;
+        closeModal() {
+
+
             this.searchOpen = false;
             this.searchOpen2 = false;
             this.showCameraModal = false;
client/views/pages/main/PhotoBook.vue
--- client/views/pages/main/PhotoBook.vue
+++ client/views/pages/main/PhotoBook.vue
@@ -6,46 +6,25 @@
     <div>
       <div class="title-box flex justify-end mb40">
         <select name="" id="">
-          <option
-            v-for="classItem in classList"
-            :key="classItem.sclsId"
-            :value="classItem.sclsId"
-            @click="
-              currentPage = 1;
-              stdPhotoSelectList(classItem.sclsId);
-            "
-          >
+          <option v-for="classItem in classList" :key="classItem.sclsId" :value="classItem.sclsId" @click="
+            currentPage = 1;
+          stdPhotoSelectList(classItem.sclsId);
+          ">
             {{ classItem.sclsNm }}
           </option>
         </select>
       </div>
       <div class="btnGroup" style="display: flex; flex-direction: column">
-        <button
-          v-for="n in totalPages"
-          :key="n"
-          @click="changePage(n)"
-          type="button"
-          title="페이지 버튼"
-          class="tab-btn"
-        >
-          <img
-            v-if="currentPage !== n"
-            src="../../../resources/img/btn49_15s_normal.png"
-            alt=""
-          />
+        <button v-for="n in totalPages" :key="n" @click="changePage(n)" type="button" title="페이지 버튼" class="tab-btn">
+          <img v-if="currentPage !== n" src="../../../resources/img/btn49_15s_normal.png" alt="" />
           <img v-else src="../../../resources/img/btn49_15s_click.png" alt="" />
           <p :class="{ 'custom-style': currentPage === n }">{{ n }}</p>
         </button>
       </div>
       <div v-if="selectedTab === 'tab1'" class="tab-box">
         <div class="flex justify-between">
-          <div
-            v-for="(photo, index) in (photoList?.result || []).slice(0, 3)"
-            :key="index"
-            class="photo"
-            :style="{ transform: getRotation(index) }"
-            @click="buttonSearch(photo)"
-          >
+          <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 class="photo-container">
@@ -60,21 +39,12 @@
           </div>
         </div>
         <div class="flex justify-between mt20">
-          <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 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 class="photo-container">
-                  <img
-                    :src="fetchImage(photo.fileRpath)"
-                    alt=""
-                    style="width: 150px"
-                  />
+                  <img :src="fetchImage(photo.fileRpath)" alt="" style="width: 150px" />
                 </div>
               </div>
               <div class="photo-text mt10 ml10">
@@ -90,32 +60,20 @@
           <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>
+              <svg-icon type="mdi" :path="mdiWindowClose" class="close-btn"></svg-icon>
             </button>
           </div>
 
-          <div
-            class="photo-modal flex justify-between mt20"
-            v-if="photoData.length > 0"
-          >
+          <div class="photo-modal flex justify-between mt20" v-if="photoData.length > 0">
             <div class="box">
               <div>
-                <img
-                  :src="fetchImage(photoData[0].fileRpath)"
-                  alt=""
-                  style="width: 640px; height: 480px"
-                />
+                <img :src="fetchImage(photoData[0].fileRpath)" alt="" style="width: 640px; height: 480px" />
               </div>
             </div>
             <div class="photo-title-container">
               <div class="title1">
                 {{ photoData[0].unitName }}을 마친
-                <em class="yellow">{{ photoData[0].stdName }}</em
-                >친구
+                <em class="yellow">{{ photoData[0].stdName }}</em>친구
               </div>
               <p class="title2 date">{{ photoData[0].photoDate }}</p>
             </div>
@@ -324,14 +282,16 @@
 };
 </script>
 
-<style>
+<style scoped>
 .btnGroup button {
   cursor: pointer;
   z-index: 100000;
 }
+
 .popup-wrap {
   z-index: 10000000;
 }
+
 .popup-box {
   top: 500px;
   width: 950px;
@@ -357,6 +317,7 @@
   flex-direction: column;
   gap: 5px;
 }
+
 .photo-modal {
   flex-direction: column;
 }
Add a comment
List