jichoi / lms_front star
woals 2024-08-22
240822 권민수 단어장 Chapter2, 2_3 페이지 데이터 적용
@718614bb3a97e5a007014d547edb4ed68498eee3
client/views/pages/main/Chapter/Chapter2.vue
--- client/views/pages/main/Chapter/Chapter2.vue
+++ client/views/pages/main/Chapter/Chapter2.vue
@@ -28,8 +28,13 @@
         </div>
 
         <div class="flex justify-center">
-          <div class="vocaGroup">
-            <div class="flex justify-between mb80">
+          <div class="vocaGroup" style="display: flex; flex-wrap: wrap;">
+            <div
+              v-for="(word) in wordList"
+              :key="word.wdId"
+              class="flex justify-between mb80"
+              style="width: 49%;"
+            >
               <article class="flex align-center">
                 <div class="imgGroup mr30">
                   <img
@@ -57,122 +62,16 @@
                     preload="auto"
                   ></audio>
                   <div>
-                    <h3>family</h3>
+                    <h3>{{ word.wdNm }}</h3>
                     <div class="flex align-center mt10">
                       <p class="yellow-box">명</p>
-                      <span class="title1">가족</span>
-                    </div>
-                  </div>
-                </div>
-              </article>
-              <article class="flex align-center">
-                <div class="imgGroup mr30">
-                  <img
-                    src="../../../../resources/img/img2_4.png"
-                    data-num="1"
-                    style="width: 200px"
-                  />
-                </div>
-                <div class="flex align-start">
-                  <button
-                    class="listen-btn mr30"
-                    data-video="1"
-                    tabindex="0"
-                    aria-label="음성 재생"
-                  >
-                    <img
-                      src="../../../../resources/img/btn10_s.png"
-                      data-num="1"
-                      @click="playAudio('audio-bank')"
-                    />
-                  </button>
-                  <audio
-                    id="audio-bank"
-                    src="client/resources/audio/bank.wav"
-                    preload="auto"
-                  ></audio>
-                  <div>
-                    <h3>bank</h3>
-                    <div class="flex align-center mt10">
-                      <p class="yellow-box">명</p>
-                      <span class="title1">은행</span>
+                      <span class="title1">{{ word.wdMnng }}</span>
                     </div>
                   </div>
                 </div>
               </article>
             </div>
-            <div class="flex justify-between">
-              <article class="flex align-center">
-                <div class="imgGroup mr30">
-                  <img
-                    src="../../../../resources/img/img2_2.png"
-                    data-num="1"
-                    style="width: 200px"
-                  />
-                </div>
-                <div class="flex align-start">
-                  <button
-                    class="listen-btn mr30"
-                    data-video="1"
-                    tabindex="0"
-                    aria-label="음성 재생"
-                  >
-                    <img
-                      src="../../../../resources/img/btn10_s.png"
-                      data-num="1"
-                      @click="playAudio('audio-love')"
-                    />
-                  </button>
-                  <audio
-                    id="audio-love"
-                    src="client/resources/audio/love.wav"
-                    preload="auto"
-                  ></audio>
-                  <div>
-                    <h3>love</h3>
-                    <div class="flex align-center mt10">
-                      <p class="yellow-box">명</p>
-                      <span class="title1">사랑</span>
-                    </div>
-                  </div>
-                </div>
-              </article>
-              <article class="flex align-center">
-                <div class="imgGroup mr30">
-                  <img
-                    src="../../../../resources/img/img2_3.png"
-                    data-num="1"
-                    style="width: 200px"
-                  />
-                </div>
-                <div class="flex align-start">
-                  <button
-                    class="listen-btn mr30"
-                    data-video="1"
-                    tabindex="0"
-                    aria-label="음성 재생"
-                  >
-                    <img
-                      src="../../../../resources/img/btn10_s.png"
-                      data-num="1"
-                      @click="playAudio('audio-police')"
-                    />
-                  </button>
-                  <audio
-                    id="audio-police"
-                    src="client/resources/audio/police.wav"
-                    preload="auto"
-                  ></audio>
-                  <div>
-                    <h3>police</h3>
-                    <div class="flex align-center mt10">
-                      <p class="yellow-box">명</p>
-                      <span class="title1">경찰</span>
-                    </div>
-                  </div>
-                </div>
-              </article>
-            </div>
+
           </div>
         </div>
       </div>
@@ -184,18 +83,33 @@
 </template>
 
 <script>
