jichoi / lms_front star
박민혁 박민혁 2024-08-21
240821 박민혁 문제 페이지 수정
@968114ff0fcf61adbc02f2812c7888aaf34e93bf
client/views/pages/teacher/QuestionDetail.vue
--- client/views/pages/teacher/QuestionDetail.vue
+++ client/views/pages/teacher/QuestionDetail.vue
@@ -84,6 +84,9 @@
             </div>
             <div class="flex align-center ">
                 <label for="file" class="title2">첨부파일</label>
+                <div v-for="(data, index) in mainfile" :key="index">
+                    <label>{{ data.fileNm }}</label>
+                </div>
                 <input type="file" ref="fileInput" @change="handleFileUpload" multiple />
             </div>
             <hr>
@@ -99,11 +102,15 @@
                         <div class="flex align-center mb20">
                             <label :for="'correct' + i" class="title2">정답여부</label>
                             <input :id="'correct' + i" type="checkbox" class="ui-checkbox"
-                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i)" />
+                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i, 5)" />
                         </div>
                     </div>
                     <div class="flex align-center mb20">
                         <label :for="'file' + i" class="title2">첨부파일</label>
+                        <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
+
                         <input type="file" :ref="'fileInput' + i" @change="handleDetailFileUpload(i)" multiple />
                     </div>
                 </div>
@@ -121,18 +128,22 @@
                         <div class="flex align-center mb20">
                             <label :for="'correct' + i" class="title2">정답여부</label>
                             <input :id="'correct' + i" type="checkbox" class="ui-checkbox"
-                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i)" />
+                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i, 4)" />
                         </div>
                     </div>
                     <div class="flex align-center mb20">
                         <label :for="'file' + i" class="title2">첨부파일</label>
+                        <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
+
                         <input type="file" :ref="'fileInput' + i" @change="handleDetailFileUpload(i)" multiple />
                     </div>
 
                 </div>
             </div>
             <div
-                v-else-if="['prblm_type_001', 'prblm_type_005', 'prblm_type_019', 'prblm_type_022'].includes(selectedSearchOption2)">
+                v-else-if="['prblm_type_001', 'prblm_type_005', 'prblm_type_018', 'prblm_type_019', 'prblm_type_022'].includes(selectedSearchOption2)">
                 <!--3지선다-->
                 <div class="gd-col2 " v-for="i in 3" :key="i">
                     <div>
@@ -144,14 +155,16 @@
                         <div class="flex align-center mb20">
                             <label :for="'correct' + i" class="title2">정답여부</label>
                             <input :id="'correct' + i" type="checkbox" class="ui-checkbox"
-                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i)" />
+                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i, 3)" />
                         </div>
                     </div>
                     <div class="flex align-center mb20">
                         <label :for="'file' + i" class="title2">첨부파일</label>
+                        <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
                         <input type="file" :ref="'fileInput' + i" @change="handleDetailFileUpload(i)" multiple />
                     </div>
-
                 </div>
             </div>
             <div
@@ -167,11 +180,15 @@
                         <div class="flex align-center mb20">
                             <label :for="'correct' + i" class="title2">정답여부</label>
                             <input :id="'correct' + i" type="checkbox" class="ui-checkbox"
-                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i)" />
+                                :checked="prblmDetail.correctIndex === i" @change="setCorrectAnswer(i, 2)" />
                         </div>
                     </div>
                     <div class="flex align-center mb20">
                         <label :for="'file' + i" class="title2">첨부파일</label>
+                        <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
+
                         <input type="file" :ref="'fileInput' + i" @change="handleDetailFileUpload(i)" multiple />
                     </div>
 
@@ -188,13 +205,16 @@
                 </div>
                 <div class="flex align-center mb20">
                     <label :for="'file' + i" class="title2">첨부파일</label>
+                    <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
+
                     <input type="file" :ref="'fileInput' + 1" @change="handleDetailFileUpload(1)" multiple />
                 </div>
