Pārlūkot izejas kodu

处理学生作答数据提交

zhousheng 4 gadi atpakaļ
vecāks
revīzija
a0b9eb1163

+ 1 - 3
TEAMModelOS/ClientApp/src/components/student-web/EventView/EventContentTypeTemplate/LessonTest.vue

@@ -30,7 +30,7 @@
                 <button @click="gotoNextItem()">確定</button>
             </div>
         </div>
-        <LessonTestPop :papers="selectData" v-if="openEva" />
+        <LessonTestPop :papers="selectData"  v-if="this.$store.getters.getisOpenLessonTestPopNow"  />
         <div>
             <EventBasicInfo :paper="paperData" />
             <div v-if="this.$store.getters.getItemTitle.isDone == false && this.$store.getters.getItemTitle.endTime <= '2020.02.10' &&this.$store.getters.getItemTitle.allowRetryNow == false">
@@ -373,7 +373,6 @@
                 }
             },
             async getPaper(data) {
-                this.openEva = false
                 this.selectData = {}
                 if (data.blob !== undefined && data.blob !== "") {
                     let key = data.code.split('-')
@@ -386,7 +385,6 @@
                     if (this.selectData.item) {
                         this.$store.commit("ToggleLessonTestPopWithSubject", data)
                         this.$store.commit("SetPaperInfo", this.selectData)
-                        this.openEva = true
                     }
                 }
             },

+ 152 - 78
TEAMModelOS/ClientApp/src/components/student-web/EventView/EventContentTypeTemplate/LessonTestPop.vue

@@ -53,9 +53,6 @@
             <div class="myProgressBar">
                 <span class="myTestProgresstitle">完成度</span>
                 <Progress style="margin-top:15px" :percent="Math.ceil((($store.getters.getPaperInfo.item.length - undo)/$store.getters.getPaperInfo.item.length)*100)" />
-                <!-- <span class="myTestProgressNum">{{ ($store.getters.getPaperInfo.item.length - undo)/$store.getters.getPaperInfo.item.length  * 100 + " % " }}</span>
-    <div class="myTestProgressContent" :style="{ width: Math.ceil((($store.getters.getPaperInfo.item.length - undo)/$store.getters.getPaperInfo.item.length)*100) + '%' }"></div>
-    <div class="myTestProgress"></div> -->
             </div>
 
             <button class="submitBtn" @click="openWarmMessage(2)" :class="{ hintClick: hintHandon() }">交卷</button>
@@ -65,7 +62,7 @@
                    :xs="24"
                    :sm="24"
                    :md="12"
-                   :lg="getQuestionData(currentQuestionNo).type == 'compose' ? 17 : 24">
+                   :lg="getQuestionData(currentQuestionNo).type != 'single'&& getQuestionData(currentQuestionNo).type != 'judge'&& getQuestionData(currentQuestionNo).type != 'multiple'? 24 : 17">
                 <div class="questionContent">
                     <span class="hintwrap">
                         <Tooltip :content="'提示'" theme="light" placement="left">
@@ -75,7 +72,7 @@
                         </Tooltip>
                     </span>
 
-                    <div class="questionType">{{ getTestType(getQuestionData(currentQuestionNo).type)}}</div>
+                    <div class="questionType">{{ getTestType(getQuestionData(currentQuestionNo).type)}}{{getQuestionData(currentQuestionNo).type}}</div>
 
                     <div class="questioDes">
                         <div style="display:flex">
@@ -83,26 +80,33 @@
                             <div v-html="getQuestionData(currentQuestionNo).question"></div>
                         </div>
                         <!--填充題輸入匡-->
