Преглед на файлове

答题项目pc版完工v1.1

李志伟 преди 3 години
родител
ревизия
dd95393e88
променени са 4 файла, в които са добавени 55 реда и са изтрити 3 реда
  1. 1
    0
      package.json
  2. 8
    0
      src/api/question.js
  3. 34
    3
      src/components/Question/index.vue
  4. 12
    0
      yarn.lock

+ 1
- 0
package.json Целия файл

@@ -28,6 +28,7 @@
28 28
     "vue-axios": "^3.4.0",
29 29
     "vue-axios-plugin": "^1.3.0",
30 30
     "vue-router": "3.0.6",
31
+    "vuedraggable": "^2.24.3",
31 32
     "vuex": "3.1.0"
32 33
   },
33 34
   "devDependencies": {

+ 8
- 0
src/api/question.js Целия файл

@@ -45,3 +45,11 @@ export const getQuestionDetail = (id, params) => request({
45 45
   url: `/admin/question/${id}`, params
46 46
 })
47 47
 
48
+/**
49
+ * 更新游戏题目顺序
50
+ * @param {*} data
51
+ * @returns
52
+ */
53
+export const UpdateQuestionSort = (data, id) => request({
54
+  url: `/admin/game/${id}/sort`, method: 'put', data
55
+})

+ 34
- 3
src/components/Question/index.vue Целия файл

@@ -11,7 +11,7 @@
11 11
           @click="handleAdd"
12 12
         >添加题目</el-button>
13 13
       </div>
14
-      <ul style="list-style-type: none;margin:24px 0 0 -40px">
14
+      <!-- <ul style="list-style-type: none;margin:24px 0 0 -40px">
15 15
         <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
16 16
           <span style="width:45px">第{{ index+1 }}题</span>
17 17
           <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
@@ -26,7 +26,25 @@
26 26
             <el-button slot="reference" type="text" style="color:red">删除</el-button>
27 27
           </el-popconfirm>
28 28
         </li>
29
-      </ul>
29
+      </ul> -->
30
+      <draggable v-model="tableData" chosen-class="chosen" force-fallback="true" group="people" animation="1000" @end="onEnd">
31
+        <transition-group>
32
+          <div v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
33
+            <span style="width:45px">第{{ index+1 }}题</span>
34
+            <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
35
+            <span style="flex:1">{{ item.title }}</span>
36
+            <el-popconfirm
37
+              style="width:30px"
38
+              icon="el-icon-info"
39
+              icon-color="red"
40
+              title="确定删除这个问题吗?"
41
+              @onConfirm="handleDelete(item)"
42
+            >
43
+              <el-button slot="reference" type="text" style="color:red">删除</el-button>
44
+            </el-popconfirm>
45
+          </div>
46
+        </transition-group>
47
+      </draggable>
30 48
       <el-pagination
31 49
         v-show="questionTotal!==0"
32 50
         style="float:right; margin:24px 0"
@@ -41,10 +59,15 @@
41 59
   </div>
42 60
 </template>
43 61
 <script>
44
-import { getQuestionList } from '@/api/question'
62
+import { getQuestionList, UpdateQuestionSort } from '@/api/question'
45 63
 import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
64
+import draggable from 'vuedraggable'
46 65
 
47 66
 export default {
67
+  // 注册draggable组件
68
+  components: {
69
+    draggable
70
+  },
48 71
   props: {
49 72
     gameId: {
50 73
       type: String,
@@ -72,6 +95,14 @@ export default {
72 95
     }
73 96
   },
74 97
   methods: {
98
+    // 拖拽结束事件
99
+    onEnd() {
100
+      const sortList = []
101
+      this.tableData.map((item, index) => {
102
+        sortList.push({ sortNo: index, serialNo: item.gameQuestionMapId })
103
+      })
104
+      UpdateQuestionSort(sortList, this.gameId)
105
+    },
75 106
     handleSizeChange(val) {
76 107
       this.pageSize = val
77 108
       this.changePagination()

+ 12
- 0
yarn.lock Целия файл

@@ -9927,6 +9927,11 @@ sort-keys@^1.0.0:
9927 9927
   dependencies:
9928 9928
     is-plain-obj "^1.0.0"
9929 9929
 
9930
+sortablejs@1.10.2:
9931
+  version "1.10.2"
9932
+  resolved "https://registry.npmmirror.com/sortablejs/download/sortablejs-1.10.2.tgz#6e40364d913f98b85a14f6678f92b5c1221f5290"
9933
+  integrity sha512-YkPGufevysvfwn5rfdlGyrGjt7/CRHwvRPogD/lC+TnvcN29jDpCifKP+rBqf+LRldfXSTh+0CGLcSg0VIxq3A==
9934
+
9930 9935
 source-list-map@^2.0.0:
9931 9936
   version "2.0.1"
9932 9937
   resolved "https://registry.npmmirror.com/source-list-map/download/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
@@ -11181,6 +11186,13 @@ vue@2.6.10:
11181 11186
   resolved "https://registry.npmmirror.com/vue/download/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
11182 11187
   integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==
11183 11188
 
11189
+vuedraggable@^2.24.3:
11190
+  version "2.24.3"
11191
+  resolved "https://registry.npmmirror.com/vuedraggable/download/vuedraggable-2.24.3.tgz#43c93849b746a24ce503e123d5b259c701ba0d19"
11192
+  integrity sha512-6/HDXi92GzB+Hcs9fC6PAAozK1RLt1ewPTLjK0anTYguXLAeySDmcnqE8IC0xa7shvSzRjQXq3/+dsZ7ETGF3g==
11193
+  dependencies:
11194
+    sortablejs "1.10.2"
11195
+
11184 11196
 vuex@3.1.0:
11185 11197
   version "3.1.0"
11186 11198
   resolved "https://registry.npmmirror.com/vuex/download/vuex-3.1.0.tgz#634b81515cf0cfe976bd1ffe9601755e51f843b9"