-
             </div>
             <div
                 v-else-if="['prblm_type_010', 'prblm_type_011', 'prblm_type_012', 'prblm_type_013', 'prblm_type_014',
-                    'prblm_type_015', 'prblm_type_016', 'prblm_type_017', 'prblm_type_018', 'prblm_type_020', 'prblm_type_021'].includes(selectedSearchOption2)">
+                    'prblm_type_015', 'prblm_type_016', 'prblm_type_017', 'prblm_type_020', 'prblm_type_021'].includes(selectedSearchOption2)">
                 <!--서술형-->
                 <div class="gd-col2 ">
                     <div class="flex align-center mb20">
@@ -203,6 +223,10 @@
                     </div>
                     <div class="flex align-center mb20">
                         <label :for="'file' + i" class="title2">첨부파일</label>
+                        <div v-for="(data, index) in prblmDetail.answers[i].fileInfo" :key="index">
+                            <label>{{ data.fileNm }}</label>
+                        </div>
+
                         <input type="file" :ref="'fileInput' + 1" @change="handleDetailFileUpload(1)" multiple />
                     </div>
 
@@ -284,20 +308,21 @@
             prblm_mtr4: '',
             prblm_mtr5: '',
             prblm_mtr6: '',
+            file_mng_id: '',
             prblmDetail: {
                 answers: {
-                    1: { text: '', isCorrect: 'N', fileMngId: null },
-                    2: { text: '', isCorrect: 'N', fileMngId: null },
-                    3: { text: '', isCorrect: 'N', fileMngId: null },
-                    4: { text: '', isCorrect: 'N', fileMngId: null },
-                    5: { text: '', isCorrect: 'N', fileMngId: null },
+                    1: { text: '', isCorrect: 'N', fileMngId: null, fileInfo: '' },
+                    2: { text: '', isCorrect: 'N', fileMngId: null, fileInfo: '' },
+                    3: { text: '', isCorrect: 'N', fileMngId: null, fileInfo: '' },
+                    4: { text: '', isCorrect: 'N', fileMngId: null, fileInfo: '' },
+                    5: { text: '', isCorrect: 'N', fileMngId: null, fileInfo: '' },
                 },
                 correctIndex: null, // 정답으로 선택된 답의 인덱스
             },
             books: [],
             units: [],
             texts: [],
-            file: '',
+            mainfile: null,
             selectedFiles: {},
         }
     },
@@ -314,61 +339,78 @@
             this.selectedFiles[index] = files;
         },
 
