浏览代码

调整题目顺序

dusenyao 1 年之前
父节点
当前提交
9e194fcb4e
共有 2 个文件被更改,包括 39 次插入7 次删除
  1. 7 0
      src/api/exercise.js
  2. 32 7
      src/views/exercise_questions/create/index.vue

+ 7 - 0
src/api/exercise.js

@@ -260,3 +260,10 @@ export function DeleteMyShareEditExercise(data) {
 export function StopShareRecord(data) {
 export function StopShareRecord(data) {
   return http.post(`/TeachingServer/ExerciseManager/StopShareRecord`, data);
   return http.post(`/TeachingServer/ExerciseManager/StopShareRecord`, data);
 }
 }
+
+/**
+ * 移动题目
+ */
+export function MoveQuestion(data) {
+  return http.post(`/TeachingServer/ExerciseManager/MoveQuestion`, data);
+}

+ 32 - 7
src/views/exercise_questions/create/index.vue

@@ -14,13 +14,17 @@
       </div>
       </div>
       <div class="exercise-list">
       <div class="exercise-list">
         <ul>
         <ul>
-          <li v-for="(item, i) in index_list" :key="i" :class="['exercise-item', { active: i === curIndex }]">
-            <SvgIcon icon-class="child" :size="20" />
-            <span class="item-name nowrap-ellipsis" @click="selectExerciseItem(i)">
-              {{ i + 1 }}. {{ exerciseNames[item.type] }}
-            </span>
-            <SvgIcon icon-class="copy" class="pointer" :size="10" @click="copy(i)" />
-          </li>
+          <draggable v-model="index_list" animation="300" @end="onEnd">
+            <transition-group>
+              <li v-for="(item, i) in index_list" :key="i" :class="['exercise-item', { active: i === curIndex }]">
+                <SvgIcon icon-class="child" :size="20" />
+                <span class="item-name nowrap-ellipsis" @click="selectExerciseItem(i)">
+                  {{ i + 1 }}. {{ exerciseNames[item.type] }}
+                </span>
+                <SvgIcon icon-class="copy" class="pointer" :size="10" @click="copy(i)" />
+              </li>
+            </transition-group>
+          </draggable>
         </ul>
         </ul>
       </div>
       </div>
       <div class="list-operate">
       <div class="list-operate">
@@ -74,17 +78,20 @@ import {
   GetQuestionInfo,
   GetQuestionInfo,
   GetExerciseInfo,
   GetExerciseInfo,
   UpdateExercise,
   UpdateExercise,
+  MoveQuestion,
 } from '@/api/exercise';
 } from '@/api/exercise';
 
 
 import CreateMain from './components/create.vue';
 import CreateMain from './components/create.vue';
 import PreviewQuestionTypeMixin from '../data/PreviewQuestionTypeMixin';
 import PreviewQuestionTypeMixin from '../data/PreviewQuestionTypeMixin';
 import SelectQuestionType from './components/common/SelectQuestionType.vue';
 import SelectQuestionType from './components/common/SelectQuestionType.vue';
+import draggable from 'vuedraggable';
 
 
 export default {
 export default {
   name: 'CreateExercise',
   name: 'CreateExercise',
   components: {
   components: {
     CreateMain,
     CreateMain,
     SelectQuestionType,
     SelectQuestionType,
+    draggable,
   },
   },
   mixins: [PreviewQuestionTypeMixin],
   mixins: [PreviewQuestionTypeMixin],
   provide() {
   provide() {
@@ -286,6 +293,24 @@ export default {
       let type = arr[arr.length - 1];
       let type = arr[arr.length - 1];
       this.index_list[this.curIndex].type = type;
       this.index_list[this.curIndex].type = type;
     },
     },
+    /**
+     * 移动题目
+     * @param {object} param0 移动参数
+     * @param {number} param0.newIndex 移动后的索引
+     */
+    onEnd({ newIndex }) {
+      MoveQuestion({
+        question_id: this.index_list[newIndex].id,
+        dest_question_id: this.index_list[newIndex + 1].id,
+        dest_position: 0,
+      })
+        .then(() => {
+          this.$message.success('移动成功');
+        })
+        .catch(() => {
+          this.$message.error('移动失败');
+        });
+    },
   },
   },
 };
 };
 </script>
 </script>