sxd 6 lat temu
rodzic
commit
fb156c7c5d
4 zmienionych plików z 38 dodań i 23 usunięć
  1. 18 0
      src/js/box/yzComponents.js
  2. 5 7
      src/js/main2.js
  3. 7 6
      src/js/yzQuestion.js
  4. 8 10
      src/js/yzToolbar.js

+ 18 - 0
src/js/box/yzComponents.js

@@ -0,0 +1,18 @@
+import boxContent from './boxContent';
+let yzComponent = function (cfg) {
+  this.parentDom = cfg.content;
+  this.boxes = [];
+};
+
+yzComponent.prototype.addComponent = function () {
+  let box = new boxContent();
+  box.renderToDom();
+  this.parentDom.append(box.vdom);
+  this.boxes.push(box);
+};
+
+yzComponent.prototype.renderDom = function() {
+    console.log(123);
+};
+
+ export default yzComponent;

+ 5 - 7
src/js/main2.js

@@ -200,8 +200,6 @@ pageManager.prototype._mergeData = function () {
       // 计数器
       i++;
     }
-   
-
 
   }
   return mergeArr;
@@ -310,8 +308,9 @@ pageManager.prototype.renderToDom = function () {
     this.refreshToolBar('none');
   });
   this.refreshToolBar();
-  $('body').on('getQuestion', (e,pageNum,domId) => {
-    this.refreshToolBar(...[pageNum,domId]);
+  // 这个触发事件是获取所操作的小题号并且动态改变
+  $('body').on('getQuestion', (e,pageNum,content) => {
+    this.refreshToolBar(...[pageNum,content]);
   });
   console.log(pages);
 };
@@ -335,7 +334,6 @@ pageManager.prototype._refreshPage = function () {
         rectNo: doms[j].rectNo,
         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);
@@ -361,10 +359,10 @@ pageManager.prototype._refreshPage = function () {
 /*
 * function 刷新顶部菜单栏
 */
-pageManager.prototype.refreshToolBar = function(pNum = null,id) {
+pageManager.prototype.refreshToolBar = function(pNum = null, content) {
   // 如果有参数说明要编辑题目
   if(pNum){
-    this.toolBar.setSubjectTitle(pNum,id);
+    this.toolBar.setSubjectTitle(pNum, content);
     $('#toolbar').remove();
   }
   this.domBody.append(this.toolBar.toolbarContent());

+ 7 - 6
src/js/yzQuestion.js

@@ -1,5 +1,5 @@
 import $ from 'jquery'
-import boxContent from './box/boxContent';
+import components from './box/yzComponents';
 
 let yzQuestion = function (cfg) {
   // content里面是box组件
@@ -58,17 +58,18 @@ yzQuestion.prototype._renderObjectiveDom = function () {
 yzQuestion.prototype._renderCommonDom = function () {
   let content = $('<div id="'+ this.domId +'_content" class="question-selection-content"></div>');
   content.css({height: (this.minHeight - 20) + 'px'});
-  let contentItem = this.content;
-  if (contentItem) {
-    contentItem.forEach( (item) => {
-      this.contentDom.push(new boxContent(item));
+  if (this.content) {
+    this.content.renderDom();
+  } else {
+    this.content = new components({
+      content: content
     });
   }
   this.vdom.append(content);
   // 冒泡监听事件
   this.vdom.on('click', ()=>{
     // 将题目和domId冒泡到顶层
-    this.vdom.trigger('getQuestion',[this.pNum,this.domId]);
+    this.vdom.trigger('getQuestion',[this.pNum,this.content]);
   });
 };
 

+ 8 - 10
src/js/yzToolbar.js

@@ -29,11 +29,10 @@ var yzToolbar = function(){
     icon: 'fa-list-alt'
   }];
 
-
   // 问题编号
   this.subjectNum = null;
-  // 需要插入组件的id
-  this.sujectDomId = null;
+  // 获取当前需要插入的Dom
+  this.currentContent = null;
 
 };
 
@@ -52,7 +51,7 @@ yzToolbar.prototype.toolbarContent = function () {
     ulDom.appendChild(liDom);
     if( item.name == 'component' ){
       liDom.addEventListener('click', () => {
-        this.addComponent();
+        this.addComponent(liDom);
       },!0);
     }
   });
@@ -62,9 +61,9 @@ yzToolbar.prototype.toolbarContent = function () {
   return toolDom;
 };
 
-yzToolbar.prototype.setSubjectTitle = function(pNum,id) {
+yzToolbar.prototype.setSubjectTitle = function(pNum,content) {
   this.subjectNum = pNum;
-  this.sujectDomId = id;
+  this.currentContent = content;
   this.menu.forEach( (item) => {
     if( item.name == 'subject' ){
       item.title = '正在编辑' + pNum;
@@ -75,13 +74,12 @@ yzToolbar.prototype.setSubjectTitle = function(pNum,id) {
   });
 };
 
-yzToolbar.prototype.addComponent = function() {
+yzToolbar.prototype.addComponent = function(dom) {
   if(this.subjectNum == 'none' || !this.subjectNum){
     alert('请选择主观题');return;
   }
-  let box = new boxContent();
-  box.renderToDom();
-  $('#' + this.sujectDomId + '_content').append(box.vdom);
+  console.log(this.currentContent);
+  this.currentContent.addComponent(1);
 };
 
 export default yzToolbar;