jichoi / lms_front star
woals 2024-08-12
240812 권민수 단어장 조회 칼럼 개선 및 책 별, 단원 별 조회 기능 추가
@ebe9d176d2385f77fd474b211798b672174eaf35
client/resources/css/common.css
--- client/resources/css/common.css
+++ client/resources/css/common.css
@@ -934,6 +934,10 @@
     color: #999999;
 }
 
+.black {
+    color: #000000;
+}
+
 .cursor {
     cursor: pointer;
 }
client/views/pages/AppRouter.js
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
@@ -85,11 +85,7 @@
 import TextDetail from "./teacher/TextDetail.vue";
 import QuestionList from "./teacher/QuestionList.vue";
 import QuestionInsert from "./teacher/QuestionInsert.vue";
-<<<<<<< HEAD
-import QuestionDetail from "./teacher/QuestionDetail.vue"; 
-=======
 import QuestionDetail from "./teacher/QuestionDetail.vue";
->>>>>>> e47769b90c7ad4f0b34f38bb2a56a8a69a894941
 import VocaList from "./teacher/VocaList.vue";
 import VocaInsert from "./teacher/VocaInsert.vue";
 import VocaDetail from "./teacher/VocaDetail.vue";
@@ -198,11 +194,7 @@
             { path: '/TextDetail.page', name: 'TextDetail', component: TextDetail },
             { path: '/QuestionList.page', name: 'QuestionList', component: QuestionList },
             { path: '/QuestionInsert.page', name: 'QuestionInsert', component: QuestionInsert },
-<<<<<<< HEAD
-            { path: '/QuestionDetail.page', name: 'QuestionDetail', component: QuestionDetail }, 
-=======
             { path: '/QuestionDetail.page', name: 'QuestionDetail', component: QuestionDetail },
->>>>>>> e47769b90c7ad4f0b34f38bb2a56a8a69a894941
             { path: '/VocaList.page', name: 'VocaList', component: VocaList },
             { path: '/VocaInsert.page', name: 'VocaInsert', component: VocaInsert },
             { path: '/VocaDetail.page', name: 'VocaDetail', component: VocaDetail },
client/views/pages/teacher/VocaList.vue
--- client/views/pages/teacher/VocaList.vue
+++ client/views/pages/teacher/VocaList.vue
@@ -1,18 +1,20 @@
 <template>
     <div class="title-box flex justify-between mb40">
         <p class="title">단어장</p>
-        <select name="" id="">
-            <option value="UNIT_000000000000001">A교재</option>
+        <select v-model="selectedBookId" @change="fetchUnits">
+            <option v-for="book in books" :key="book.book_id" :value="book.book_id">
+                {{ book.book_nm }}
+            </option>
         </select>
     </div>
     <label for="" class="title2">단원</label>
-        <div class="unit-pagination flex mt10 mb20" style="gap: 10px;">
-            <button class="selected-btn">1</button>
-            <button>2</button>
-            <button>3</button>
-        </div>
+    <div class="unit-pagination flex mt10 mb20" style="gap: 10px;">
+        <button v-for="unit in units" :key="unit.unitId" @click="selectUnit(unit.unitId)" :class="{ 'selected-btn': selectedUnitId === unit.unitId }">
+            {{ unit.unitName }}
+        </button>
+    </div>
     <div class="search-wrap flex justify-between mb20 align-center">
-        <div class="title2 gray">?단원 전체 목록</div>
+        <div class="title2 gray flex"><div class="black">[{{ selectedUnitName }}]</div>단원 전체 목록</div>
         <div>
             <select name="" id="" class="mr10 data-wrap">
                 <option value="">지문</option>
@@ -31,15 +33,13 @@
                 <td>지문</td>
                 <td>단어 목록</td>
                 <td>작성자</td>
-                <td>등록일</td>
             </thead>
             <tbody>
                 <tr v-for="(wordBook, index) in dataList" :key="wordBook.wdBookId" @click="goToViewPage('VocaDetail')">
                     <td>{{ createNo(index) }}</td>
                     <td>{{ wordBook.textTtl }}</td>
                     <td>{{ wordBook.wordsPreview }}</td>