-                        <input v-if="getQuestionData(currentQuestionNo).type == 'compose'"
-                               type="text"
-                               v-model="checkers[currentQuestionNo][0]"
-                               required
-                               minlength="3"
-                               maxlength="5" />
-                        &nbsp;
-                        <input v-if="getQuestionData(currentQuestionNo).type == 'compose'"
-                               type="text"
-                               v-model="checkers[currentQuestionNo][1]"
-                               required
-                               minlength="3"
-                               maxlength="5" />
-                        &nbsp;
-                        <input v-if="getQuestionData(currentQuestionNo).type == 'compose'"
-                               type="text"
-                               v-model="checkers[currentQuestionNo][2]"
-                               required
-                               minlength="3"
-                               maxlength="5" />
+                        <div v-if="getQuestionData(currentQuestionNo).type == 'compose'">
+                            <div v-for="(item,index) in getQuestionData(currentQuestionNo).children">
+                                <div style="display:flex;margin-top:20px">
+                                    <span>({{index +1}})</span>{{'compose'+index}}
+                                    <div v-html="item.question"></div>
+                                </div>
+                                <div :ref="'compose'+index" :data-index="index" style="text-align:left" @click="optionClick(item)"></div>
+                            </div>
+                            <!--<input type="text"
+                                   v-model="checkers[currentQuestionNo][0]"
+                                   required
+                                   minlength="3"
+                                   maxlength="5" />
+                            &nbsp;
+                            <input type="text"
+                                   v-model="checkers[currentQuestionNo][1]"
+                                   required
+                                   minlength="3"
+                                   maxlength="5" />
+                            &nbsp;
+                            <input type="text"
+                                   v-model="checkers[currentQuestionNo][2]"
+                                   required
+                                   minlength="3"
+                                   maxlength="5" />-->
+                        </div>
+                       
                     </div>
 
                     <div class="md-ansSheetGroup">
@@ -148,7 +152,7 @@
 
 
                     <!--切換頁-->
-                    <div class="pageCtl2" v-if="getQuestionData(currentQuestionNo).type == 'compose'">
+                    <div class="pageCtl2" v-if="getQuestionData(currentQuestionNo).type != 'single'&& getQuestionData(currentQuestionNo).type != 'judge'&& getQuestionData(currentQuestionNo).type != 'multiple'">
                         <button @click="preQ()" v-if="currentQuestionNo != 0">
                             <Icon type="ios-arrow-back" />上一題
                         </button>
@@ -168,13 +172,13 @@
                    :sm="24"
                    :md="12"
                    :lg="7"
-                   v-if="getQuestionData(currentQuestionNo).type != 'compose'">
+                   v-if="getQuestionData(currentQuestionNo).type == 'single'|| getQuestionData(currentQuestionNo).type == 'judge'|| getQuestionData(currentQuestionNo).type == 'multiple'">
                 <div class="checkAnswer">
                     <div class="questionNo">第{{ currentQuestionNo + 1 }}題 我的答案是:</div>
                     <div v-if="getQuestionData(currentQuestionNo).type == 'judge'" align="center">
                         <label class="testBtn yesNoBtn">
                             <input type="radio" value="O" v-model="checkers[currentQuestionNo]" />
-                            <div class="testbg">○</div>
+                            <Icon type="ios-radio-button-off" />
                         </label>
                         <label class="testBtn yesNoBtn">
                             <input type="radio" value="X" v-model="checkers[currentQuestionNo]" />
@@ -214,9 +218,11 @@
                         <label class="testBtn"
                                v-for="(item, index) in getQuestionData(currentQuestionNo).option"
                                :key="index">
-                            <input :type="qtypeOption(currentQuestionNo)"
+                            <input type="checkbox"
                                    :value="getQuestionData(currentQuestionNo).option[index].code"
-                                   v-model="checkers[currentQuestionNo]" />
+                                   v-model="checkers[currentQuestionNo]" 
+                                    @click="getAns(currentQuestionNo,index)"
+                                   />
                             <div class="testbg">
                                 <Row :gutter="10">
                                     <i-col :xs="8" :sm="8" :md="8" :lg="8">