-        problemSearch() {
-            const vm = this;
-            vm.prblm = JSON.parse(sessionStorage.getItem("selectQuestionList"));
-            axios({
-                url: "problem/problemInfo.json",
-                method: "post",
-                headers: {
-                    "Content-Type": "application/json; charset=UTF-8",
-                },
-                data: {
-                    prblmId: vm.prblm.prblmId,
-                },
-            })
-                .then(function (res) {
-                    console.log("problem - response : ", res.data);
-                    vm.dataList = res.data.problem;
-                    vm.problemDetail = res.data.problemDetail;
+        // 문제 정보 가져오기
+        async problemSearch() {
+            try {
+                const vm = this;
+                vm.prblm = JSON.parse(sessionStorage.getItem("selectQuestionList"));
 
-                    vm.selectedSearchOption = vm.dataList.prblmCtgryId;
-                    vm.selectedSearchOption2 = vm.dataList.prblmTypeId;
-                    vm.book_id = vm.dataList.bookId;
-                    vm.unit_id = vm.dataList.unitId;
-                    vm.text_id = vm.dataList.textId;
-                    vm.prblm_scr = vm.dataList.prblmScr;
-                    vm.prblm_expln = vm.dataList.prblmExpln;
-                    vm.prblm_hint = vm.dataList.prblmHint;
-                    vm.prblm_cmmt = vm.dataList.prblmCmmt;
-                    vm.prblm_mtr1 = vm.dataList.prblmMtr1;
-                    vm.prblm_mtr2 = vm.dataList.prblmMtr2;
-                    vm.prblm_mtr3 = vm.dataList.prblmMtr3;
-                    vm.prblm_mtr4 = vm.dataList.prblmMtr4;
-                    vm.prblm_mtr5 = vm.dataList.prblmMtr5;
-                    vm.prblm_mtr6 = vm.dataList.prblmMtr6;
+                const res = await axios({
+                    url: "problem/problemInfo.json",
+                    method: "post",
+                    headers: {
+                        "Content-Type": "application/json; charset=UTF-8",
+                    },
+                    data: {
+                        prblmId: vm.prblm.prblmId,
+                    },
+                });
 
-                    if (vm.problemDetail.length > 0) {
-                        vm.prblmDetail.answers = vm.problemDetail.reduce((acc, detail, index) => {
-                            acc[index + 1] = {
-                                text: detail.prblmDtlExpln,
-                                isCorrect: detail.prblmYn === 'Y' ? 'Y' : 'N',
-                                fileMngId: detail.fileMngId || null
-                            };
-                            return acc;
-                        }, {});
+                console.log("problem - response : ", res.data);
+                vm.dataList = res.data.problem;
+                vm.problemDetail = res.data.problemDetail;
 
-                        vm.prblmDetail.correctIndex = vm.problemDetail.findIndex(detail => detail.prblmYn === 'Y');
+                vm.selectedSearchOption = vm.dataList.prblmCtgryId;
+                vm.selectedSearchOption2 = vm.dataList.prblmTypeId;
+                vm.book_id = vm.dataList.bookId;
+                vm.unit_id = vm.dataList.unitId;
+                vm.text_id = vm.dataList.textId;
+                vm.prblm_scr = vm.dataList.prblmScr;
+                vm.prblm_expln = vm.dataList.prblmExpln;
+                vm.prblm_hint = vm.dataList.prblmHint;
+                vm.prblm_cmmt = vm.dataList.prblmCmmt;
+                vm.prblm_mtr1 = vm.dataList.prblmMtr1;
+                vm.prblm_mtr2 = vm.dataList.prblmMtr2;
+                vm.prblm_mtr3 = vm.dataList.prblmMtr3;
+                vm.prblm_mtr4 = vm.dataList.prblmMtr4;
+                vm.prblm_mtr5 = vm.dataList.prblmMtr5;
+                vm.prblm_mtr6 = vm.dataList.prblmMtr6;
+                vm.file_mng_id = vm.dataList.fileMngId;
 
-                        if (vm.dataList.prblmTypeId === 'prblm_type_009') {
-                            vm.prblmDetail.answer1 = vm.problemDetail.find(detail => detail.prblmYn === 'Y') ? 'O' : 'X';
+                if (vm.problemDetail.length > 0) {
+                    vm.prblmDetail.answers = {};
+
+                    for (let index = 0; index < vm.problemDetail.length; index++) {
+                        const detail = vm.problemDetail[index];
+                        let fileInfo = null;
+
+                        if (detail.fileMngId) {
+                            fileInfo = await vm.findFile(detail.fileMngId);
                         }
+
+                        vm.prblmDetail.answers[index + 1] = {
+                            prblmDtlId: detail.prblmDtlId,
+                            text: detail.prblmDtlExpln,
+                            isCorrect: detail.prblmYn === 'Y' ? 'Y' : 'N',
+                            fileMngId: detail.fileMngId || null,
+                            fileInfo: fileInfo
+                        };
                     }
 
-                })
-                .catch(function (error) {
-                    console.log("problem - error : ", error);
-                });
+                    vm.prblmDetail.correctIndex = vm.problemDetail.findIndex(detail => detail.prblmYn === 'Y') + 1;
+
+                    if (vm.dataList.prblmTypeId === 'prblm_type_009') {
+                        vm.prblmDetail.answer1 = vm.problemDetail.find(detail => detail.prblmYn === 'Y') ? 'O' : 'X';
+                    }
+                }
+
+                if (vm.file_mng_id) {
+                    vm.mainfile = await vm.findFile(vm.file_mng_id);
+                }
+
+            } catch (error) {
+                console.log("problem - error : ", error);
+            }
         },
 
         // 문제 수정
@@ -405,7 +447,7 @@
                 textId: this.text_id, // 지문 아이디
                 unitId: this.unit_id, // 단원 아이디
                 bookId: this.book_id, // 교재 아이디
-               // userId: this.user_id, // 유저 아이디
+                // userId: this.user_id, // 유저 아이디
                 userId: 'USID_000000000000004', // 유저 아이디
                 prblmMtr1: this.prblm_mtr1, // 문제 지표
                 prblmMtr2: this.prblm_mtr2,
@@ -461,7 +503,7 @@
                 answerCount = 5;
             } else if (['prblm_type_004', 'prblm_type_006', 'prblm_type_024'].includes(this.selectedSearchOption2)) {
                 answerCount = 4;
-            } else if (['prblm_type_001', 'prblm_type_005', 'prblm_type_019', 'prblm_type_022'].includes(this.selectedSearchOption2)) {
+            } else if (['prblm_type_001', 'prblm_type_005', 'prblm_type_018', 'prblm_type_019', 'prblm_type_022'].includes(this.selectedSearchOption2)) {
                 answerCount = 3;
             } else if (['prblm_type_002', 'prblm_type_003', 'prblm_type_007', 'prblm_type_023'].includes(this.selectedSearchOption2)) {
                 answerCount = 2;
@@ -476,7 +518,7 @@
                 }
 
                 details.push({
-                    prblmId,
+                    prblmDtlId: answers[i].prblmDtlId,
                     prblmDtlExpln: answers[i].text || '',
                     prblmYn: answers[i].isCorrect, // isCorrect가 'Y' 또는 'N'으로 설정됨
                     fileMngId: answers[i].fileMngId,
@@ -487,10 +529,10 @@
             return details;
         },
 
-        setCorrectAnswer(index) {
+        setCorrectAnswer(index, size) {
             this.prblmDetail.correctIndex = index;
             // 선택된 인덱스의 답만 'Y'로 설정하고, 나머지는 'N'으로 설정
-            for (let i = 1; i <= 5; i++) {
+            for (let i = 1; i <= size; i++) {
                 this.prblmDetail.answers[i].isCorrect = i === index ? 'Y' : 'N';
             }
         },
@@ -625,6 +667,32 @@
                 });
         },
 
+        // 업로드한 파일 정보 가져오기
+        async findFile(fileMngId) {
+            try {
+                const response = await axios({
+                    url: "/file/find.json",
+                    method: "post",
+                    headers: {
+                        "Content-Type": "application/json; charset=UTF-8",
+                    },
+                    data: {
+                        file_mng_id: fileMngId,
+                    },
+                });
+
+                if (response.data && response.data.list) {
+                    return response.data.list; // 파일 정보를 반환
+                } else {
+                    console.error("파일 정보를 가져오는 데 실패했습니다: ", response.data);
+                    return [];
+                }
+            } catch (error) {
+                console.log("result - error : ", error);
+                return [];
+            }
+        }
+
     },
     watch: {
     },
@@ -641,6 +709,7 @@
 
         this.fetchBooks();
         this.fetchUnits();
+        this.fetchTexts();
 
         this.problemSearch();
     }
client/views/pages/teacher/QuestionInsert.vue
--- client/views/pages/teacher/QuestionInsert.vue
+++ client/views/pages/teacher/QuestionInsert.vue
@@ -620,6 +620,7 @@
 
         this.fetchBooks();
         this.fetchUnits();
+        this.fetchTexts();
     }
 }
 
Add a comment
List