jichoi / lms_front star
이은진 이은진 2024-08-09
240809 이은진 교사 지문 수정
@34b5a9920c13ea42c5f2d11f8f3747721c963eba
client/views/pages/teacher/TextDetail.vue
--- client/views/pages/teacher/TextDetail.vue
+++ client/views/pages/teacher/TextDetail.vue
@@ -1,19 +1,19 @@
 <template>
     <div class="title-box flex justify-between mb40">
-        <p class="title">지문 등록</p>
+        <p class="title">지문 상세 보기</p>
     </div>
     <div class="board-wrap">
         <div class="flex align-center mb20">
             <label for="" class="title2">제목</label>
-            <input v-if="isEditing" type="text" v-model="post.textTtl" class="data-wrap">
-            <p v-else class="data-wrap">{{ post.textTtl }}</p>
+            <input v-if="isEditing" type="text" v-model="post.textTtl" class=" data-wrap">
+            <p class="data-wrap" v-else>{{ post.textTtl }}</p>
         </div>
         <div class="flex align-center mb20">
             <label for="" class="title2">URL</label>
             <input v-if="isEditing" type="text" v-model="post.textUrl" class="data-wrap">
             <p v-else class="data-wrap">{{ post.textUrl }}</p>
         </div>
-        <div class="flex align-center mb20">
+        <div class="flex align-center mb20" style="display: flex; flex-direction: row;">
             <label class="title2">형식</label>
             <label class="title2">
                 <input type="radio" v-model="post.textTypeId" value="1" class="data-wrap" :disabled="!isEditing"> 일반
@@ -23,6 +23,25 @@
             </label>
             <label class="title2">
                 <input type="radio" v-model="post.textTypeId" value="3" class="data-wrap" :disabled="!isEditing"> 책 리스닝
+            </label>
+            <select v-if="isEditing" id="" v-model="post.bookId" @change="fetchUnits" class="ml20">
+                <option value="" disabled>교재를 선택하세요</option>
+                <option v-for="book in books" :key="book.book_id" :value="book.book_id">
+                    {{ book.book_nm }}
+                </option>
+            </select>
+            <label v-else for="" class="title2 flex align-center ml20" style="display: flex; width: 20rem;">교재:&nbsp;
+                <p class="title2">{{ post.bookName }}</p>
+            </label>
+                <select v-if="isEditing" name="" id="" v-model="post.unitId" class="ml20">
+                    <option value="" disabled>단원을 선택하세요</option>
+                    <option v-for="unit in units" :key="unit.unitId" :value="unit.unitId">
+                        {{ unit.unitName }}
+                    </option>
+                </select>
+            <label v-else  for="" class="title2 flex align-center ml20"
+                style="display: flex; width: 20rem; text-align: right;">단원:&nbsp;
+                <p class="title2">{{ post.unitName }}</p>
             </label>
         </div>
         <hr>
@@ -56,17 +75,33 @@
     data() {
         return {
             mdiMagnify: mdiMagnify,
-            post: {"textId": "",
-                "textTtl": "",
-                "textCnt": "",
-                "textUrl": "",
-                "textTypeId": ""}, 
-            isEditing: false // Add this property to toggle edit mode
+            post: {
+                textId: "",
+                textTtl: "",
+                textCnt: "",
+                textUrl: "",
+                textTypeId: "",
+                bookId: "",
+                unitId: "",
+                bookName: "",  
+                unitName: ""
+            },
+            books: [],  
+            units: [], 
+            isEditing: false
         };
     },
     computed: {
         textId() {
             return this.$route.query.textId;
+        },
+        selectedBookName() {
+            const book = this.books.find(book => book.book_id === this.post.bookId);
+            return book ? book.book_nm : '';
+        },
+        selectedUnitName() {
+            const unit = this.units.find(unit => unit.unit_id === this.post.unitId);
+            return unit ? unit.unit_nm : '';
         }
     },
     methods: {
@@ -86,7 +121,11 @@
                         this.post.textTtl = response.data[0].text_ttl;
                         this.post.textCnt = response.data[0].text_cnt;
                         this.post.textUrl = response.data[0].text_url;
-                        this.post.textTypeId = response.data[0].text_type_id; 
+                        this.post.textTypeId = response.data[0].text_type_id;
+                        this.post.bookId = response.data[0].book_id;
+                        this.post.unitId = response.data[0].unit_id;
+                        this.post.bookName = response.data[0].book_name;
+                        this.post.unitName = response.data[0].unit_name;
                     } else {
                         this.error = "Failed to fetch post details.";
                     }