+import axios from 'axios';
+
 export default {
   data() {
-    return {};
+    return {
+      wdBookId: "WORD_BOOK_000000000000042",
+      wordList: [],
+    };
   },
   methods: {
-    complete() {
-        const { unit_id, book_id } = this.$route.query;
-        this.$router.push({ name: 'Dashboard', query: { value: 2, unit_id, book_id } });
+    fetchWordList() {
+      axios.post("/word/getWordsByBookId.json", {
+        wdBookId: this.wdBookId,
+      })
+      .then((response) => {
+        console.log(response.data);
+        this.wordList = response.data;
+      })
+      .catch((error) => {
+        console.error("단어 목록을 불러오는 중 오류 발생:", error);
+      })
     },
+
     goToPage(page) {
       this.$router.push({ name: page });
     },
+
     playAudio(audioId) {
       const audio = document.getElementById(audioId);
       if (audio) {
@@ -204,13 +118,16 @@
         console.error(`Audio element with ID ${audioId} not found.`);
       }
     },
+
   },
-  watch: {},
-  computed: {},
-  components: {},
-  mounted() {},
+  mounted() {
+    console.log("챕터2 단어장 마운트 완료");
+    this.fetchWordList();
+  },
 };
+
 </script>
+
 <style scoped>
 .grid-container {
   display: grid;
client/views/pages/main/Chapter/Chapter2_3.vue
--- client/views/pages/main/Chapter/Chapter2_3.vue
+++ client/views/pages/main/Chapter/Chapter2_3.vue
@@ -84,69 +84,13 @@
 export default {
     data() {
         return {
-            items: [
-                {
-                    imgSrc1: 'client/resources/img/img53_6_35s.png',
-                    imgSrc2: 'client/resources/img/img53_1_35s.png',
-                    con: {
-                        imgSrc: 'client/resources/img/img54_s.png',
-                        titleEm: 'c',
-                        title: 'loud',
-                        boxText: '명',
-                        subtitle: '구름',
-                    },
-                },
-                {
-                    imgSrc1: 'client/resources/img/img53_7_35s.png',
-                    imgSrc2: 'client/resources/img/img53_2_35s.png',
-                    con: {
-                        imgSrc: 'client/resources/img/img40_s.png',
-                        titleEm: 'a',
-                        title: 'pple',
-                        boxText: '명',
-                        subtitle: '사과',
-                    },
-                },
-                {
-                    imgSrc1: 'client/resources/img/img53_8_35s.png',
-                    imgSrc2: 'client/resources/img/img53_3_35s.png',
-                    con: {
-                        imgSrc: 'client/resources/img/31img40_s.png',
-                        titleEm: 'l',
-                        title: 'og',
-                        boxText: '명',
-                        subtitle: '통나무',
-                    },
-                },
-                {
-                    imgSrc1: 'client/resources/img/img53_9_35s.png',
-                    imgSrc2: 'client/resources/img/img53_4_35s.png',
-                    con: {
-                        imgSrc: 'client/resources/img/img41_s.png',
-                        titleEm: 'g',
-                        title: 'uitar',
-                        boxText: '명',
-                        subtitle: '기타',
-                    },
-                },
-                {
-                    imgSrc1: 'client/resources/img/img53_10_35s.png',
-                    imgSrc2: 'client/resources/img/img53_5_35s.png',
-                    con: {
-                        imgSrc: 'client/resources/img/img76_41s.png',
-                        titleEm: 'w',
-                        title: 'atermelon',
-                        boxText: '명',
-                        subtitle: '수박',
-                    },
-                },
-            ],
+            items: [],
             currentCon: {
-                imgSrc: 'client/resources/img/img54_s.png',
-                titleEm: 'c',
-                title: 'loud',
+                imgSrc: '',
+                titleEm: '',
+                title: '',
                 boxText: '명',
-                subtitle: '구름',
+                subtitle: '',
             },
             selectedIndex: 0,
             timer: '00',
@@ -160,6 +104,8 @@
 
             path: mdiStop,
             nowWord: 'cloud',
+
+            wdBookId: "WORD_BOOK_000000000000043",
         };
     },
     methods: {
@@ -258,6 +204,43 @@
                 console.log('파일 전송 실패: ', error);
             }
         },
+
+        // 단어 리스트를 서버에서 받아와 items에 적용하는 메서드
+        async fetchWordList() {
+            try {
+                const response = await axios.post('/word/getWordsByBookId.json', {
+                    wdBookId: this.wdBookId,
+                });
+
+                this.wordList = response.data;
+
+                this.items = this.wordList.map((word, index) => {
+                    const imgSrc1 = `client/resources/img/img53_${6 + index}_35s.png`;
+                    const imgSrc2 = `client/resources/img/img53_${1 + index}_35s.png`;
+                    return {
+                        imgSrc1,
+                        imgSrc2,
+                        con: {
+                            imgSrc: 'client/resources/img/img54_s.png', // 일단은 구름 사진으로 고정
+                            titleEm: word.wdNm.charAt(0), // 단어의 첫 글자
+                            title: word.wdNm.slice(1), // 단어의 나머지 부분
+                            boxText: '명',
+                            subtitle: word.wdMnng, // 단어의 의미
+                        },
+                    };
+                });
+
+                // items 리스트의 첫 번째 항목을 currentCon에 설정
+                if (this.items.length > 0) {
+                    this.currentCon = this.items[0].con;
+                    this.nowWord = this.currentCon.titleEm + this.currentCon.title;
+                }
+
+            } catch (error) {
+                console.error('단어 목록을 불러오는 중 오류 발생:', error);
+            }
+        },
+
     },
     watch: {
         transcription: null, // 서버에서 받아온 텍스트 결과
@@ -269,6 +252,9 @@
             deep: true, // Watch for deep changes in currentCon
         },
     },
+    mounted() {
+        this.fetchWordList();
+    },
     beforeDestroy() {
         if (this.intervalId) {
             clearInterval(this.intervalId);
Add a comment
List