jichoi / lms_front star
dajeong 2024-08-22
240822 정다정 대화지문 API 추가
@5fbbd6bdaef940a4c7906a8fbb059449f83f2dd2
client/views/pages/main/Chapter/Chapter1_2.vue
--- client/views/pages/main/Chapter/Chapter1_2.vue
+++ client/views/pages/main/Chapter/Chapter1_2.vue
@@ -1,131 +1,154 @@
 <template>
-  <div id="Chapter1_2" class="content-wrap">
-    <div style="margin: 30px 0px 50px; width: 20%">
-      <router-link to="/MyPlan.page">
-        <div class="logo mb25"><img src="../../../../resources/img/logo2.png" alt=""></div>
-      </router-link>
-    </div>
-    <div class="title-box mb25 flex align-center mt40" style="
-    justify-content: space-between;
-">
-      <div>
-        <span class="title mr40">1. Hello WORLD</span>
-        <span class="subtitle">my name is dd</span>
-      </div>
-      <button class="completeBtn" @click="complete"> 학습 종료 </button>
-    </div>
-    <div class="flex justify-between align-center">
-      <div class="pre-btn" @click="goToPage('Chapter1_1')"><img src="../../../../resources/img/left.png" alt=""></div>
-      <div class="content title-box">
-        <p class="title mt25 title-bg">step1. Hello WORLD</p>
-        <div class="flex justify-center">
-          <div class="readGroup">
-            <h4>각 인물들의 대화를 집중해서 읽어보세요</h4>
-            <div>
-              <div class="textbox">
-                <article class="flex align-start mb10">
-                  <div class="icon mr40">
-                    <img src="../../../../resources/img/img37_s.png" alt="">
-                    <p class="name">발화자</p>
-                  </div>
-                  <p class="read">What’s up man, nice to meet you Minsu. how are you today?</p>
-                </article>
-                <article class="flex align-start mb10 justify-end">
-                  <p class="read mr40">What’s up man, nice to meet you Minsu. how are you today?</p>
-                  <div class="icon ">
-                    <img src="../../../../resources/img/img37_s.png" alt="">
-                    <p class="name">발화자</p>
-                  </div>
-                </article>
-                <article class="flex align-start mb10">
-                  <div class="icon mr40">
-                    <img src="../../../../resources/img/img37_s.png" alt="">
-                    <p class="name">발화자</p>
-                  </div>
-                  <p class="read">What’s up man, nice to meet you Minsu. how are you today?</p>
-                </article>
-                <article class="flex align-start mb10 justify-end">
-                  <p class="read mr40">What’s up man, nice to meet you Minsu. how are you today?</p>
-                  <div class="icon ">
-                    <img src="../../../../resources/img/img37_s.png" alt="">
-                    <p class="name">발화자</p>
-                  </div>
-                </article>
-              </div>
-            </div>
-
-          </div>
+    <div id="Chapter1_2" class="content-wrap">
+        <div style="margin: 30px 0px 50px; width: 20%">
+            <router-link to="/MyPlan.page">
+                <div class="logo mb25"><img src="../../../../resources/img/logo2.png" alt="" /></div>
+            </router-link>
         </div>
-      </div>
-      <div class="next-btn" @click="goToPage('Chapter1_3')"><img src="../../../../resources/img/right.png" alt=""></div>
+        <div class="title-box mb25 flex align-center mt40" style="justify-content: space-between">
+            <div>
+                <span class="title mr40">1. Hello WORLD</span>
+                <span class="subtitle">my name is dd</span>
+            </div>
+            <button class="completeBtn" @click="complete">학습 종료</button>
+        </div>
+        <div class="flex justify-between align-center">
+            <div class="pre-btn" @click="goToPage('Chapter1_1')"><img src="../../../../resources/img/left.png" alt="" /></div>
+            <div class="content title-box">
+                <p class="title mt25 title-bg">step1. Hello WORLD</p>
+                <div class="flex justify-center">
+                    <div class="readGroup">
+                        <h4>각 인물들의 대화를 집중해서 읽어보세요</h4>
+                        <div>
+                            <div class="textbox">
+                                <article v-for="(line, index) in combinedLines" :key="index" :class="['flex', 'align-start', 'mb10', { 'justify-end': index % 2 !== 0 }]">
+                                    <div v-if="index % 2 === 0" class="icon mr40">
+                                        <img src="../../../../resources/img/img37_s.png" alt="" />
+                                        <p class="name">{{ speakerA_name }}</p>
+                                    </div>
+                                    <p v-if="index % 2 === 0" class="read">{{ line }}</p>
+
+                                    <p v-if="index % 2 !== 0" class="read mr40">{{ line }}</p>
+                                    <div v-if="index % 2 !== 0" class="icon">
+                                        <img src="../../../../resources/img/img37_s.png" alt="" />
+                                        <p class="name">{{ speakerB_name }}</p>
+                                    </div>
+                                </article>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="next-btn" @click="goToPage('Chapter1_3')"><img src="../../../../resources/img/right.png" alt="" /></div>
+        </div>
+        <TextToImage />
     </div>
