jichoi / lms_front star
이은진 이은진 08-20
240820 이은진 사진 저장/가져오기
@523f03fd6cf0174670dd19a370126873c59290c1
client/views/pages/main/AIDashboard.vue
--- client/views/pages/main/AIDashboard.vue
+++ client/views/pages/main/AIDashboard.vue
@@ -223,7 +223,7 @@
                                     <p>재촬영</p>
                                 </button>
 
-                                <button class="login-btn" type="submit" @click="goToPage('PhotoEdit')">
+                                <button class="login-btn" type="submit" @click="goToPageImg('PhotoEdit')">
                                     <img src="../../../resources/img/btn07_s.png" alt="">
                                     <p>완성</p>
                                 </button>
@@ -266,11 +266,11 @@
                 <p>학습 종료하기</p>
             </button>
             <h2 class="mb40 mt10">이 단원을 끝낸 친구들</h2>
-            <article class=" flex-column" style="gap: 5px;">
+            <article class="flex-column" style="gap: 5px;">
                 <div class="flex" style="gap: 5px;">
-                    <div @click="buttonSearch" class="photo"><img src="../../../resources/img/img143_75s.png" alt="">
-                    </div>
-                    <div @click="buttonSearch" class="photo"><img src="../../../resources/img/img143_75s.png" alt="">
+                    <div v-for="(image, index) in images" :key="image.fileId" @click="buttonSearch(image)"
+                        class="photo">
+                        <img :src="image.url" :alt="image.fileNm" reloadable="true" />
                     </div>
                 </div>
             </article>
@@ -305,6 +305,7 @@
 <script>
 import SvgIcon from '@jamescoyle/vue-icon';
 import { mdiMagnify, mdiHeart, mdiWindowClose } from '@mdi/js';
+import axios from 'axios';
 
 export default {
     data() {
@@ -364,11 +365,74 @@
 
 
             isHidden: false,
+            images: []
 
         }
     },
     methods: {
+        async findFile(file_mng_id) {
+            try {
+                const res = await axios({
+                    url: "/file/find.json",
+                    method: "post",
+                    headers: {
+                        "Content-Type": "application/json; charset=UTF-8",
+                    },
+                    data: {
+                        file_mng_id: file_mng_id,
+                    },
+                });
+                return res.data.list[0];
+            } catch (error) {
+                console.log("result - error : ", error);
+                return null;
+            }
+        },
+        fetchImage() {
+            axios({
+                url: "/photo/photoUnitList.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                    unitId: "UNIT_000000000000001",
+                    sclsId: "1"
+                }
+            })
+                .then(response => {
+                    this.file_mng_id = response.data;
 
+                    const findFilePromises = this.file_mng_id.map(id =>
+                        this.findFile(id.file_mng_id)
+                    );
+
+                    return Promise.all(findFilePromises);
+                })
+                .then(fileResults => {
+                    // Format file results to include image URL
+                    this.images = fileResults.map(file => {
+                        if (file) {
+                            return {
+                                url: "http://localhost:9080/" + `${file.fileRpath}`,
+                                fileId: file.fileId,
+                                fileNm: file.fileNm,
+                                // Add any other properties you need here
+                            };
+                        }
+                        return null;
+                    }).filter(image => image !== null);
+                })
+                .catch(error => {
+                    console.error("Error fetching images:", error);
+                });
+        },
+        goToPageImg(page) {
+            const canvas = document.querySelector('canvas');
+            const dataURL = canvas.toDataURL('image/png');
+
+            this.$router.push({ name: page, query: { image: encodeURIComponent(dataURL) } });
+        },
         finishSchedule() {
             this.isHidden = true;
         },