@@ -266,6 +272,7 @@
 <script>
     import Loading from "vue-loading-overlay";
     import "vue-loading-overlay/dist/vue-loading.css";
+    import E from '@/utils/wangEditor.js'
     export default {
         name: "LessonTestPop",
         components: {
@@ -277,6 +284,8 @@
             this.WarmMessageisOpen = false;
             this.showMessageNum = 0;
         },
+        mounted() {
+        },
         props: {
             papers: {
                 type: Object,
@@ -287,6 +296,19 @@
         },
         data() {
             return {
+                options: [...new Array(4).keys()], // 默认四个选项
+                existOptions: [...new Array(4).keys()],
+                initFlag: true,
+                trueIndex: 0,
+                editSingleInfo: {},
+                stemEditor: null,
+                stemContent: '',
+                optionsContent: [],
+                optionEditors: [],
+                defaultConfig: {
+                    uploadImgShowBase64: true,
+                    menus: this.$tools.wangEditorMenuSimple
+                },
                 //loading畫面
                 ishideHint: false,
                 isLoading: false,
@@ -330,14 +352,68 @@
             };
         },
         methods: {
+            //初始化编辑器
+            initEditors() {
+                if (this.getQuestionData(this.currentQuestionNo).children.length > 0) {
+                    this.getQuestionData(this.currentQuestionNo).children.forEach((item, i) => {
+                        console.log(i)
+                        let that = this
+                        let editor = new E(that.$refs['compose' + i])
+                        editor.customConfig = this.defaultConfig
+                        editor.customConfig.uploadVideoDisable = true,
+
+                            // 选项编辑器失焦隐藏工具栏
+                            editor.customConfig.onblur = function () {
+                                let allToolbars = document.getElementsByClassName('qn-option-editor')
+                                for (let i = 0; i < allToolbars.length; i++) {
+                                    if (allToolbars[i].children.length) {
+                                        allToolbars[i].children[0].style.visibility = 'hidden'
+                                    }
+                                }
+                            }
+
+                        editor.customConfig.onVideoWarning = (text) => {
+                            this.$Message.warning(text)
+                        },
+
+                            // 选项编辑器内容发生变化时
+                            editor.customConfig.onchange = (html) => {
+                                let key = String.fromCharCode(64 + parseInt(i + 1))
+                                let codeArr = this.optionsContent.map(item => item.code)
+                                // 如果已经编辑过则 修改选项内容
+                                if (codeArr.indexOf(key) !== -1) {
+                                    this.optionsContent[codeArr.indexOf(key)].value = html
+                                } else { // 否则创建新选项
+                                    let option = {
+                                        code: key,
+                                        value: html
+                                    }
+                                    this.optionsContent.push(option)
+                                }
+                            }
+                        editor.create()
+                        this.optionEditors.push(editor)
+                        that.$refs["compose" + i].dataset.editorId = editor.id
+
+                        // 如果是编辑状态 则将选项内容回显
+                        if (Object.keys(this.editSingleInfo).length > 0) {
+                            editor.txt.html(this.editSingleInfo.option[i].value)
+                        }
+                    })
+                }
+            },
             getPaper() {
                 let paper = this.$store.getters.getCurrentSubject
                 this.paperData = { ...paper }
                 console.log(paper)
+               
             },
             getTestType(data) {
                 for (let item of this.testType) {
                     if (item.value == data) {
+                        if (item.value != 'single' || item.value != 'judge' || item.value != 'multiple') {
+                            //this.initEditors()
+                        }
                         return item.label
                     }
                 }
@@ -352,6 +428,12 @@
                 }
                 
             },
+            getAns(data, index) {
+                if (this.getQuestionData(this.currentQuestionNo).type == "single") {
+                    this.checkers[data].push(this.getQuestionData(this.currentQuestionNo).option[index].code)
+                }
+            },
+
             hintHandon() {
                 var undoQuestion = 0;
                 for (var i = 0; i <= this.$store.getters.getPaperInfo.item.length-1; i++) {
@@ -359,7 +441,6 @@
                         undoQuestion++;
                     }
                 }
-                console.log("未做題目" + undoQuestion);
                 this.undo = undoQuestion;
                 if (undoQuestion != 0) return false;
                 else return true;
@@ -391,10 +472,6 @@
                         if (this.checkers[i] != "") {
                             this.showMessageNum = 2;
                         }
-                        console.log(
-                            "第" + i + "題:" + this.checkers[i],
-                            this.checkers[i] == ""
-                        );
                     }
                 } else return;
                 console.log(this.showMessageNum);
