jichoi / lms_front star
PsHooN7979 08-09
240809 박세훈 게시판 수정
@6c8fd5e3292469fa246518de030bc3ddd0ccca27
client/views/pages/teacher/Board.vue
--- client/views/pages/teacher/Board.vue
+++ client/views/pages/teacher/Board.vue
@@ -153,25 +153,26 @@
       })
         .then(function (res) {
           console.log("dataList - response : ", res.data);
-
-          vm.dataList = res.data.result[0].boardClass[0].board;
-          vm.userNm = res.data.result[0].userNm;
-          vm.userId = res.data.result[0].userId;
-          vm.totalPosts = res.data.totalBoard;
-          vm.selectClass();
-          sessionStorage.removeItem("selectedBoardList");
-          sessionStorage.removeItem("file");
-
-          console.log(vm.userId);
+          if (res.data.result.length !== 0) {
+            vm.dataList = res.data.result[0].boardClass[0].board;
+            vm.userNm = res.data.result[0].userNm;
+            vm.userId = res.data.result[0].userId;
+            vm.totalPosts = res.data.totalBoard;
+            vm.selectClass();
+            sessionStorage.removeItem("bbsId");
+            sessionStorage.removeItem("file");
+          } else {
+            vm.selectClass();
+          }
         })
         .catch(function (error) {
-          console.log("result - error : ", error);
+          console.log("boardListError - error : ", error);
         });
     },
 
     // 게시글 정보 세션에 저장
     selectBoardList(item) {
-      sessionStorage.setItem("selectedBoardList", JSON.stringify(item));
+      sessionStorage.setItem("bbsId", JSON.stringify(item.bbsId));
     },
 
     // 반 아이디 세션에 저장
