Browse Source

答题项目pc版完工v1.1

李志伟 3 years ago
parent
commit
dd95393e88
4 changed files with 55 additions and 3 deletions
  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 View File

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

+ 8
- 0
src/api/question.js View File

45
   url: `/admin/question/${id}`, params
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 View File

11
           @click="handleAdd"
11
           @click="handleAdd"
12
         >添加题目</el-button>
12
         >添加题目</el-button>
13
       </div>
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
         <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
15
         <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
16
           <span style="width:45px">第{{ index+1 }}题</span>
16
           <span style="width:45px">第{{ index+1 }}题</span>
17
           <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
17
           <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
26
             <el-button slot="reference" type="text" style="color:red">删除</el-button>
26
             <el-button slot="reference" type="text" style="color:red">删除</el-button>
27
           </el-popconfirm>
27
           </el-popconfirm>
28
         </li>
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
       <el-pagination
48
       <el-pagination
31
         v-show="questionTotal!==0"
49
         v-show="questionTotal!==0"
32
         style="float:right; margin:24px 0"
50
         style="float:right; margin:24px 0"
41
   </div>
59
   </div>
42
 </template>
60
 </template>
43
 <script>
61
 <script>
44
-import { getQuestionList } from '@/api/question'
62
+import { getQuestionList, UpdateQuestionSort } from '@/api/question'
45
 import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
63
 import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
64
+import draggable from 'vuedraggable'
46
 
65
 
47
 export default {
66
 export default {
67
+  // 注册draggable组件
68
+  components: {
69
+    draggable
70
+  },
48
   props: {
71
   props: {
49
     gameId: {
72
     gameId: {
50
       type: String,
73
       type: String,
72
     }
95
     }
73
   },
96
   },
74
   methods: {
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
     handleSizeChange(val) {
106
     handleSizeChange(val) {
76
       this.pageSize = val
107
       this.pageSize = val
77
       this.changePagination()
108
       this.changePagination()

+ 12
- 0
yarn.lock View File

9927
   dependencies:
9927
   dependencies:
9928
     is-plain-obj "^1.0.0"
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
 source-list-map@^2.0.0:
9935
 source-list-map@^2.0.0:
9931
   version "2.0.1"
9936
   version "2.0.1"
9932
   resolved "https://registry.npmmirror.com/source-list-map/download/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
9937
   resolved "https://registry.npmmirror.com/source-list-map/download/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
11181
   resolved "https://registry.npmmirror.com/vue/download/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
11186
   resolved "https://registry.npmmirror.com/vue/download/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
11182
   integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==
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
 vuex@3.1.0:
11196
 vuex@3.1.0:
11185
   version "3.1.0"
11197
   version "3.1.0"
11186
   resolved "https://registry.npmmirror.com/vuex/download/vuex-3.1.0.tgz#634b81515cf0cfe976bd1ffe9601755e51f843b9"
11198
   resolved "https://registry.npmmirror.com/vuex/download/vuex-3.1.0.tgz#634b81515cf0cfe976bd1ffe9601755e51f843b9"