@@ -404,51 +481,48 @@
             },
             closetest: function () {
                 this.WarmMessageisOpen = false;
-                this.doAjax();
-
-                if (this.showMessageNum == 2) {
-                    let multiSubject = ["國文", "英文", "數學"];
-                    console.log(
-                        "完成測驗",
-                        this.$store.getters.getCurrentSubject,
-                        multiSubject.includes(this.$store.getters.getCurrentSubject)
-                    );
-
-                    // if (
-                    //   multiSubject.includes(this.$store.getters.getCurrentSubject) == false
-                    // ) {
-                    //   this.$store.commit(
-                    //     "SavefinishedItemID",
-                    //     this.$store.getters.getItemTitle.eventID
-                    //   );
-                    // }
-                    // if (
-                    //   multiSubject.includes(this.$store.getters.getCurrentSubject) == true
-                    // ) {
-                    //   this.$store.commit(
-                    //     "SavefinishedSubject",
-                    //     this.$store.getters.getCurrentSubject
-                    //   );
-                    //   if (
-                    //     this.$store.getters.getCurrentfinishedSubject.length ==
-                    //     multiSubject.length
-                    //   ) {
-                    //     this.$store.commit(
-                    //       "SavefinishedItemID",
-                    //       this.$store.getters.getItemTitle.eventID
-                    //     );
-                    //   }
-                    // }
-                }
+                if (this.checkers.length) {
+                    let len = 0
+                    for (let item of this.checkers) {
+                        if (item.length !== 0) {
+                            len++
+                        }
+                    }
+                    if (len = this.$store.getters.getPaperInfo.item.length) {
+                        this.summit();
+                    } else {
+                        this.$Message.warning('请完成作答再提交!')
+                    }
+                } 
             },
-            doAjax() {
+            summit() {
+                console.log(this.$store.getters.getPaperInfo)
+                console.log(this.$store.getters.getItemTitle)
                 this.isLoading = true;
-
-                // simulate AJAX
-                setTimeout(() => {
-                    this.$store.commit("ToggleLessonTestPopWithSubject", "");
-                    this.isLoading = false;
-                }, 3000);
+                let req = {
+                    id: this.$store.getters.getPaperInfo.id,
+                    answer: this.checkers,
+                    studentId: this.$store.state.userInfo.sub,
+                    classId: this.$store.state.user.studentProfile.classinfo.id,
+                    subjectId: this.$store.getters.getPaperInfo.subjectId,
+                    multipleRule: this.$store.getters.getPaperInfo.multipleRule,
+                    paperId: this.$store.getters.getItemTitle.id,
+                    school: this.$store.getters.getItemTitle.school
+                }
+                this.$api.studentWeb.SaveStuExamPaper(req).then(res => {
+                    if (res) {
+                        this.$Message.success('作答信息提交成功!')
+                        setTimeout(() => {
+                            this.$store.commit("ToggleLessonTestPopWithSubject", "");
+                            this.isLoading = false;
+                        }, 2000);
+                    }
+                }, err => {
+                    this.$Message.warning('作答信息保存失败!')
+                    setTimeout(() => {
+                        this.isLoading = false;
+                    }, 1000);
+                })
             },
         },
         watch: {