@@ -210,7 +211,6 @@
     // 반 조회
     selectClass() {
       const vm = this;
-      console.log(vm.userId);
       axios({
         url: "/classes/selectClass.json",
         method: "post",
client/views/pages/teacher/noticeDetail.vue
--- client/views/pages/teacher/noticeDetail.vue
+++ client/views/pages/teacher/noticeDetail.vue
@@ -70,6 +70,7 @@
 
       dataList: null,
       sclsId: "",
+      bbsId: "",
 
       title: "",
       content: "",
@@ -83,19 +84,33 @@
     goToPage(page) {
       this.$router.push({ name: page });
     },
-    created() {
-      const vm = this;
-      const seletedBoardList = JSON.parse(
-        sessionStorage.getItem("selectedBoardList")
-      );
 
-      if (seletedBoardList) {
-        vm.dataList = seletedBoardList;
-      }
-      vm.title = vm.dataList.bbsTtl;
-      vm.content = vm.dataList.bbsCnt;
-      vm.category = vm.dataList.bbsCls;
-      vm.time = vm.dataList.bbsTm;
+    findBoard() {
+      const vm = this;
+      vm.bbsId = JSON.parse(sessionStorage.getItem("bbsId"));
+      console.log(vm.bbsId);
+      axios({
+        url: "/board/find.json",
+        method: "post",
+        headers: {
+          "Content-Type": "application/json; charset=UTF-8",
+        },
+        data: {
+          bbsId: vm.bbsId,
+        },
+      })
+        .then(function (res) {
+          console.log("boardData - response : ", res.data);
+          vm.dataList = res.data.result[0].boardClass[0].board[0];
+          vm.title = vm.dataList.bbsTtl;
+          vm.content = vm.dataList.bbsCnt;
+          vm.category = vm.dataList.bbsCls;
+          vm.time = vm.dataList.bbsTm;
+          vm.findFile();
+        })
+        .catch(function (error) {
+          console.log("boardData - error : ", error);
+        });
     },
 
     findFile() {
@@ -136,16 +151,11 @@
         .then(function (res) {
           console.log("dataList - response : ", res.data);
           vm.dataList = res.data[0].boardClass[0].board[0];
-          sessionStorage.setItem(
-            "selectedBoardList",
-            JSON.stringify(vm.dataList)
-          );
           vm.title = vm.dataList.bbsTtl;
           vm.content = vm.dataList.bbsCnt;
           vm.category = vm.dataList.bbsCls;
           vm.time = vm.dataList.bbsTm;
           vm.findFile();
-          console.log(vm.dataList);
         })
         .catch(function (error) {
           console.log("result - error : ", error);
@@ -169,16 +179,11 @@
         .then(function (res) {
           console.log("dataList - response : ", res.data);
           vm.dataList = res.data[0].boardClass[0].board[0];
-          sessionStorage.setItem(
-            "selectedBoardList",
-            JSON.stringify(vm.dataList)
-          );
           vm.title = vm.dataList.bbsTtl;
           vm.content = vm.dataList.bbsCnt;
           vm.category = vm.dataList.bbsCls;
           vm.time = vm.dataList.bbsTm;
           vm.findFile();
-          console.log(vm.dataList);
         })
         .catch(function (error) {
           console.log("result - error : ", error);
@@ -213,8 +218,7 @@
   },
   mounted() {
     console.log("Main2 mounted");
-    this.created();
-    this.findFile();
+    this.findBoard();
   },
 };
 </script>
client/views/pages/teacher/noticeInsert.vue
--- client/views/pages/teacher/noticeInsert.vue
+++ client/views/pages/teacher/noticeInsert.vue
@@ -14,13 +14,18 @@
       <div class="flex align-center">
         <label for="file" class="title2">첨부파일</label>
         <label for="file" class="title2"> {{ file.fileNm }}</label>
-        <input type="file" ref="fileInput" @change="handleFileUpload" />
+        <input
+          type="file"
+          ref="fileInput"
+          @change="handleFileUpload"
+          multiple
+        />
       </div>
       <div class="flex justify-between mt50">
         <button title="글쓰기" class="new-btn" @click="goToPage('Board')">
           목록
         </button>
-        <button title="글쓰기" class="new-btn" @click="goToPage('Board')">
+        <button title="글쓰기" class="new-btn">
           {{ buttonLabel }}
         </button>
       </div>
@@ -43,8 +48,10 @@
       category: "Notice",
       file: "",
       sclsId: "",
+      bbsId: "",
+      fileMngId: null,
 
-      selectedFile: null,
+      selectedFiles: [],
       dataList: "",
 
       // 데이터 편집 상태 (true = 수정, false = 등록)
@@ -57,57 +64,89 @@
     },
 
     handleFileUpload(e) {
-      this.selectedFile = e.target.files[0];
-      console.log(this.selectedFile);
+      this.selectedFiles = e.target.files;
     },
 
     created() {
       const vm = this;
       const sclsId = JSON.parse(sessionStorage.getItem("sclsId"));
-      const dataList = JSON.parse(sessionStorage.getItem("selectedBoardList"));
+      const bbsId = JSON.parse(sessionStorage.getItem("bbsId"));
       const file = JSON.parse(sessionStorage.getItem("file"));
 
       if (sclsId) {
         vm.sclsId = sclsId;
-        if (dataList && file) {
-          vm.dataList = dataList;
+        if (bbsId && file) {
+          vm.bbsId = bbsId;
           vm.file = file;
-          vm.title = vm.dataList.bbsTtl;
-          vm.content = vm.dataList.bbsCnt;
-          vm.category = vm.dataList.bbsCls;
+          vm.fileMngId = file.fileMngId;
           vm.isEditMode = true;
+          vm.findBoard();
         } else {
           vm.isEditMode = false;
         }
       }
     },
+
+    // 게시글 상세 조회
+    findBoard() {
+      const vm = this;
+      vm.bbsId = JSON.parse(sessionStorage.getItem("bbsId"));
+      console.log(vm.bbsId);
+      axios({
+        url: "/board/find.json",
+        method: "post",
+        headers: {
+          "Content-Type": "application/json; charset=UTF-8",
+        },
+        data: {
+          bbsId: vm.bbsId,
+        },
+      })
+        .then(function (res) {
+          console.log("boardData - response : ", res.data);
+          vm.dataList = res.data.result[0].boardClass[0].board[0];
+          vm.title = vm.dataList.bbsTtl;
+          vm.content = vm.dataList.bbsCnt;
+          vm.category = vm.dataList.bbsCls;
+          vm.time = vm.dataList.bbsTm;
+        })
+        .catch(function (error) {
+          console.log("boardData - error : ", error);
+        });
+    },
+
     // 게시글 등록
     async dataInsert() {
       const vm = this;
       try {
         // 파일 업로드
-        const formData = new FormData();
-        formData.append("files", this.selectedFile);
-
-        const fileUploadResponse = await axios.post(
-          "/file/upload.json",
-          formData,
-          {
-            headers: {
-              "Content-Type": "multipart/form-data",
-            },
+        if (this.selectedFiles && this.selectedFiles.length > 0) {
+          // 파일 업로드
+          const formData = new FormData();
+          for (let i = 0; i < this.selectedFiles.length; i++) {
+            formData.append("files", this.selectedFiles[i]);
           }
-        );
 
-        // 업로드 후 파일 매니지 아이디 호출
-        const fileMngId = fileUploadResponse.data.fileMngId;
+          const fileUploadResponse = await axios.post(
+            "/file/upload.json",
+            formData,
+            {
+              headers: {
+                "Content-Type": "multipart/form-data",
+              },
+            }
+          );
+
+          // 업로드 후 파일 매니지 아이디 호출
+          fileMngId = fileUploadResponse.data.fileMngId;
+        }
 
         // 게시물 등록
         const newData = {
           bbsTtl: vm.title,
           bbsCls: vm.category,
           bbsCnt: vm.content,
-          fileMngId: fileMngId,
+          fileMngId: vm.fileMngId,
           sclsId: vm.sclsId,
         };
 
@@ -126,29 +165,33 @@
       const vm = this;
 
       // 파일 업로드
-      const formData = new FormData();
-      formData.append("files", this.selectedFile);
-
-      const fileUploadResponse = await axios.post(
-        "/file/upload.json",
-        formData,
-        {
-          headers: {
-            "Content-Type": "multipart/form-data",
-          },
+      if (this.selectedFiles && this.selectedFiles.length > 0) {
+        // 파일 업로드
+        const formData = new FormData();
+        for (let i = 0; i < this.selectedFiles.length; i++) {
+          formData.append("files", this.selectedFiles[i]);
         }
-      );
 
-      // 업로드 후 파일 매니지 아이디 호출
-      const fileMngId = fileUploadResponse.data.fileMngId;
+        const fileUploadResponse = await axios.post(
+          "/file/upload.json",
+          formData,
+          {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          }
+        );
+
+        // 업로드 후 파일 매니지 아이디 호출
+        fileMngId = fileUploadResponse.data.fileMngId;
+      }
 
       const newData = {
         bbsTtl: vm.title,
         bbsCls: vm.category,
         bbsCnt: vm.content,
-        fileMngId: fileMngId,
-        sclsId: vm.sclsId,
-        bbsId: this.dataList.bbsId,
+        fileMngId: vm.fileMngId,
+        bbsId: vm.bbsId,
       };
       await axios({
         url: "/board/update.json",
Add a comment
List