@@ -761,6 +825,7 @@
     mounted() {
         console.log('main mounted');
 
+        this.fetchImage();
 
     },
     computed() {
client/views/pages/main/PhotoEdit.vue
--- client/views/pages/main/PhotoEdit.vue
+++ client/views/pages/main/PhotoEdit.vue
@@ -1,31 +1,32 @@
 <template>
-   <div class="content-wrap " >
+  <div class="content-wrap ">
     <div class="flex justify-center">
       <div>
         <div class="frame title-box">
-          <div class="photo" >
-            <img src="../../../resources/img/img143_75s.png" alt="">
+          <div class="photo">
+            <img :src="imageSrc" alt="">
           </div>
           <p class="title mt20" style="color: #fff;">2024.07.01 1단원 완료!</p>
-          
+
         </div>
         <div class="btn-wrap flex justify-center mt40" style="gap: 40px;">
-            <button class="login-btn" @click="goToPage('PhotoDesign')">
-              <img src="../../../resources/img/btn07_s.png" alt="">
-              <p>수정하기</p>
-            </button>
-  
-            <button class="login-btn" type="submit" @click="goToPage('Dashboard')"><img
-                src="../../../resources/img/btn07_s.png" alt="">
-              <p>완료</p>
-            </button>
-          </div>
+          <button class="login-btn" @click="goToPage('PhotoDesign')">
+            <img src="../../../resources/img/btn07_s.png" alt="">
+            <p>수정하기</p>
+          </button>
+
+          <button class="login-btn" type="submit" @click="insertPhoto()"><img src="../../../resources/img/btn07_s.png"
+              alt="">
+            <p>완료</p>
+          </button>
+        </div>
       </div>
     </div>
   </div>
 </template>
 
 <script>
+import axios from 'axios';
 export default {
   data() {
     return {
@@ -35,13 +36,82 @@
       ],
       timer: '00',
       selectedIndex: 0,
+
+      imageSrc: '',
+      file: '',
+      fileId: '',
     }
   },
   methods: {
+    async fetchImageAsFile(imageUrl, filename = "image.jpg") {
+      try {
+        const response = await fetch(imageUrl);
+        const blob = await response.blob();
+
+        const file = new File([blob], filename, { type: blob.type });
+
+        return file;
+      } catch (error) {
+        console.error("이미지 변환 오류:", error);
+        throw new Error("이미지 변환에 실패했습니다.");
+      }
+    },
+    async fetchPhoto() {
+      const image = this.$route.query.image;
+      if (image) {
+        this.imageSrc = decodeURIComponent(image);
+        try {
+          this.file = await this.fetchImageAsFile(this.imageSrc, "image.jpg");
+        } catch (error) {
+          console.error("파일 변환 오류:", error);
+        }
+      }
+    }, async uploadFiles(file) {
+      if (!file) {
+        console.error("파일이 없습니다.");
+        throw new Error("파일이 없습니다.");
+      }
+      const formData = new FormData();
+      formData.append("files", file);
+
+      try {
+        const response = await axios.post("/file/upload.json", formData, {
+          headers: {
+            "Content-Type": "multipart/form-data",
+          },
+        });
+
+        return response.data.fileMngId; // 서버에서 반환된 파일 매니지 ID
+      } catch (error) {
+        console.error("파일 업로드 오류:", error);
+        throw new Error("파일 업로드에 실패했습니다.");
+      }
+    }, async insertPhoto() {
+      try {
+        this.fileId = await this.uploadFiles(this.file);
+
+        const response = await axios({
+          url: "/photo/insertPhoto.json",
+          method: "post",
+          headers: {
+            "Content-Type": "application/json; charset=UTF-8",
+          },
+          data: {
+            "photoMngId": "PHOTO_MNG_000000000000001", // 사진첩아이디 교체
+            "likeData": "0",
+            "unitId": "UNIT_000000000000001", // 유닛아이디 교체
+            "stdId": "1", //학생아이디 교체
+            "fileMngId": this.fileId
+          }
+        });
+        this.$router.push({ name: 'AIDashboard' });
+      } catch (error) {
+        console.error("사진 삽입 오류:", error);
+      }
+    },
     updateContent(index) {
-         this.selectedIndex = index;
-        //  this.currentCon = this.items[index].con;
-      },
+      this.selectedIndex = index;
+    },
     goToPage(page) {
       this.$router.push({ name: page });
     },
@@ -68,7 +138,7 @@
   components: {
   },
   mounted() {
-
+    this.fetchPhoto();
   }
 }
 </script>
@@ -118,5 +188,8 @@
 .pickGroup article>div>p {
   font-size: 64px;
 }
-.popTxt{width: 101px;}
+
+.popTxt {
+  width: 101px;
+}
 </style>
(파일 끝에 줄바꿈 문자 없음)
Add a comment
List