@@ -96,8 +135,19 @@
                     this.error = "Failed to fetch post details.";
                 });
         },
-        dataInsert() { 
-            axios.post("/text/textUpdate.json", this.post, {
+        dataInsert() {
+            this.newPost = {
+                textId: this.post.textId,
+                textTtl: this.post.textTtl,
+                textCnt: this.post.textCnt,
+                textUrl: this.post.textUrl,
+                textTypeId: this.post.textTypeId,
+                bookId: this.post.bookId,
+                unitId: this.post.unitId
+            };
+            console.log(this.newPost)
+
+            axios.post("/text/textUpdate.json", this.newPost, {
                 headers: {
                     "Content-Type": "application/json; charset=UTF-8",
                 }
@@ -107,17 +157,17 @@
                     this.fetchPostDetail();
                 })
                 .catch(error => {
-                    console.log("dataInsert - error : ", error.response.data);
+                    console.log("dataInsert - error:", error.response.data);
                     alert("게시글 등록에 오류가 발생했습니다.");
                 });
         },
         toggleEdit() {
-            if (this.isEditing) { 
+            if (this.isEditing) {
                 this.dataInsert();
                 this.isEditing = false;
             } else {
-                // Enter edit mode
                 this.isEditing = true;
+                this.fetchBooks();
             }
         },
         deletePost() {
@@ -134,11 +184,40 @@
                     console.error("Error deleting post:", error);
                     alert("게시글 삭제에 오류가 발생했습니다.");
                 });
+        },
+        fetchBooks() {
+            axios.post("/book/findAll.json", {}, {
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                }
+            })
+                .then(response => {
+                    this.books = response.data;  
+                })
+                .catch(error => {
+                    console.error("fetchBooks - error:", error);
+                    alert("교재 목록을 불러오는 중 오류가 발생했습니다.");
+                });
+        },
+        fetchUnits() {
+            if (!this.post.bookId) return;  
+
+            axios.post("/unit/unitList.json", { bookId: this.post.bookId }, {
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                }
+            })
+                .then(response => {
+                    this.units = response.data;  
+                })
+                .catch(error => {
+                    console.error("fetchUnits - error:", error);
+                    alert("단원 목록을 불러오는 중 오류가 발생했습니다.");
+                });
         }
     },
     mounted() {
         this.fetchPostDetail();
-        console.log('Main2 mounted');
     },
     components: {
         SvgIcon
@@ -146,6 +225,5 @@
 };
 </script>
 
-<style scoped>
-/* Add any necessary styles here */
+<style scoped> 
 </style>
client/views/pages/teacher/TextInsert.vue
--- client/views/pages/teacher/TextInsert.vue
+++ client/views/pages/teacher/TextInsert.vue
@@ -1,4 +1,4 @@
-<!-- userid, bookid, unitid 추가해야함. filemng는? 모르겟음 -->
+
 <template>
     <div class="title-box flex justify-between mb40">
         <p class="title">지문 등록</p>
@@ -23,6 +23,18 @@
             <label class="title2">
                 <input type="radio" v-model="newData.textTypeId" value="3" class="data-wrap"> 책 리스닝
             </label>
+            <select name="" id="" v-model="newData.bookId" @change="fetchUnits" class="ml20">
+                <option value="" disabled>교재를 선택하세요</option>
+                <option v-for="book in books" :key="book.book_id" :value="book.book_id">
+                    {{ book.book_nm }}
+                </option>
+            </select>
+            <select name="" id="" v-model="newData.unitId" class="ml20">
+                <option value="" disabled>단원을 선택하세요</option>
+                <option v-for="unit in units" :key="unit.unitId" :value="unit.unitId">
+                    {{ unit.unitName }}
+                </option>
+            </select>
         </div>
         <hr>
         <div class="flex align-center">