-                    <td>{{ wordBook.userId }}</td>
-                    <td>{{ '' }}</td>
+                    <td>{{ wordBook.userNm }}</td>
                 </tr>
             </tbody>
         </table>
@@ -55,7 +55,7 @@
             </button>
         </article>
         <div class="flex justify-end ">
-            <button type="button" title="등록" class="new-btn" @click="goToPage('VocaInsert')">
+            <button type="button" title="등록" class="new-btn" @click="goToViewPage('VocaInsert')">
                 등록
             </button>
         </div>
@@ -72,15 +72,57 @@
     data () {
         return {
             mdiMagnify: mdiMagnify,
+            books: [],
+            units: [],
+            selectedBookId: null, // 선택된 책 ID 저장 변수
+            selectedUnitId: null, // 선택된 단원 ID 저장 변수
+            selectedUnitName: '', // 선택된 단원의 이름 저장 변수
             dataList: [],
             currentPage: 0,
             itemsPerPage: 2,
-            totalPosts: 0,
-            unitId: "UNIT_000000000000001"
+            totalPosts: 0
         }
     },
     methods: {
 
+        // 모든 책 목록을 가져오는 메서드
+        fetchBooks() {
+            axios.post('/book/findAll.json')
+            .then(response => {
+                this.books = response.data;
+                if (this.books.length > 0) {
+                    this.selectedBookId = this.books[1].book_id; // 두 번째 책을 선택하도록 기본 설정
+                    this.fetchUnits(); // 책 선택 후 단원 목록 가져오기
+                }
+            })
+            .catch(error => {
+                console.error("책 목록 가져오기 실패: ", error);
+            });
+        },
+
+        // 선택된 책의 단원 목록을 가져오는 메서드
+        fetchUnits() {
+            axios.post('/unit/unitList.json', { bookId: this.selectedBookId })
+            .then(response => {
+                this.units = response.data;
+                if (this.units.length > 0) {
+                    this.selectUnit(this.units[4].unitId); // 다섯 번째 단원을 선택하도록 기본 설정
+                }
+            })
+            .catch(error => {
+                console.error("단원 목록 가져오기 실패: ", error);
+            });
+        },
+
+        // 단원을 선택했을 때 호출되는 메서드
+        selectUnit(unitId) {
+            this.selectedUnitId = unitId;
+            const selectedUnit = this.units.find(unit => unit.unitId === unitId);
+            this.selectedUnitName = selectedUnit ? selectedUnit.unitName : '';
+            this.dataSelectList(); // 단어장 목록 조회
+        },
+
+        // 단어장 목록 조회 메서드
         dataSelectList() {
             const vm = this;
             axios({
@@ -90,7 +132,7 @@
                     "Content-Type": "application/json; charset=UTF-8",
                 },
                 data: {
-                    unitId: vm.unitId,
+                    unitId: vm.selectedUnitId,
                     page: vm.currentPage + 1,
                     pageSize: vm.itemsPerPage
                 },
@@ -134,6 +176,8 @@
                 alert("단어장 목록 조회에 오류가 발생했습니다.");
             });
         },
+
+        // 단어 목록 생략 String 생성 메서드
         generateWordsPreview(words) {
             const maxLength = 20; // 최대 표시 길이 설정
             const wordString = words.join(', ');
@@ -144,9 +188,13 @@
                 return wordString;
             }
         },
+
+        // 단어장 NO 생성 메서드
         createNo(index) {
             return this.totalPosts - (this.currentPage * this.itemsPerPage + index);
         },
+
+        // 페이지네이션 이동 메서드
         goToPage(page) {
             if (page < 0 || page >= this.totalPages) {
                 return;
@@ -154,6 +202,8 @@
             this.currentPage = page;
             this.dataSelectList();
         },
+
+        // 페이지 이동 메서드
         goToViewPage(page) {
             this.$router.push({ name: page });
         },
@@ -184,7 +234,7 @@
     },
     mounted() {
         console.log('Voca Book List Component mounted');
-        this.dataSelectList();
+        this.fetchBooks();
     }
 }
 </script>
(No newline at end of file)
Add a comment
List