Browse Source

删除页面

曹冬冬 5 years ago
parent
commit
204ca9e373
2 changed files with 30 additions and 6 deletions
  1. 29 5
      src/views/h5editor/overview.vue
  2. 1 1
      src/vuex/editor/actions.js

+ 29 - 5
src/views/h5editor/overview.vue

@@ -38,6 +38,7 @@
                 :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px', transform: 'scale(' + 70 / canvasWidth +')',backgroundColor: bodyBackgroundColor }"
                 :elements="page.elements" type="see" />
             </div>
+            <span @click="deletePage(page,index)">删除</span>
           </div>
           <div class="item-page-add" @click="addPage">添加题目页</div>
         </li>
@@ -83,9 +84,8 @@
       <el-collapse-transition>
         <div v-show="showTopic">
           <div class="topic-group">
-            <el-checkbox v-for="(item, index) in questionList" :label="item.name" :key="index"
-              @change="checked=>selectCheckbox(checked,item,index)" :checked="isChecked(index)"
-              :disabled="isDisabled(index)">
+            <el-checkbox v-model="item.isChecked" v-for="(item, index) in questionList" :label="item.name"
+              :key="item.name" @change="checked=>selectCheckbox(checked,item,index)" :disabled="isDisabled(index)">
             </el-checkbox>
           </div>
         </div>
@@ -131,6 +131,9 @@ export default {
     editorApi.cncTestDetail(data).then(res => {
       if (res.success) {
         this.questionList = res.single.questionList;
+        for (var i = 0; i < this.questionList.length; i++) {
+          this.questionList[i].isChecked = this.isChecked(i);
+        }
         console.log("success", this.questionList);
       } else {
         console.log("error");
@@ -172,6 +175,7 @@ export default {
       this.selectQuestions.forEach(function(value, key, arr) {
         arrTemp.push(...value);
       });
+      console.log("isChecked", index, arrTemp.indexOf(question) != -1);
       return arrTemp.indexOf(question) != -1;
     },
     isDisabled(index) {
@@ -360,8 +364,29 @@ export default {
         "rgba(255,255,255,0)";
       this.$store.dispatch("copyPage", page);
     },
-    delPage(page) {
+    deletePage(page, index) {
+      var pageSlelctQ = this.selectQuestions[index - 1] || [];
+      var deleteList = [];
+      for (var i = 0; i < pageSlelctQ.length; i++) {
+        var question = this.questionList.filter(
+          item => item.questionId == pageSlelctQ[i]
+        );
+        if (question.length > 0) {
+          var selectIndex = this.questionList.findIndex(
+            itemTemp => itemTemp.questionId == question[0].questionId
+          );
+          this.questionList[selectIndex].isChecked = false;
+          deleteList.push({ index: selectIndex, item: question[0] });
+        }
+      }
+      for (var i = 0; i < deleteList.length; i++) {
+        console.log("WWWWWWWWW", deleteList[i]);
+        this.selectCheckbox(false, deleteList[i].item, deleteList[i].index);
+      }
+      this.questions.splice(index, 1);
       this.$store.dispatch("delPage", page);
+      var editingPage = this.pages[index - 1];
+      this.setEditingPage(editingPage, index - 1);
     },
     addPage() {
       this.bodyBackgroundColor =
@@ -413,7 +438,6 @@ export default {
       this.resultPageCount = val;
     },
     questions(val) {
-      console.log("当前页数:", val);
       this.selectQuestions = val;
     },
     currentPage(val) {

+ 1 - 1
src/vuex/editor/actions.js

@@ -138,7 +138,7 @@ export const copyPage = ({ commit }, data) => {
  * @param commit
  */
 export const delPage = ({ commit }, page) => {
-  commit(types.DELETE_PAGE, page)
+  commit(types.DELETE_PAGE, page);
 }
 
 export const getPageByThemeId = ({ dispatch, commit }, id) => {