@@ -49,11 +61,11 @@
 
 
 export default {
-  computed: {
-    textId() {
-      return this.$route.query.textId;
-    }
-  },
+    computed: {
+        textId() {
+            return this.$route.query.textId;
+        }
+    },
     data() {
         return {
             mdiMagnify: mdiMagnify,
@@ -63,22 +75,28 @@
                 textTtl: "",
                 textCnt: "",
                 textUrl: "",
-                textTypeId: ""
+                textTypeId: "",
+                //fileMngId:"",
+                // userId:"".
+                bookId: "",
+                unitId: ""
             },
+            books: [],  
+            units: [],  
         }
     },
     methods: {
         goToPage(page) {
             this.$router.push({ name: page });
         }, fetchPostDetail() {
-            const textId=this.$route.query.textId
+            const textId = this.$route.query.textId
             axios({
                 url: `/text/selectOneText.json`,
                 method: "post",
                 headers: {
                     "Content-Type": "application/json; charset=UTF-8",
                 },
-                data: {    "textId":  textId   }
+                data: { "textId": textId }
             })
                 .then(response => {
                     if (response.data && response.data[0]) {
@@ -119,13 +137,72 @@
                 return;
             }
 
+            if (!this.newData.textUrl) {
+                alert("url을 입력해 주세요.");
+                return;
+            }
+
+            if (!this.newData.textTypeId) {
+                alert("지문 형식을 입력해 주세요.");
+                return;
+            }
+
+            if (!this.newData.bookId) {
+                alert("교재를 선택해 주세요.");
+                return;
+            }
+
+            if (!this.newData.unitId) {
+                alert("단원을 선택해 주세요.");
+                return;
+            }
+
             if (!this.newData.textCnt) {
                 alert("내용을 입력해 주세요.");
                 return;
             }
 
             this.dataInsert();
-        }
+        },
+        fetchBooks() {
+            axios({
+                url: "/book/findAll.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+            })
+                .then(response => {
+                    console.log(response.data)
+                    this.books = response.data;  
+                })
+                .catch(error => {
+                    console.error("fetchBooks - error: ", error);
+                    alert("교재 목록을 불러오는 중 오류가 발생했습니다.");
+                });
+        },
+        fetchUnits() {
+            if (!this.newData.bookId) return;  
+
+            axios({
+                url: "/unit/unitList.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                    "bookId": this.newData.bookId
+                },
+            })
+                .then(response => {
+                    console.log(response.data)
+                    this.units = response.data;  
+                })
+                .catch(error => {
+                    console.error("fetchUnits - error: ", error);
+                    alert("단원 목록을 불러오는 중 오류가 발생했습니다.");
+                });
+        },
     },
     watch: {
 
@@ -138,6 +215,7 @@
     },
     mounted() {
         this.fetchPostDetail();
+        this.fetchBooks();  
         console.log('Main2 mounted');
     }
 }
client/views/pages/teacher/TextList.vue
--- client/views/pages/teacher/TextList.vue
+++ client/views/pages/teacher/TextList.vue
@@ -1,16 +1,23 @@
 <template>
     <div class="title-box flex justify-between mb40 myplan">
         <p class="title">지문</p>
-        <select name="" id="">
-            <option value="">A 교재</option>
+        <select name="" id="" v-model="selectedBook" @change="fetchUnits">
+            <option value="" disabled>교재를 선택하세요</option>
+            <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>
+    <label for="" class="title2">단원</label>
+    <div class="unit-pagination flex mt10 mb20" style="gap: 10px;">
+        <button 
+            v-for="(unit, index) in units" 
+            :key="index" 
+            :class="{ 'selected-btn': selectedUnit === unit.unitId }"
+            @click="selectUnit(unit.unitId)">
+            {{ unit.unitName }}
+        </button>
+    </div>
     <div class="search-wrap flex justify-end mb20">
         <select name="" id="" class="mr10 data-wrap" style="width: 15rem;" v-model="option">
             <option value="" disabled>검색유형</option>
@@ -78,6 +85,8 @@
             totalPosts: 0,
             option: "",
             keyword: "",
+            books: [], 
+            selectedBook: "", 
             optionList: [
                 { text: "번호", value: "textId" },
                 { text: "제목", value: "textTtl" },
@@ -85,8 +94,9 @@
                 { text: "작성자", value: "userId" },
                 { text: "등록일", value: "regDt" },
             ],
+            units: [], 
+            selectedUnit: null, 
             searching: false,
-
         };
     },
     methods: {
@@ -107,64 +117,110 @@
                 this.goBack();
             }
         },
