ting.yin 4 年之前
父節點
當前提交
4d976d9938

+ 8 - 12
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/jsonView.jsp

@@ -55,6 +55,7 @@
                         for (var j in questions) {
                         	var question = questions[j];
                         	var subNumber = question.subIndex==null?question.subNumber:question.subNumber+"-"+question.subIndex;
+                        	let jsons = findJson(question.mainNumber, subNumber, questions)
                         	let paperQuestion = findQuestion(question.mainNumber, subNumber, paperqQuestions)
                             // 按题号过滤
                             if (questionArr[question.mainNumber + "." + subNumber] === true || questionNumbers == "") {
@@ -83,7 +84,7 @@
                                             "italic": true,
                                             "danger": true
                                         },
-                                        "value": "(字数统计:" + jsonTextCount(question.answer) + ")"
+                                        "value": "(字数统计:" + textCount(jsons) + ")"
                                     }]
                                 };
                                 let standardTitle = {
@@ -124,17 +125,12 @@
     }
 
     
-    function textCount(jsonBody) {
-        let sections = jsonBody.sections || [];
-        let count = 0;
-        sections.forEach(section => {
-            let blocks = section.blocks || [];
-            blocks.forEach(block => {
-                if (block.type === 'text' && block.value != undefined) {
-                    count += block.value.length;
-                }
-            });
-        });
+    function textCount(jsons) {
+        jsons = Array.isArray(jsons) ? jsons : []
+        let count = 0
+        jsons.forEach(data => {
+            count += this.jsonTextCount(data.answer)
+        })
         return count;
     }
     function jsonTextCount(jsonData) {

+ 10 - 7
stmms-web/src/main/webapp/static/mark-json/js/json-view.js

@@ -44,7 +44,7 @@ JsonView.prototype.render = function () {
         this.task.markStepList.forEach(step => {
             let question = this.findQuestion(step.mainNumber, step.subNumber, this.task.paperData)
             let jsons = this.findJson(step.mainNumber, step.subNumber, this.task.jsonData)
-            if (question != undefined && jsons.length > 0) {
+            if (question != undefined ) {
                 let numberTitle = {
                     "blocks": [{
                         "type": "text",
@@ -59,6 +59,7 @@ JsonView.prototype.render = function () {
                         "value": "题干:"
                     }]
                 };
+                var textcount = jsons.length > 0? this.textCount(jsons) : 0
                 let answerTitle = {
                     "blocks": [{
                         "type": "text",
@@ -70,7 +71,7 @@ JsonView.prototype.render = function () {
                             "italic": true,
                             "danger": true
                         },
-                        "value": "(字数统计:" + this.textCount(jsons) + ")"
+                        "value": "(字数统计:" + textcount + ")"
                     }]
                 };
                 let standardTitle = {
@@ -87,11 +88,13 @@ JsonView.prototype.render = function () {
                 }
                 $(renderRichText(question.body)).appendTo(this.holder);
                 $(renderSection(answerTitle)).appendTo(this.holder);
-                jsons.forEach(node => {
-                	node.answer.forEach(node => {
-                        $(renderRichText(node)).appendTo(this.holder);
-                    });
-                })
+                if(jsons.length > 0){
+                	jsons.forEach(node => {
+                		node.answer.forEach(node => {
+                			$(renderRichText(node)).appendTo(this.holder);
+                		});
+                	})
+                }
                 $(renderSection(standardTitle)).appendTo(this.holder);
                 let nodes =renderRichText(question.answer);
                 nodes.forEach(node => {