lsiten il y a 6 ans
Parent
commit
afe570698c
3 fichiers modifiés avec 50 ajouts et 43 suppressions
  1. 38 40
      src/js/main2.js
  2. 7 1
      src/js/yzDom.js
  3. 5 2
      src/js/yzQuestion.js

+ 38 - 40
src/js/main2.js

@@ -146,7 +146,8 @@ pageManager.prototype._mergeData = function () {
     rectNo: -1,
     isSubject: true,
     cdelete: 0,
-    minHeight: -1
+    minHeight: -1,
+    content: null
   };
   for (let index in data) {
     item = data[index];
@@ -225,62 +226,57 @@ pageManager.prototype._itemToPage = function (item) {
   let domOption = JSON.parse(JSON.stringify(item));
   if ( item.height >  this.currentPage.gap) {
     let gap = this.currentPage.gap;
-    if (gap > this.minHeight) {
+    if (gap > 0) {
         let holdHeight = gap;
-        // item中减去已经放进页面的高度,继续递归
-        // 循环item的questions,看看能容纳几个question,出去已经容纳的question
+        //1、 cHoldQuestions 当前页可以容纳的小题数组
+        //2、 questionsTemp 当前页容纳不了的小题数组
         let cHoldQuestions = [];
-        let tempCanHolderItem = {};
         let questionsTemp = [];
+
+        // 下一页的高度
+        let nextBoxHeight = 0;
         item.questions.filter(domItem => {
-          
           gap -= domItem.minHeight;
           if (gap >= 0) {
             cHoldQuestions.push(domItem);
-            return false;
           } else {
-            gap = Math.abs(gap);
-            tempCanHolderItem = JSON.parse(JSON.stringify(domItem))
-            domItem.minHeight = gap;
-            tempCanHolderItem.minHeight -= gap;
-            // 如果该页剩余小于最小高度,则跳到下一页
-            if (tempCanHolderItem.minHeight >= this.minHeight) {
-              cHoldQuestions.push(tempCanHolderItem);
-            }
-            // 如果该小问在下一页高度小于最小高度,则舍去
-            if (domItem.minHeight >= this.minHeight) {
-              questionsTemp.push(domItem);
-              return true;
-            } else {  
-              return false;
-            }
+            // 如果该页容纳不了该小问,则该小问在下一页显示
+            nextBoxHeight += domItem.minHeight;
+            questionsTemp.push(domItem);
           }
         })
         item.questions = questionsTemp;
-        item.height -= holdHeight;
-        
         domOption.height = holdHeight;
         domOption.questions = cHoldQuestions;
-        if (item.height > this.minHeight) {
-          domOption.isDrag = false;
-        } else {
-          domOption.isDrag = true;
+        if (domOption.questions.length > 0) {
+          item.height -= domOption.height;
+          item.height < nextBoxHeight && (item.height = nextBoxHeight);
+          this.currentPage.addDom(domOption);
         }
-        // 如果有最小高度,则说明是刷新状态
-        if(item.minHeight) {
-          item.minHeight -= domOption.height;
-          item.minHeight = item.minHeight <= 0 ? 0 : item.minHeight;
-        }
-        this.currentPage.addDom(domOption);
-        this.currentPage.gap = 0;
-        this.currentPage = null;
-        if (item.height > this.minHeight) {
+        if(item.questions.length > 0 ) {
+          if (item.height > this.minHeight) {
+            domOption.isDrag = false;
+          } else {
+            domOption.isDrag = true;
+          }
           // 如果有最小高度,则说明是刷新状态
           if(item.minHeight) {
-            item.minHeight <= 0 && (item.cdelete = 1);
+            item.minHeight -= domOption.height;
+            item.minHeight = item.minHeight <= 0 ? 0 : item.minHeight;
+          }
+          this.currentPage.gap = 0;
+          this.currentPage = null;
+          if (item.height > this.minHeight) {
+            // 如果有最小高度,则说明是刷新状态
+            if(item.minHeight) {
+              item.minHeight <= 0 && (item.cdelete = 1);
+            }
+            this._itemToPage(item);
           }
-          this._itemToPage(item);
+        } else {
+          domOption.isDrag = true;
         }
+        
     } else {
       this.currentPage.gap = 0;
       this.currentPage = null;
@@ -339,7 +335,9 @@ pageManager.prototype._refreshPage = function () {
         isSubject: doms[j].isSubject,
         questions: doms[j].questions,
         rectNo: doms[j].rectNo,
-        minHeight: doms[j].minHeight
+        minHeight: doms[j].minHeight,
+        content: doms[j].content
+
       };
       if(parseInt(item.rectNo) === nowRectNo) {
         data[(length-1)].questions.push.apply(data[(length-1)].questions, item.questions);

+ 7 - 1
src/js/yzDom.js

@@ -12,7 +12,11 @@ var yzDom = function(cfg) {
   this.isDrag = cfg.isDrag;
   this.rowDetail = cfg.rowDetail;
   this.isSubject = cfg.isSubject;
+  this.content = cfg.content || null;
   this.questionsDom = [];
+
+ // 该dom第几个question 
+  this.questionIndex = 0;
   
   this.vDom = null;
   this.colDoms = {};
@@ -24,6 +28,9 @@ var yzDom = function(cfg) {
 yzDom.prototype._initQustionsDoms = function () {
   let questions = this.questions;
   for (let index in questions) {
+    this.questionIndex++;
+
+    questions[index].order = this.questionIndex;
     this.questionsDom.push(new yzQuestion(questions[index]));
   }
 }
@@ -87,7 +94,6 @@ yzDom.prototype._renderCommonDom = function () {
 yzDom.prototype.renderToDom = function () {
   this.vDom = $('<div id="' +this.domId+ '" class="border-selection"></div>');
  
-
   !this.isSubject ? this._renderObjectiveDom() : this._renderCommonDom();
 
   let cssOption = {height: this.height};

+ 5 - 2
src/js/yzQuestion.js

@@ -17,6 +17,9 @@ let yzQuestion = function (cfg) {
   this.blockindex = parseInt(cfg.blockindex);
   this.blocknum = parseInt(cfg.blocknum);
 
+
+  this.order = parseInt(cfg.order);
+
   this.domId = ('lsiten_question_'+Math.random()).replace('.','_');
   // dom相关属性
   this.vdom = null;
@@ -96,8 +99,8 @@ yzQuestion.prototype._renderTitleDom = function () {
 yzQuestion.prototype.renderToDom = function () {
   this.vdom = $('<div id="'+ this.domId +'" class="question-selection"></div>');
   this.vdom.css({
-    height: this.minHeight
-  });
+    minHeight: this.minHeight
+  })
   this._renderTitleDom();
   // 如果是客观题
   if (!this.isSubject) {