-    <TextToImage />
-  </div>
 </template>
 
 <script>
-import TextToImage from '../../../component/TextToImage.vue';
+import TextToImage from "../../../component/TextToImage.vue";
+import axios from "axios";
 export default {
-  data() {
-    return {
-    }
-  },
-  methods: {
-    complete() {
-        const { unit_id, book_id } = this.$route.query;
-        this.$router.push({ name: 'Dashboard', query: { value: 1, unit_id, book_id } });
+    data() {
+        return {
+            text_id: "TEXT_000000000000050",
+            text_data: null, // 받아온 지문 정보
+            speakerA_name: null,
+            speakerB_name: null,
+            speakerA: [],
+            speakerB: [],
+        };
     },
-    goToPage(page) {
-      this.$router.push({ name: page });
-    }
-  },
-  watch: {
+    methods: {
+        complete() {
+            const { unit_id, book_id } = this.$route.query;
+            this.$router.push({ name: "Dashboard", query: { value: 1, unit_id, book_id } });
+        },
+        goToPage(page) {
+            this.$router.push({ name: page });
+        },
+        // 대화 지문 API
+        async fetchText() {
+            axios({
+                url: "/text/selectOneText.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                    textId: this.text_id,
+                },
+            })
+                .then((response) => {
+                    this.text_data = response.data[0].text_cnt;
+                    this.splitConversation();
+                })
+                .catch((err) => {
+                    console.log("지문 에러 : ", err);
+                });
+        },
+        // 대화 지문 split
+        splitConversation() {
+            const lines = this.text_data.split("/");
+            const speakers = {};
 
-  },
-  computed: {
+            lines.forEach((line) => {
+                const [speaker, message] = line.trim().split(":");
 
-  },
-  components: {
-    TextToImage: TextToImage
-  },
-  mounted() {
-    const textArea = this.$refs.textArea;
-    const popup = this.$refs.popup;
+                if (!speakers.speakerA_name && !speakers.speakerB_name) {
+                    // 첫 번째 발화자를 speakerA_name으로 설정
+                    speakers.speakerA_name = speaker.trim();
+                    this.speakerA.push(message.trim());
+                } else if (speakers.speakerA_name && !speakers.speakerB_name && speakers.speakerA_name !== speaker.trim()) {
+                    // 두 번째 발화자를 speakerB_name으로 설정
+                    speakers.speakerB_name = speaker.trim();
+                    this.speakerB.push(message.trim());
+                } else if (speaker.trim() === speakers.speakerA_name) {
+                    // speakerA_name에 내용 추가
+                    this.speakerA.push(message.trim());
+                } else if (speaker.trim() === speakers.speakerB_name) {
+                    // speakerB_name에 내용 추가
+                    this.speakerB.push(message.trim());
+                }
+            });
 
-    textArea.addEventListener('mousemove', (event) => {
-      const text = textArea.value;
-      const words = text.split(' ');
-      const selectionStart = textArea.selectionStart;
-      const selectionEnd = textArea.selectionEnd;
+            this.speakerA_name = speakers.speakerA_name;
+            this.speakerB_name = speakers.speakerB_name;
+        },
+    },
+    watch: {},
+    computed: {
+        combinedLines() {
+            const maxLength = Math.max(this.speakerA.length, this.speakerB.length);
+            const lines = [];
 
-      if (selectionStart !== selectionEnd) {
-        const selectedText = text.substring(selectionStart, selectionEnd);
-        const rect = textArea.getBoundingClientRect();
-        popup.style.left = `${event.clientX}px`;
-        popup.style.top = `${event.clientY + window.scrollY}px`;
-        popup.innerHTML = `You selected: ${selectedText}`;
-        popup.style.display = 'block';
-      } else {
-        popup.style.display = 'none';
-      }
-    });
-
-    document.addEventListener('click', (event) => {
-      if (!textArea.contains(event.target) && !popup.contains(event.target)) {
-        popup.style.display = 'none';
-      }
-    });
-  }
-}
+            for (let i = 0; i < maxLength; i++) {
+                if (i < this.speakerA.length) {
+                    lines.push(this.speakerA[i]);
+                }
+                if (i < this.speakerB.length) {
+                    lines.push(this.speakerB[i]);
+                }
+            }
+            return lines;
+        },
+    },
+    components: {
+        TextToImage: TextToImage,
+    },
+    mounted() {
+        this.fetchText();
+    },
+};
 </script>
 
 <style>
 .completeBtn {
-  margin-right: 100px;
-  background-color: #ffba08;
-  padding: 10px 30px;
-  border-radius: 10px;
-  font-size: 28px;
-  font-family: 'ONEMobilePOPOTF';
+    margin-right: 100px;
+    background-color: #ffba08;
+    padding: 10px 30px;
+    border-radius: 10px;
+    font-size: 28px;
+    font-family: "ONEMobilePOPOTF";
 }
-</style>
(No newline at end of file)
+</style>
Add a comment
List