jichoi / lms_front star
woals 2024-08-23
240823 권민수 단어장 2_2 페이지 api 연결
@516c4721831fcd844ee7b4a4dc68a788c3fe6b64
client/views/pages/main/Chapter/Chapter2_2.vue
--- client/views/pages/main/Chapter/Chapter2_2.vue
+++ client/views/pages/main/Chapter/Chapter2_2.vue
@@ -45,7 +45,7 @@
             <button class="popTxt" v-for="(item, index) in items" :key="index">
               <div class="listenGroup">
                 <img :src="item.imgSrc1" />
-                <p class="textbox"><img :src="item.imgSrc" /></p>
+                <p class="textbox"><img :src="item.imgSrc" style="height: 150px;"/></p>
               </div>
               <div
                 class="listenGroup"
@@ -73,36 +73,37 @@
 export default {
   data() {
     return {
-      items: [
-        {
-          imgSrc1: "client/resources/img/img49_s.png",
-          imgSrc2: "client/resources/img/img50_s.png",
-          imgSrc: "client/resources/img/img77_41s.png",
-          isSecondImageVisible: false,
-          title: "america",
-        },
-        {
-          imgSrc1: "client/resources/img/img49_s.png",
-          imgSrc2: "client/resources/img/img50_s.png",
-          imgSrc: "client/resources/img/img47_s.png",
-          isSecondImageVisible: false,
-          title: "airplane",
-        },
-        {
-          imgSrc1: "client/resources/img/img49_s.png",
-          imgSrc2: "client/resources/img/img50_s.png",
-          imgSrc: "client/resources/img/img75_41s.png",
-          isSecondImageVisible: false,
-          title: "cat",
-        },
-        {
-          imgSrc1: "client/resources/img/img49_s.png",
-          imgSrc2: "client/resources/img/img50_s.png",
-          imgSrc: "client/resources/img/img74_41s.png",
-          isSecondImageVisible: false,
-          title: "mountain",
-        },
-      ],
+      // items: [
+      //   {
+      //     imgSrc1: "client/resources/img/img49_s.png",
+      //     imgSrc2: "client/resources/img/img50_s.png",
+      //     imgSrc: "client/resources/img/img77_41s.png",
+      //     isSecondImageVisible: false,
+      //     title: "america",
+      //   },
+      //   {
+      //     imgSrc1: "client/resources/img/img49_s.png",
+      //     imgSrc2: "client/resources/img/img50_s.png",
+      //     imgSrc: "client/resources/img/img47_s.png",
+      //     isSecondImageVisible: false,
+      //     title: "airplane",
+      //   },
+      //   {
+      //     imgSrc1: "client/resources/img/img49_s.png",
+      //     imgSrc2: "client/resources/img/img50_s.png",
+      //     imgSrc: "client/resources/img/img75_41s.png",
+      //     isSecondImageVisible: false,
+      //     title: "cat",
+      //   },
+      //   {
+      //     imgSrc1: "client/resources/img/img49_s.png",
+      //     imgSrc2: "client/resources/img/img50_s.png",
+      //     imgSrc: "client/resources/img/img74_41s.png",
+      //     isSecondImageVisible: false,
+      //     title: "mountain",
+      //   },
+      // ],
+      items: [],
       timer: 0,
       intervalId: null,
       currentIndex: 0,
@@ -118,14 +119,44 @@
       this.currentWdBkIndex = this.$store.getters.getCurrentWdBkIndex; // 현재 단어장 인덱스
       this.wdBookIdList = this.$store.getters.getWdBookIdList; // 단어컨텐츠의 단어장 id 리스트
       this.wdBookId = this.$store.getters.getWdBookIdList[this.currentWdBkIndex] // 현재 단어장 콘텐츠 인덱스에 대한 단어장 id
+      console.log(this.wdBookId);
 
-      // this.fetchWordList();
+      this.fetchWordList();
     },
 
     async fetchWordList() {
-      console.log("현재 단어장 콘텐츠 인덱스: ", this.$store.getters.getCurrentWdBkIndex);
-      this.currentWdBkIndex = this.$store.getters.getCurrentWdBkIndex;
-      console.log("현재 단어장 콘텐츠 인덱스에 대한 단어장 id: ", this.$store.getters.getWdBookIdList[this.currentWdBkIndex]);
+      try {
+        const response = await axios.post('/word/getWordsByBookId.json', {
+          wdBookId: this.wdBookId,
+        });
+
+        const wordList = response.data;
+
+        // 각 word 객체에 대해 fileRpath를 받아오는 요청 처리
+        const requests = wordList.map(async (word) => {
+          const fileResponse = await axios.post("/file/find.json", {
+            file_mng_id: word.fileMngId,
+          });
+
+          const fileRpath = fileResponse.data.list.length > 0 ? fileResponse.data.list[0].fileRpath : null;
+          console.log("각 단어의 fileRpath: ", fileRpath);
+
+          // items 배열에 새로운 항목 추가
+          this.items.push({
+            imgSrc1: "client/resources/img/img49_s.png",
+            imgSrc2: "client/resources/img/img50_s.png",
+            imgSrc: "http://165.229.169.113:9080/" + fileRpath, // 받아온 fileRpath로 이미지 설정
+            isSecondImageVisible: false, 
+            title: word.wdNm,
+          });
+        });
+
+        // 모든 요청이 완료될 때까지 대기
+        await Promise.all(requests);
+
+      } catch (error) {
+        console.error('단어 목록을 불러오는 중 오류 발생:', error);
+      }
     },
 
     async goToPrevPage() {
Add a comment
List