jichoi / lms_front star
woals 2024-08-23
240823 권민수 단어장 나머지 페이지도 세팅 준비
@1dd9d7e2a9ab411bd3340032880e549652d8dd47
client/views/pages/main/Chapter/Chapter2.vue
--- client/views/pages/main/Chapter/Chapter2.vue
+++ client/views/pages/main/Chapter/Chapter2.vue
@@ -18,7 +18,8 @@
       <button class="completeBtn" @click="complete">학습 종료</button>
     </div>
     <div class="flex justify-between align-center">
-      <div class="pre-btn" @click="goToPage('Chapter1_3')">
+    
+      <div class="pre-btn" @click="goToPage('Chapter1_3')"> <!-- @click="goToPrevPage" -->
         <img src="../../../../resources/img/left.png" alt="" />
       </div>
       <div class="content title-box">
@@ -75,7 +76,7 @@
           </div>
         </div>
       </div>
-      <div class="next-btn" @click="goToPage('Chapter2_3')">
+      <div class="next-btn" @click="goToPage('Chapter2_3')"> <!-- @click="goToNextPage" -->
         <img src="../../../../resources/img/right.png" alt="" />
       </div>
     </div>
@@ -90,11 +91,22 @@
     return {
       wdBookId: "WORD_BOOK_000000000000042",
       wordList: [],
-      wordContentList: [],
-      wdContentId: "",
+
+      wdBookIdList: [], // 단어 컨텐츠의 단어장 id 리스트
+      currentWdBkIndex: 0, // 현재 단어장 인덱스
+      wdBookTypeIdState: "", // 이동할 페이지 타입 id
+      wordBookType: "", // 이동할 페이지
     };
   },
   methods: {
+    pageSetting() {
+      this.currentWdBkIndex = this.$store.getters.getCurrentWdBkIndex; // 현재 단어장 인덱스
+      this.wdBookIdList = this.$store.getters.getWdBookIdList; // 단어컨텐츠의 단어장 id 리스트
+      this.wdBookId = this.$store.getters.getWdBookIdList[this.currentWdBkIndex] // 현재 단어장 콘텐츠 인덱스에 대한 단어장 id
+
+      // this.fetchWordList();
+    },
+
     async fetchWordList() {
       try {
         const response = await axios.post("/word/getWordsByBookId.json", {
@@ -126,6 +138,88 @@
       }
     },
 
+    async goToPrevPage() {
+      if (this.currentWdBkIndex - 1 < 0) {
+        alert("단어장 첫번째 페이지 입니다");
+      } else {
+        this.currentWdBkIndex--;
+        this.$store.dispatch('updateCurrentWdBkIndex', this.currentWdBkIndex);
+
+        try {
+          const response = await axios.post("/wordbook/find.json", {
+            wdBookId: this.$store.getters.getWdBookIdList[this.currentWdBkIndex]
+          });
+          this.wdBookTypeIdState = response.data.wdBookTypeId;
+          console.log("이전 단어장 타입 id: ", this.wdBookTypeIdState);
+
+          switch (this.wdBookTypeIdState) {
+            case "1":
+                this.wordBookType = "Chapter2";
+                break;
+            case "2":
+                this.wordBookType = "Chapter2_3";
+                break;
+            case "3":
+                this.wordBookType = "Chapter2_2";
+                break;
+            case "4":
+                this.wordBookType = "Chapter2_9";
+                break;
+            case "5":
+                this.wordBookType = "Chapter2_4";
+                break;
+            default:
+                this.wordBookType = null;
+          }
+          
+          this.goToPage(this.wordBookType); 
+        } catch (error) {
+          console.error('단어장 정보 불러오는 중 오류 발생:', error);
+        }
+      }
+    },
+
+    async goToNextPage() {
+      if (this.currentWdBkIndex + 1 >= this.wdBookIdList.length) {
+        alert("단어장 마지막 페이지 입니다");
+      } else {
+        this.currentWdBkIndex++;
+        this.$store.dispatch('updateCurrentWdBkIndex', this.currentWdBkIndex);
+
+        try {
+          const response = await axios.post("/wordbook/find.json", {
+            wdBookId: this.$store.getters.getWdBookIdList[this.currentWdBkIndex]
+          });
+          this.wdBookTypeIdState = response.data.wdBookTypeId;
+          console.log("다음 단어장 타입 id: ", this.wdBookTypeIdState);
+
+          switch (this.wdBookTypeIdState) {
+            case "1":
+                this.wordBookType = "Chapter2";
+                break;
+            case "2":
+                this.wordBookType = "Chapter2_3";
+                break;
+            case "3":
+                this.wordBookType = "Chapter2_2";
+                break;
+            case "4":
+                this.wordBookType = "Chapter2_9";
+                break;
+            case "5":
+                this.wordBookType = "Chapter2_4";
+                break;
+            default:
+                this.wordBookType = null;
+          }
+          
+          this.goToPage(this.wordBookType); 
+        } catch (error) {
+          console.error('단어장 정보 불러오는 중 오류 발생:', error);
+        }
+      }
+    },
+
     goToPage(page) {
       this.$router.push({ name: page });
     },
@@ -142,6 +236,7 @@
   },
   mounted() {
     console.log("챕터2 단어장 마운트 완료");
+    // this.pageSetting();
     this.fetchWordList();
   },
 };
client/views/pages/main/Chapter/Chapter2_3.vue
--- client/views/pages/main/Chapter/Chapter2_3.vue
+++ client/views/pages/main/Chapter/Chapter2_3.vue
@@ -15,7 +15,7 @@
             <button class="completeBtn" @click="complete">학습 종료</button>
         </div>
         <div class="flex justify-between align-center">
-            <div class="pre-btn" @click="goToPage('Chapter2')">
+            <div class="pre-btn" @click="goToPage('Chapter2')"> <!-- @click="goToPrevPage" -->
                 <img src="../../../../resources/img/left.png" alt="" />
             </div>
             <div class="content title-box">
@@ -71,7 +71,7 @@
                     </div>
                 </div>
             </div>
-            <div class="next-btn" @click="goToPage('Chapter2_2')">
+            <div class="next-btn" @click="goToPage('Chapter2_2')"> <!-- @click="goToNextPage" -->
                 <img src="../../../../resources/img/right.png" alt="" />
             </div>
         </div>
@@ -106,9 +106,103 @@
             nowWord: 'cloud',
 
             wdBookId: "WORD_BOOK_000000000000043",
+            wdBookIdList: [], // 단어 컨텐츠의 단어장 id 리스트
+            currentWdBkIndex: 0, // 현재 단어장 인덱스
+            wdBookTypeIdState: "", // 이동할 페이지 타입 id
+            wordBookType: "", // 이동할 페이지
         };
     },
     methods: {
+        pageSetting() {
+            this.currentWdBkIndex = this.$store.getters.getCurrentWdBkIndex; // 현재 단어장 인덱스
+            this.wdBookIdList = this.$store.getters.getWdBookIdList; // 단어컨텐츠의 단어장 id 리스트
+            this.wdBookId = this.$store.getters.getWdBookIdList[this.currentWdBkIndex] // 현재 단어장 콘텐츠 인덱스에 대한 단어장 id
+
+            // this.fetchWordList();
+        },
+
+        async goToPrevPage() {
+            if (this.currentWdBkIndex - 1 < 0) {
+                alert("단어장 첫번째 페이지 입니다");
+            } else {
+                this.currentWdBkIndex--;
+                this.$store.dispatch('updateCurrentWdBkIndex', this.currentWdBkIndex);
+
+                try {
+                    const response = await axios.post("/wordbook/find.json", {
+                        wdBookId: this.$store.getters.getWdBookIdList[this.currentWdBkIndex]
+                    });
+                    this.wdBookTypeIdState = response.data.wdBookTypeId;
+                    console.log("이전 단어장 타입 id: ", this.wdBookTypeIdState);
+
+                    switch (this.wdBookTypeIdState) {
+                        case "1":
+                            this.wordBookType = "Chapter2";
+                            break;
+                        case "2":
+                            this.wordBookType = "Chapter2_3";
+                            break;
+                        case "3":
+                            this.wordBookType = "Chapter2_2";
+                            break;
+                        case "4":
+                            this.wordBookType = "Chapter2_9";
+                            break;
+                        case "5":
+                            this.wordBookType = "Chapter2_4";
+                            break;
+                        default:
+                            this.wordBookType = null;
+                    }
+                    
+                    this.goToPage(this.wordBookType); 
+                } catch (error) {
+                    console.error('단어장 정보 불러오는 중 오류 발생:', error);
+                }
+            }
+        },
+
+        async goToNextPage() {
+            if (this.currentWdBkIndex + 1 >= this.wdBookIdList.length) {
+                alert("단어장 마지막 페이지 입니다");
+            } else {
+                this.currentWdBkIndex++;
+                this.$store.dispatch('updateCurrentWdBkIndex', this.currentWdBkIndex);
+
+                try {
+                    const response = await axios.post("/wordbook/find.json", {
+                        wdBookId: this.$store.getters.getWdBookIdList[this.currentWdBkIndex]
+                    });
+                    this.wdBookTypeIdState = response.data.wdBookTypeId;
+                    console.log("다음 단어장 타입 id: ", this.wdBookTypeIdState);
+
+                    switch (this.wdBookTypeIdState) {
+                        case "1":
+                            this.wordBookType = "Chapter2";
+                            break;
+                        case "2":
+                            this.wordBookType = "Chapter2_3";
+                            break;
+                        case "3":
+                            this.wordBookType = "Chapter2_2";
+                            break;
+                        case "4":
+                            this.wordBookType = "Chapter2_9";
+                            break;
+                        case "5":
+                            this.wordBookType = "Chapter2_4";
+                            break;
+                        default:
+                            this.wordBookType = null;
+                    }
+                    
+                    this.goToPage(this.wordBookType); 
+                } catch (error) {
+                    console.error('단어장 정보 불러오는 중 오류 발생:', error);
+                }
+            }
+        },
+
         complete() {
             const { unit_id, book_id } = this.$route.query;
             this.$router.push({ name: 'Dashboard', query: { value: 2, unit_id, book_id } });
@@ -264,6 +358,7 @@
         },
     },
     mounted() {
+        // this.pageSetting();
         this.fetchWordList();
     },
     beforeDestroy() {
Add a comment
List