+        selectUnit(unitId) {
+            this.selectedUnit = unitId;
+            this.fetchData();  
+        },
         search() {
             if (!this.option) {
                 alert("검색유형을 선택해 주세요")
             } else {
-                this.currentPage = 1; // Reset to first page on new search
+                this.currentPage = 1; 
                 this.searching = true;
-                this.fetchData(); // Call the method to fetch search results}
-            }},
-            fetchData() {
-                const idx = (this.currentPage - 1) * this.pageSize;
-                axios({
-                    url: "/text/textSearch.json",
-                    method: "post",
-                    headers: {
-                        "Content-Type": "application/json; charset=UTF-8",
-                    },
-                    data: {
-                        "option": this.option,
-                        "keyword": this.keyword,
-                        "pageSize": this.pageSize,
-                        "startIndex": idx
-                    },
-                })
-                    .then(response => {
-                        this.posts = response.data.list;
-                        if (!this.searching || this.keyword == "") {
-                            this.totalPosts = response.data.totalText;
-                        }
-                        else if (this.searching)
-                            this.totalPosts = response.data.resultCount;
-                        this.posts.forEach(post => {
-                            let regDt = post.regDt;
-                            let date = new Date(regDt);
-                            post.regDt = date.toISOString().split('T')[0];
-                        });
-                    })
-                    .catch(error => {
-                        console.error("fetchData - error: ", error);
-                        alert("검색 중 오류가 발생했습니다.");
+                this.fetchData();  
+            }
+        },
+        fetchData() {
+            const idx = (this.currentPage - 1) * this.pageSize;
+            axios({
+                url: "/text/textSearch.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                    "option": this.option,
+                    "keyword": this.keyword,
+                    "pageSize": this.pageSize,
+                    "startIndex": idx,
+                    "unitId": this.selectedUnit  
+                },
+            })
+                .then(response => {
+                    this.posts = response.data.list;
+                    if (!this.searching || this.keyword === "") {
+                        this.totalPosts = response.data.totalText;
+                    } else if (this.searching) {
+                        this.totalPosts = response.data.resultCount;
+                    }
+                    this.posts.forEach(post => {
+                        let regDt = post.regDt;
+                        let date = new Date(regDt);
+                        post.regDt = date.toISOString().split('T')[0];
                     });
-            },
-            changePage(page) {
-                if (page > 0 && page <= this.totalPages) {
-                    this.currentPage = page;
-                    this.fetchData();
-                }
+                })
+                .catch(error => {
+                    console.error("fetchData - error: ", error);
+                    alert("검색 중 오류가 발생했습니다.");
+                });
+        },
+        changePage(page) {
+            if (page > 0 && page <= this.totalPages) {
+                this.currentPage = page;
+                this.fetchData();
             }
         },
-        computed: {
-            totalPages() {
-                return Math.ceil(this.totalPosts / this.pageSize);
-            }
+        fetchBooks() {
+            axios({
+                url: "/book/findAll.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+            })
+                .then(response => {
+                    console.log(response.data)
+                    this.books = response.data;  
+                })
+                .catch(error => {
+                    console.error("fetchBooks - error: ", error);
+                    alert("교재 목록을 불러오는 중 오류가 발생했습니다.");
+                });
         },
-        components: {
-            SvgIcon
+        fetchUnits() {
+            if (!this.selectedBook) return; 
+
+            axios({
+                url: "/unit/unitList.json",
+                method: "post",
+                headers: {
+                    "Content-Type": "application/json; charset=UTF-8",
+                },
+                data: {
+                    "bookId": this.selectedBook
+                },
+            })
+                .then(response => {
+                    console.log(response.data)
+                    this.units = response.data; 
+                })
+                .catch(error => {
+                    console.error("fetchUnits - error: ", error);
+                    alert("단원 목록을 불러오는 중 오류가 발생했습니다.");
+                });
         },
-        mounted() {
-            this.fetchData();
+    },
+    computed: {
+        totalPages() {
+            return Math.ceil(this.totalPosts / this.pageSize);
         }
-    };
+    },
+    components: {
+        SvgIcon
+    },
+    mounted() {
+        this.fetchBooks(); // Fetch books when the component is mounted
+        this.fetchData(); // Fetch data for the default view
+    }
+};
 </script>
Add a comment
List