Bladeren bron

游戏模块v1.8

李志伟 3 jaren geleden
bovenliggende
commit
9276fd502c

+ 2
- 2
src/api/answer.js Bestand weergeven

@@ -41,6 +41,6 @@ export const UpdateAnswer = (data, id) => request({
41 41
  * @param {*} params
42 42
  * @returns
43 43
  */
44
-export const getAnswerDetail = (id) => request({
45
-  url: `/admin/answer/${id}`
44
+export const getAnswerDetail = (id, params) => request({
45
+  url: `/admin/answer/${id}`, params
46 46
 })

+ 38
- 0
src/api/gamelevelquestion.js Bestand weergeven

@@ -0,0 +1,38 @@
1
+import request from '@/utils/request'
2
+
3
+/**
4
+ * 删除关联
5
+ * @param {*} data
6
+ * @returns
7
+ */
8
+export const deleteGameLeverQuestion = (id) => request({
9
+  url: `/admin/game-level-question/${id}`, method: 'delete'
10
+})
11
+/**
12
+ * 更新测试游戏问题的分数
13
+ * @param {*} data
14
+ * @returns
15
+ */
16
+export const UpdateGameLeverQuestion = (data, id) => request({
17
+  url: `/admin/game-level-question/${id}`, method: 'put', data
18
+})
19
+
20
+/**
21
+* 添加关联游戏和题库的接口
22
+* @param {*} data
23
+* @returns
24
+*/
25
+export const saveGameLeverQuestion = (data) => request({
26
+  url: '/admin/game-level-question',
27
+  method: 'post',
28
+  data
29
+})
30
+
31
+/**
32
+ * 查询关联详情
33
+ * @param {*} params
34
+ * @returns
35
+ */
36
+export const getGameLeverQuestionDetail = (id, params) => request({
37
+  url: `/admin/game-level-question/${id}`, params
38
+})

+ 3
- 2
src/api/question.js Bestand weergeven

@@ -41,6 +41,7 @@ export const UpdateQuestion = (data, id) => request({
41 41
  * @param {*} params
42 42
  * @returns
43 43
  */
44
-export const getQuestionDetail = (id) => request({
45
-  url: `/admin/question/${id}`
44
+export const getQuestionDetail = (id, params) => request({
45
+  url: `/admin/question/${id}`, params
46 46
 })
47
+

+ 10
- 7
src/components/Question/drawer.vue Bestand weergeven

@@ -24,7 +24,7 @@
24 24
               </el-select>
25 25
             </el-input>
26 26
           </el-form-item>
27
-          <el-form-item v-if="resultMode === 'character_matched'" label="匹配特征:" :label-width="formLabelWidth">
27
+          <el-form-item label="匹配特征:" :label-width="formLabelWidth">
28 28
             <el-select
29 29
               v-model="form.characterList"
30 30
               multiple
@@ -57,8 +57,7 @@ export default {
57 57
     dialog: Boolean,
58 58
     questionId: String,
59 59
     answerId: String,
60
-    gameId: String,
61
-    resultMode: String
60
+    gameId: String
62 61
   },
63 62
   data() {
64 63
     return {
@@ -109,7 +108,7 @@ export default {
109 108
   watch: {
110 109
     answerId() {
111 110
       if (this.answerId) {
112
-        getAnswerDetail(this.answerId).then((res) => {
111
+        getAnswerDetail(this.answerId, { gameId: this.gameId }).then((res) => {
113 112
           this.form = res.data
114 113
           if (res.data.characterList) {
115 114
             const list = []
@@ -135,7 +134,6 @@ export default {
135 134
               })
136 135
               data.characterList = list
137 136
             }
138
-            data.questionId = this.questionId
139 137
             switch (data.option) {
140 138
               case 'A':data.sortNo = 1; break
141 139
               case 'B':data.sortNo = 2; break
@@ -143,8 +141,12 @@ export default {
143 141
               case 'D':data.sortNo = 4; break
144 142
               case 'E':data.sortNo = 5; break
145 143
               case 'F':data.sortNo = 6; break
146
-              case '对':data.sortNo = 1; break
147
-              case '错':data.sortNo = 2; break
144
+              case 'G':data.sortNo = 7; break
145
+              case 'H':data.sortNo = 8; break
146
+              case 'I':data.sortNo = 9; break
147
+              case 'J':data.sortNo = 10; break
148
+              case 'true':data.sortNo = 1; break
149
+              case 'false':data.sortNo = 2; break
148 150
               default:break
149 151
             }
150 152
             if (this.answerId) {
@@ -158,6 +160,7 @@ export default {
158 160
                 }
159 161
               })
160 162
             } else {
163
+              data.questionId = this.questionId
161 164
               saveAnswer(data).then((res) => {
162 165
                 this.$message('添加成功')
163 166
                 this.$emit('handleEditDrawer', true)

+ 103
- 59
src/components/Question/edit.vue Bestand weergeven

@@ -1,22 +1,45 @@
1 1
 <template>
2 2
   <div style="padding: 20px">
3 3
     <h2 style="text-align: center">
4
-      游戏题目{{ questionId ? "编辑" : "添加" }}
4
+      游戏题目{{ gameQuestionMapId!==0 ? "编辑" : "添加" }}
5 5
     </h2>
6
-    <el-form ref="form" :rules="rules" :model="form" label-width="90px">
7
-      <el-form-item label="题目:" prop="title">
8
-        <el-input v-model="form.title" placeholder="请输入实例名(必填)">
6
+    <el-form ref="form" :model="form" label-width="90px">
7
+      <el-form-item label="题目:">
8
+        <el-input v-if="resultMode === 'character_matched'" v-model="form.title" placeholder="请输入实例名(必填)">
9 9
           <el-select slot="prepend" v-model="form.optType" style="width:100px" placeholder="请选择">
10 10
             <el-option label="单选题" value="single" />
11 11
             <el-option label="多选题" value="many" />
12 12
             <el-option label="判断题" value="judgment" />
13 13
           </el-select>
14 14
         </el-input>
15
+        <el-select
16
+          v-else
17
+          v-model="nowQuestionId"
18
+          filterable
19
+          default-first-option
20
+          style="width:100%"
21
+          placeholder="请选择"
22
+          :disabled="gameQuestionMapId!==0"
23
+        >
24
+          <el-option
25
+            v-for="item in questionList"
26
+            :key="item.questionId"
27
+            :label="item.title"
28
+            :value="item.questionId"
29
+          />
30
+        </el-select>
15 31
       </el-form-item>
16
-      <el-form-item v-if="questionId!==undefined && resultMode === 'examination'" label="正确选项:">
32
+      <el-form-item v-if="resultMode==='examination'" label="分数">
33
+        <el-input v-model="form.score" type="number" min="1" max="50" />
34
+      </el-form-item>
35
+      <el-form-item
36
+        v-if="gameQuestionMapId!==0 && resultMode === 'examination'"
37
+        label="正确选项:"
38
+      >
17 39
         <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
18 40
         <el-select
19 41
           v-model="form.rightAnswer"
42
+          disabled
20 43
           style="width:100%"
21 44
           multiple
22 45
           filterable
@@ -32,14 +55,15 @@
32 55
         </el-select>
33 56
       </el-form-item>
34 57
       <el-form-item>
35
-        <el-button type="primary" @click="onSubmit('form')">确定</el-button>
58
+        <el-button type="primary" @click="onSubmit">确定</el-button>
36 59
         <el-button @click="$router.go(-1)">返回</el-button>
37 60
       </el-form-item>
38 61
     </el-form>
39
-    <el-card v-if="questionId!==undefined" shadow="never" body-style="padding:0" class="box-card">
62
+    <el-card v-if="gameQuestionMapId!==0" shadow="never" body-style="padding:0" class="box-card">
40 63
       <div slot="header" class="clearfix">
41 64
         <h3 style="float:left">答案列表</h3>
42 65
         <el-button
66
+          v-if=" resultMode !== 'examination'"
43 67
           type="primary"
44 68
           style="float: right"
45 69
           icon="el-icon-plus"
@@ -48,11 +72,12 @@
48 72
       </div>
49 73
       <ul style="list-style-type: none;margin:24px 0 24px -40px">
50 74
         <li v-for="answer in answerList" :key="answer.answerId" class="answerli">
51
-          <div style="flex:1;width: 100%;overflow: hidden;display: flex;" @click="handleEdit(answer)">
75
+          <div style="flex:1;width: 100%;overflow: hidden;display: flex;" @click="resultMode === 'examination'?'':handleEdit(answer)">
52 76
             <span style="width:45px">{{ answer.option }}</span>
53 77
             <span style="flex:1">{{ answer.content }}</span>
54 78
           </div>
55 79
           <el-popconfirm
80
+            v-if="resultMode !== 'examination'"
56 81
             style="width:30px"
57 82
             icon="el-icon-info"
58 83
             icon-color="red"
@@ -66,10 +91,9 @@
66 91
     </el-card>
67 92
     <QuestionDrawer
68 93
       :dialog="dialog"
69
-      :question-id="questionId"
94
+      :question-id="form.questionId"
70 95
       :answer-id="answerId"
71 96
       :game-id="gameId"
72
-      :result-mode="resultMode"
73 97
       @handleCloseDrawer="handleCloseDrawer"
74 98
       @handleEditDrawer="handleEditDrawer"
75 99
     />
@@ -77,8 +101,9 @@
77 101
 </template>
78 102
 <script>
79 103
 
80
-import { saveQuestion, UpdateQuestion, getQuestionDetail } from '@/api/question'
104
+import { getQuestionList } from '@/api/question'
81 105
 import { getAnswerList, deleteAnswer } from '@/api/answer'
106
+import { saveGameLeverQuestion, UpdateGameLeverQuestion, getGameLeverQuestionDetail } from '@/api/gamelevelquestion'
82 107
 import QuestionDrawer from '@/components/Question/drawer.vue'
83 108
 
84 109
 export default {
@@ -86,22 +111,29 @@ export default {
86 111
     QuestionDrawer
87 112
   },
88 113
   props: {
89
-    gameId: String,
90
-    questionId: String,
114
+    gameQuestionMapId: {
115
+      type: Number,
116
+      required: true
117
+    },
118
+    gameId: {
119
+      type: String,
120
+      required: true
121
+    },
91 122
     resultMode: String
92 123
   },
93 124
   data() {
94 125
     return {
95
-      rules: {
96
-        title: [{ required: true, message: '请输入游戏名称', trigger: 'blur' }]
97
-      },
98 126
       form: {
99 127
         title: undefined,
100 128
         optType: undefined,
101 129
         rightAnswer: undefined,
102 130
         gameId: undefined,
131
+        score: 0,
132
+        status: 1,
103 133
         questionId: undefined
104 134
       },
135
+      nowQuestionId: undefined, // 当前问题id用于获取答案列表 和匹配游戏模式传入答案编辑弹窗的questionId
136
+      questionList: [], // 用于存储测试模式下选择问题的下拉菜单的数据源
105 137
       // 答案列表(包括选项 内容 特征词列表)
106 138
       answerList: [],
107 139
       answerId: undefined,
@@ -112,37 +144,43 @@ export default {
112 144
   },
113 145
   watch: {
114 146
     // 用于点击左边改变右边的页面
115
-    questionId: function() {
116
-      if (this.questionId) {
117
-        this.rightList = []
118
-        getQuestionDetail(this.questionId).then((res) => {
147
+    gameQuestionMapId: function() {
148
+      if (this.gameQuestionMapId !== 0) {
149
+        getGameLeverQuestionDetail(this.gameQuestionMapId, { gameId: this.gameId }).then((res) => {
119 150
           this.form = res.data
120 151
           this.form.rightAnswer = res.data.rightAnswer?.split(',')
152
+          this.nowQuestionId = res.data.questionId
153
+          getAnswerList({ questionId: res.data.questionId }).then((res) => {
154
+            this.answerList = res.data.records
155
+          })
121 156
         })
122
-        this.handleAnswerList()
123 157
       } else {
124 158
         this.form = {
125 159
           title: undefined,
126 160
           optType: undefined,
161
+          score: 0,
162
+          status: 1,
127 163
           gameId: undefined,
128 164
           rightAnswer: undefined,
129 165
           questionId: undefined
130 166
         }
131
-        this.answerList = []
132
-        this.rightList = []
167
+        this.nowQuestionId = undefined
133 168
       }
134 169
     }
135 170
   },
171
+  mounted: function() {
172
+    getQuestionList({ pageSize: 999 }).then((res) => { this.questionList = res.data.records })
173
+  },
136 174
   methods: {
137 175
     // 添加答案
138 176
     onAddAnswer() {
139
-      this.dialog = true
140 177
       this.answerId = undefined
178
+      this.dialog = true
141 179
     },
142 180
     // 编辑答案
143 181
     handleEdit(val) {
144
-      this.dialog = true
145 182
       this.answerId = val.answerId
183
+      this.dialog = true
146 184
     },
147 185
     // 删除答案
148 186
     handleDelete(val) {
@@ -154,7 +192,6 @@ export default {
154 192
     // 关闭答案抽屉
155 193
     handleCloseDrawer() {
156 194
       this.dialog = false
157
-      this.answerId = undefined
158 195
     },
159 196
     // 编辑答案抽屉成功重新查询列表
160 197
     handleEditDrawer(val) {
@@ -163,14 +200,8 @@ export default {
163 200
     },
164 201
     // 查询当前问题答案列表
165 202
     handleAnswerList() {
166
-      getAnswerList({ questionId: this.questionId }).then((res) => {
203
+      getAnswerList({ questionId: this.nowQuestionId }).then((res) => {
167 204
         this.answerList = res.data.records
168
-        // 给正确答按下拉菜单数据源赋值
169
-        const list = []
170
-        this.answerList.map(item => {
171
-          list.push(item.option)
172
-        })
173
-        this.rightList = list
174 205
       })
175 206
     },
176 207
     // 转换特征数组数据格式
@@ -181,37 +212,50 @@ export default {
181 212
       })
182 213
       return nameList.toString()
183 214
     },
184
-    onSubmit(form) {
185
-      this.$refs[form].validate((valid) => {
186
-        if (valid) {
187
-          if (this.form.optType) {
188
-            const data = { ...this.form }
189
-            data.gameId = this.gameId
190
-            data.status = 1
191
-            if (this.questionId) {
192
-              if (data.rightAnswer) {
193
-                data.rightAnswer = data.rightAnswer.toString()
194
-              }
195
-              UpdateQuestion(data, this.questionId).then((res) => {
196
-                this.$message('修改问题成功')
197
-                // 告诉父页面问题表需要刷新并且关闭当前组件
198
-                this.$emit('handleRefreshQuestion', true)
199
-              })
200
-            } else {
201
-              saveQuestion(data).then((res) => {
202
-                this.$message('添加问题成功')
203
-                // 告诉父页面问题表需要刷新并且关闭当前组件
204
-                this.$emit('handleRefreshQuestion', true)
205
-                this.$emit('handleEditQuestion', res.data.questionId)
206
-              })
207
-            }
215
+    // 非空判断方法
216
+    handelNull() {
217
+      if (this.resultMode === 'examination') {
218
+        if (this.nowQuestionId) {
219
+          if (this.form.score && this.form.score !== 0) {
220
+            return true
208 221
           } else {
209
-            this.$message('请选择题型')
222
+            this.$message('请输入本题分数')
223
+            return false
210 224
           }
211 225
         } else {
226
+          this.$message('请选择题目')
212 227
           return false
213 228
         }
214
-      })
229
+      } else {
230
+        if (this.form.optType) {
231
+          if (this.form.title) {
232
+            return true
233
+          } else {
234
+            this.$message('请输入题目')
235
+            return false
236
+          }
237
+        } else {
238
+          this.$message('请选择题型')
239
+          return false
240
+        }
241
+      }
242
+    },
243
+    onSubmit() {
244
+      if (this.handelNull()) {
245
+        const data = { ...this.form }
246
+        if (this.gameQuestionMapId === 0) {
247
+          saveGameLeverQuestion({ ...data, gameId: this.gameId, questionId: this.nowQuestionId }).then((res) => {
248
+            this.$message('添加问题成功')
249
+            this.$emit('handleRefreshQuestion', true)
250
+            this.$emit('handleEditQuestion', res.data.gameQuestionMapId)
251
+          })
252
+        } else {
253
+          UpdateGameLeverQuestion({ ...data, gameId: this.gameId, questionId: this.nowQuestionId }, this.gameQuestionMapId).then((res) => {
254
+            this.$message('修改问题成功')
255
+            this.$emit('handleRefreshQuestion', true)
256
+          })
257
+        }
258
+      }
215 259
     }
216 260
   }
217 261
 }

+ 19
- 8
src/components/Question/index.vue Bestand weergeven

@@ -3,6 +3,7 @@
3 3
     <el-card class="box-card" shadow="never" body-style="padding:0">
4 4
       <div slot="header" class="clearfix">
5 5
         <h3 style="float:left">题库列表</h3>
6
+        <h4 v-if="resultMode==='examination'" style="float:left;margin-left: 10px;">总分{{ totalScore }}</h4>
6 7
         <el-button
7 8
           type="primary"
8 9
           style="float: right"
@@ -40,24 +41,30 @@
40 41
   </div>
41 42
 </template>
42 43
 <script>
43
-import { getQuestionList, deleteQuestion } from '@/api/question'
44
+import { getQuestionList } from '@/api/question'
45
+import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
44 46
 
45 47
 export default {
46 48
   props: {
47
-    gameId: String
49
+    gameId: {
50
+      type: String,
51
+      required: true
52
+    },
53
+    resultMode: String
48 54
   },
49 55
   data() {
50 56
     return {
51 57
       tableData: [],
52 58
       pageSize: 20,
53 59
       currentPage: 1,
54
-      questionTotal: 0// 条目总数
60
+      questionTotal: 0, // 条目总数
61
+      totalScore: 0
55 62
     }
56 63
   },
57 64
   watch: {
58 65
     gameId: {
59 66
       handler(val) {
60
-        if (this.gameId) {
67
+        if (val) {
61 68
           this.onSearch()
62 69
         }
63 70
       },
@@ -85,11 +92,11 @@ export default {
85 92
       this.$emit('handleAddQuestion', true)
86 93
     },
87 94
     handleEdit(row) {
88
-      // 向外传送数据row.questionId
89
-      this.$emit('handleEditQuestion', row.questionId)
95
+      // 向外传送数据row.gameQuestionMapId
96
+      this.$emit('handleEditQuestion', row.gameQuestionMapId)
90 97
     },
91 98
     handleDelete(row) {
92
-      deleteQuestion(row.questionId).then(() => {
99
+      deleteGameLeverQuestion(row.gameQuestionMapId).then(() => {
93 100
         this.$message('删除问题成功')
94 101
         this.onSearch()
95 102
         // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
@@ -97,11 +104,15 @@ export default {
97 104
       })
98 105
     },
99 106
     onSearch() {
100
-      getQuestionList({ gameId: this.gameId, endDate: this.endDate, pageSize: this.pageSize }).then(
107
+      getQuestionList({ gameId: this.gameId, pageSize: this.pageSize }).then(
101 108
         (res) => {
102 109
           this.tableData = res.data.records
103 110
           this.questionTotal = res.data.total
104 111
           this.pageSize = res.data.size
112
+          this.totalScore = 0
113
+          res.data.records.map(item => {
114
+            this.totalScore += item.score
115
+          })
105 116
         }
106 117
       )
107 118
     }

+ 1
- 0
src/icons/svg/question.svg Bestand weergeven

@@ -0,0 +1 @@
1
+<svg t="1641808834314" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3156" width="128" height="128"><path d="M687.510353 284.53208a58.008527 58.008527 0 0 1-58.622915-56.933347V35.90948a15.615711 15.615711 0 0 1 9.72782-13.823745 15.257318 15.257318 0 0 1 16.434896 3.27674l240.686747 233.877273a14.847725 14.847725 0 0 1 3.174341 16.383697 14.540531 14.540531 0 0 1-13.874943 8.908635h-197.525946z m0 56.933347h203.516235a29.74665 29.74665 0 0 1 21.350005 8.447844 30.565835 30.565835 0 0 1 9.21583 21.298806v538.818831a117.245831 117.245831 0 0 1-35.17375 81.560092 113.917893 113.917893 0 0 1-81.713688 32.357801H219.295015a113.764295 113.764295 0 0 1-81.713688-32.357801A117.245831 117.245831 0 0 1 102.407577 910.030908V113.988035A117.245831 117.245831 0 0 1 137.581327 32.427944 113.764295 113.764295 0 0 1 219.295015 0.070143h319.789284a31.231422 31.231422 0 0 1 31.538616 30.719431v196.809159c1.382374 64.152413 53.656607 115.095471 116.887438 113.866694m-409.592422 511.939329h468.164138a29.029863 29.029863 0 0 0 29.337058-28.466673 29.081062 29.081062 0 0 0-29.337058-28.517873H277.917931a29.081062 29.081062 0 0 0-29.337058 28.517873 29.029863 29.029863 0 0 0 29.337058 28.466673z m0-170.851239h468.164138a28.313076 28.313076 0 0 0 20.479622-8.038252 29.234659 29.234659 0 0 0 8.857436-20.428422 28.722669 28.722669 0 0 0-29.337058-28.159479H277.917931a28.722669 28.722669 0 0 0-29.337058 28.159479 29.439455 29.439455 0 0 0 8.806237 20.428422 28.517872 28.517872 0 0 0 20.530821 8.038252z m0-170.544045h292.704984a29.029863 29.029863 0 0 0 29.285859-28.466674 28.978664 28.978664 0 0 0-29.285859-28.466673H277.917931a28.978664 28.978664 0 0 0-29.337058 28.466673 29.029863 29.029863 0 0 0 29.337058 28.466674z" p-id="3157"></path></svg>

+ 21
- 0
src/router/index.js Bestand weergeven

@@ -43,6 +43,27 @@ export const constantRoutes = [
43 43
     }]
44 44
   },
45 45
 
46
+  {
47
+    path: '/question',
48
+    component: Layout,
49
+    meta: { title: '测试题库管理', icon: 'form' },
50
+    children: [
51
+      {
52
+        path: 'question',
53
+        name: '题库列表',
54
+        component: () => import('@/views/question/index'),
55
+        meta: { title: '测试题库列表', icon: 'question' }
56
+      },
57
+      {
58
+        hidden: true,
59
+        path: 'question/deit',
60
+        name: 'questionEdit',
61
+        component: () => import('@/views/question/edit'),
62
+        meta: { title: '题目编辑', icon: 'question' }
63
+      }
64
+    ]
65
+  },
66
+
46 67
   {
47 68
     path: '/gameManage',
48 69
     component: Layout,

+ 6
- 7
src/views/gameManage/edit.vue Bestand weergeven

@@ -1,6 +1,5 @@
1 1
 <template>
2 2
   <div class="body_edit">
3
-    <!-- <h3 style="width:100%; margin:auto">游戏{{ gameId ? "编辑" : "新增" }}</h3> -->
4 3
     <el-tabs v-model="activeName">
5 4
       <el-tab-pane label="游戏详情" name="game">
6 5
         <el-form ref="form" :rules="rules" class="gameForm" :model="gameForm" label-width="100px">
@@ -64,15 +63,15 @@
64 63
             <Question
65 64
               ref="Question"
66 65
               :gameId="gameId"
67
-              @handleAddQuestion="questionId = undefined"
68
-              @handleCloseQuestion="questionId = undefined"
66
+              :resultMode="gameForm.resultMode"
67
+              @handleAddQuestion="gameQuestionMapId = 0"
68
+              @handleCloseQuestion="gameQuestionMapId = 0"
69 69
               @handleEditQuestion="handleEditQuestion"
70 70
             />
71 71
           </el-col>
72 72
           <el-col :span="12">
73 73
             <QuestionEdit
74
-              ref="QuestionEdit"
75
-              :questionId="questionId"
74
+              :gameQuestionMapId="gameQuestionMapId"
76 75
               :gameId="gameId"
77 76
               :resultMode="gameForm.resultMode"
78 77
               @handleRefreshQuestion="handleRefreshQuestion"
@@ -125,7 +124,7 @@ export default {
125 124
       ],
126 125
       gameId: undefined,
127 126
       activeName: 'game',
128
-      questionId: undefined,
127
+      gameQuestionMapId: 0,
129 128
       characterId: undefined
130 129
     }
131 130
   },
@@ -189,7 +188,7 @@ export default {
189 188
       this.$refs.GameCharacter.onSearch()
190 189
     },
191 190
     handleEditQuestion(val) {
192
-      this.questionId = val
191
+      this.gameQuestionMapId = val
193 192
     },
194 193
     handleRefreshQuestion() {
195 194
       this.$refs.Question.onSearch()

+ 0
- 1
src/views/gameManage/index.vue Bestand weergeven

@@ -70,7 +70,6 @@ import { getGameList, deleteGame } from '@/api/game'
70 70
 export default {
71 71
   data() {
72 72
     return {
73
-      characterId: undefined,
74 73
       title: undefined,
75 74
       daterange: undefined,
76 75
       tableData: [],

+ 153
- 0
src/views/question/drawer.vue Bestand weergeven

@@ -0,0 +1,153 @@
1
+<template>
2
+  <div>
3
+    <el-drawer
4
+      ref="drawer"
5
+      :show-close="false"
6
+      :wrapperClosable="false"
7
+      :title="answerId ?'编辑答案' : '添加答案'"
8
+      :before-close="handleClose"
9
+      :visible.sync="dialog"
10
+      direction="ltr"
11
+      custom-class="demo-drawer"
12
+    >
13
+      <div class="demo-drawer__content">
14
+        <el-form ref="form" :model="form" :rules="rules" style="margin:20px">
15
+          <el-form-item label="答案:" prop="content" :label-width="formLabelWidth">
16
+            <el-input v-model="form.content" placeholder="请输入答案(必填)">
17
+              <el-select slot="prepend" v-model="form.option" filterable allow-create default-first-option style="width:100px" placeholder="请选择">
18
+                <el-option
19
+                  v-for="item in options"
20
+                  :key="item.value"
21
+                  :label="item.label"
22
+                  :value="item.value"
23
+                />
24
+              </el-select>
25
+            </el-input>
26
+          </el-form-item>
27
+          <el-form-item style="text-align:center">
28
+            <el-button @click="handleClose">取 消</el-button>
29
+            <el-button type="primary" @click="onSubmit('form')">确 定</el-button>
30
+          </el-form-item>
31
+        </el-form>
32
+      </div>
33
+    </el-drawer>
34
+  </div>
35
+</template>
36
+<script>
37
+import { getAnswerDetail, saveAnswer, UpdateAnswer } from '@/api/answer'
38
+export default {
39
+  props: {
40
+    dialog: Boolean,
41
+    questionId: String,
42
+    answerId: String
43
+  },
44
+  data() {
45
+    return {
46
+      rules: {
47
+        content: [{ required: true, message: '请输入答案内容', trigger: 'blur' }]
48
+      },
49
+      form: {
50
+        option: undefined,
51
+        content: undefined,
52
+        sortNo: 1,
53
+        status: 1
54
+      },
55
+      formLabelWidth: '120px',
56
+      options: [
57
+        {
58
+          value: 'A',
59
+          label: 'A'
60
+        },
61
+        {
62
+          value: 'B',
63
+          label: 'B'
64
+        },
65
+        {
66
+          value: 'C',
67
+          label: 'C'
68
+        },
69
+        {
70
+          value: 'D',
71
+          label: 'D'
72
+        },
73
+        {
74
+          value: 'true',
75
+          label: '对'
76
+        },
77
+        {
78
+          value: 'false',
79
+          label: '错'
80
+        }
81
+      ]
82
+    }
83
+  },
84
+  watch: {
85
+    answerId() {
86
+      if (this.answerId) {
87
+        getAnswerDetail(this.answerId).then((res) => {
88
+          this.form = res.data
89
+        })
90
+      }
91
+    }
92
+  },
93
+  methods: {
94
+    onSubmit(form) {
95
+      this.$refs[form].validate((valid) => {
96
+        if (valid) {
97
+          if (this.form.option) {
98
+            const data = { ...this.form }
99
+            switch (data.option) {
100
+              case 'A':data.sortNo = 1; break
101
+              case 'B':data.sortNo = 2; break
102
+              case 'C':data.sortNo = 3; break
103
+              case 'D':data.sortNo = 4; break
104
+              case 'E':data.sortNo = 5; break
105
+              case 'F':data.sortNo = 6; break
106
+              case 'G':data.sortNo = 7; break
107
+              case 'H':data.sortNo = 8; break
108
+              case 'I':data.sortNo = 9; break
109
+              case 'J':data.sortNo = 10; break
110
+              case 'true':data.sortNo = 1; break
111
+              case 'false':data.sortNo = 2; break
112
+              default:break
113
+            }
114
+            if (this.answerId) {
115
+              UpdateAnswer(data, this.answerId).then((res) => {
116
+                this.$message('修改成功')
117
+                this.$emit('handleEditDrawer', true)
118
+                this.form = {
119
+                  option: undefined,
120
+                  content: undefined
121
+                }
122
+              })
123
+            } else {
124
+              data.questionId = this.questionId
125
+              saveAnswer(data).then((res) => {
126
+                this.$message('添加成功')
127
+                this.$emit('handleEditDrawer', true)
128
+                this.form = {
129
+                  option: undefined,
130
+                  content: undefined
131
+                }
132
+              })
133
+            }
134
+          } else {
135
+            this.$message('请在灰色下拉菜单中添加选项')
136
+          }
137
+        } else {
138
+          return false
139
+        }
140
+      })
141
+    },
142
+    handleClose() {
143
+      this.$emit('handleCloseDrawer', true)
144
+      this.form = {
145
+        option: undefined,
146
+        content: undefined
147
+      }
148
+    }
149
+  }
150
+}
151
+</script>
152
+<style>
153
+</style>

+ 209
- 0
src/views/question/edit.vue Bestand weergeven

@@ -0,0 +1,209 @@
1
+<template>
2
+  <div class="body_edit">
3
+    <h2 style="text-align: center">
4
+      游戏题目{{ questionId ? "编辑" : "添加" }}
5
+    </h2>
6
+    <el-form ref="form" :rules="rules" :model="form" label-width="90px">
7
+      <el-form-item label="题目:" prop="title">
8
+        <el-input v-model="form.title" placeholder="请输入实例名(必填)">
9
+          <el-select slot="prepend" v-model="form.optType" style="width:100px" placeholder="请选择">
10
+            <el-option label="单选题" value="single" />
11
+            <el-option label="多选题" value="many" />
12
+            <el-option label="判断题" value="judgment" />
13
+          </el-select>
14
+        </el-input>
15
+      </el-form-item>
16
+      <el-form-item v-if="questionId!==undefined" label="正确选项:">
17
+        <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
18
+        <el-select
19
+          v-model="form.rightAnswer"
20
+          style="width:100%"
21
+          multiple
22
+          filterable
23
+          default-first-option
24
+          placeholder="请选择"
25
+        >
26
+          <el-option
27
+            v-for="item in rightList"
28
+            :key="item"
29
+            :label="item"
30
+            :value="item"
31
+          />
32
+        </el-select>
33
+      </el-form-item>
34
+      <el-form-item>
35
+        <el-button type="primary" @click="onSubmit('form')">确定</el-button>
36
+        <el-button @click="$router.go(-1)">返回</el-button>
37
+      </el-form-item>
38
+    </el-form>
39
+    <el-card v-if="questionId!==undefined" shadow="never" body-style="padding:0" class="box-card">
40
+      <div slot="header" class="clearfix">
41
+        <h3 style="float:left">答案列表</h3>
42
+        <el-button
43
+          type="primary"
44
+          style="float: right"
45
+          icon="el-icon-plus"
46
+          @click="onAddAnswer"
47
+        >添加答案</el-button>
48
+      </div>
49
+      <ul style="list-style-type: none;margin:24px 0 24px -40px">
50
+        <li v-for="answer in answerList" :key="answer.answerId" class="answerli">
51
+          <div style="flex:1;width: 100%;overflow: hidden;display: flex;" @click="handleEdit(answer)">
52
+            <span style="width:45px">{{ answer.option }}</span>
53
+            <span style="flex:1">{{ answer.content }}</span>
54
+          </div>
55
+          <el-popconfirm
56
+            style="width:30px"
57
+            icon="el-icon-info"
58
+            icon-color="red"
59
+            title="确定删除这个答案吗?"
60
+            @onConfirm="handleDelete(answer)"
61
+          >
62
+            <el-button slot="reference" type="text" class="deleteQuestion" style="color:red">删除</el-button>
63
+          </el-popconfirm>
64
+        </li>
65
+      </ul>
66
+    </el-card>
67
+    <QuestionDrawer
68
+      :dialog="dialog"
69
+      :question-id="questionId"
70
+      :answer-id="answerId"
71
+      @handleCloseDrawer="handleCloseDrawer"
72
+      @handleEditDrawer="handleEditDrawer"
73
+    />
74
+  </div>
75
+</template>
76
+<script>
77
+
78
+import { saveQuestion, UpdateQuestion, getQuestionDetail } from '@/api/question'
79
+import { getAnswerList, deleteAnswer } from '@/api/answer'
80
+import QuestionDrawer from '@/views/question/drawer.vue'
81
+
82
+export default {
83
+  components: {
84
+    QuestionDrawer
85
+  },
86
+  data() {
87
+    return {
88
+      questionId: undefined,
89
+      rules: {
90
+        title: [{ required: true, message: '请输入游戏名称', trigger: 'blur' }]
91
+      },
92
+      form: {
93
+        title: undefined,
94
+        optType: undefined,
95
+        rightAnswer: undefined,
96
+        questionId: undefined
97
+      },
98
+      // 答案列表(包括选项 内容 特征词列表)
99
+      answerList: [],
100
+      answerId: undefined,
101
+      // 正确答案数据源
102
+      rightList: [],
103
+      dialog: false
104
+    }
105
+  },
106
+  watch: {
107
+    '$route.query.id': {
108
+      handler(val) {
109
+        if (val) {
110
+          this.questionId = val
111
+          getQuestionDetail(this.questionId).then((res) => {
112
+            this.form = res.data
113
+            this.form.rightAnswer = res.data.rightAnswer?.split(',')
114
+          })
115
+          this.handleAnswerList()
116
+        }
117
+      },
118
+      immediate: true // 页面加载时就启动
119
+    }
120
+  },
121
+  methods: {
122
+    // 添加答案
123
+    onAddAnswer() {
124
+      this.answerId = undefined
125
+      this.dialog = true
126
+    },
127
+    // 编辑答案
128
+    handleEdit(val) {
129
+      this.answerId = val.answerId
130
+      this.dialog = true
131
+    },
132
+    // 删除答案
133
+    handleDelete(val) {
134
+      deleteAnswer(val.answerId).then((res) => {
135
+        this.$message('删除答案成功')
136
+        this.handleAnswerList()
137
+      })
138
+    },
139
+    // 关闭答案抽屉
140
+    handleCloseDrawer() {
141
+      this.dialog = false
142
+    },
143
+    // 编辑答案抽屉成功重新查询列表
144
+    handleEditDrawer(val) {
145
+      this.handleCloseDrawer()
146
+      this.handleAnswerList()
147
+    },
148
+    // 查询当前问题答案列表
149
+    handleAnswerList() {
150
+      getAnswerList({ questionId: this.questionId }).then((res) => {
151
+        this.answerList = res.data.records
152
+        // 给正确答按下拉菜单数据源赋值
153
+        const list = []
154
+        this.answerList.map(item => {
155
+          list.push(item.option)
156
+        })
157
+        this.rightList = list
158
+      })
159
+    },
160
+    onSubmit(form) {
161
+      this.$refs[form].validate((valid) => {
162
+        if (valid) {
163
+          if (this.form.optType) {
164
+            const data = { ...this.form }
165
+            data.status = 1
166
+            if (this.questionId) {
167
+              if (data.rightAnswer) {
168
+                data.rightAnswer = data.rightAnswer.sort().toString()
169
+              }
170
+              UpdateQuestion(data, this.questionId).then((res) => {
171
+                this.$message('修改问题成功')
172
+              })
173
+            } else {
174
+              saveQuestion(data).then((res) => {
175
+                this.$message('添加问题成功')
176
+                this.$router.replace({
177
+                  name: 'questionEdit',
178
+                  query: { id: res.data.questionId }
179
+                })
180
+              })
181
+            }
182
+          } else {
183
+            this.$message('请选择题型')
184
+          }
185
+        } else {
186
+          return false
187
+        }
188
+      })
189
+    }
190
+  }
191
+}
192
+</script>
193
+<style scoped lang="scss">
194
+.answerli {
195
+  width: 100%;
196
+  overflow: hidden;
197
+  display: flex;
198
+  line-height:40px;
199
+  background-color: white;
200
+  padding:0 8px;
201
+  border: 1px solid #f0f2f5;
202
+}
203
+.answerli:hover {
204
+  background-color: rgb(230, 247, 255);
205
+}
206
+.answerli:nth-of-type(even) {
207
+  background: #f0f2f5;
208
+}
209
+</style>

+ 118
- 0
src/views/question/index.vue Bestand weergeven

@@ -0,0 +1,118 @@
1
+<template>
2
+  <div class="body" style="font-size:14px">
3
+    <el-card class="box-card" shadow="never">
4
+      题库名称:
5
+      <el-input v-model="title" style="width: 200px; margin-right: 20px" />
6
+      <div style="float:right">
7
+        <el-button type="primary" @click="onSearch">查询</el-button>
8
+        <el-button @click="onReset">重置</el-button>
9
+        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">添加题目</el-button>
10
+      </div>
11
+    </el-card>
12
+    <el-table stripe :data="tableData" border style="width: 100%">
13
+      <el-table-column prop="title" label="题目名称" />
14
+      <el-table-column prop="createDate" label="创建时间">
15
+        <template slot-scope="scope">
16
+          {{
17
+            scope.row.createDate.substr(0, 10)
18
+          }}
19
+        </template>
20
+      </el-table-column>
21
+      <el-table-column fixed="right" label="操作">
22
+        <template slot-scope="scope">
23
+          <el-link :underline="false" style="margin-right:1em" type="primary">
24
+            <router-link
25
+              :to="{name: 'questionEdit', query: { id: scope.row.questionId }}"
26
+            >编辑</router-link>
27
+          </el-link>
28
+          <el-popconfirm
29
+            icon="el-icon-info"
30
+            icon-color="red"
31
+            title="确定删除这个问题吗?"
32
+            @onConfirm="handleDelete(scope.row)"
33
+          >
34
+            <el-button slot="reference" type="text" style="color:red">删除</el-button>
35
+          </el-popconfirm>
36
+        </template>
37
+      </el-table-column>
38
+    </el-table>
39
+    <el-pagination
40
+      v-show="gameTotal!==0"
41
+      style="float:right; margin:20px 0"
42
+      :total="gameTotal"
43
+      :current-page="currentPage"
44
+      :page-sizes="[4, 10, 20, 50]"
45
+      :page-size="pageSize"
46
+      layout="total, prev, pager, next, sizes"
47
+      @size-change="handleSizeChange"
48
+      @current-change="handleCurrentChange"
49
+    />
50
+  </div>
51
+</template>
52
+<script>
53
+import { getQuestionList, deleteQuestion } from '@/api/question'
54
+
55
+export default {
56
+  data() {
57
+    return {
58
+      title: undefined,
59
+      tableData: [],
60
+      //
61
+      pageSize: 10,
62
+      currentPage: 1,
63
+      gameTotal: 0 // 条目总数
64
+    }
65
+  },
66
+  mounted() {
67
+    this.onSearch()
68
+  },
69
+  methods: {
70
+    // 改变每页显示条数
71
+    handleSizeChange(val) {
72
+      this.pageSize = val
73
+      this.changePagination()
74
+    },
75
+    // 改变页码
76
+    handleCurrentChange(val) {
77
+      this.currentPage = val
78
+      this.changePagination()
79
+    },
80
+    // 改变分页组件重新查询数据
81
+    changePagination() {
82
+      getQuestionList({
83
+        title: this.title,
84
+        pageNum: this.currentPage,
85
+        pageSize: this.pageSize
86
+      }).then((res) => {
87
+        this.tableData = res.data.records
88
+      })
89
+    },
90
+    handleAdd() {
91
+      this.$router.push({ name: 'questionEdit' })
92
+    },
93
+    handleDelete(row) {
94
+      deleteQuestion(row.questionId).then(() => {
95
+        this.onSearch()
96
+      })
97
+    },
98
+    onSearch() {
99
+      getQuestionList({
100
+        title: this.title,
101
+        pageSize: this.pageSize
102
+      }).then((res) => {
103
+        this.tableData = res.data.records
104
+        this.gameTotal = res.data.total
105
+        this.pageSize = res.data.size
106
+      })
107
+    },
108
+    onReset() {
109
+      this.title = undefined
110
+      this.currentPage = 1
111
+      this.pageSize = 10
112
+      this.onSearch()
113
+    }
114
+  }
115
+}
116
+</script>
117
+<style>
118
+</style>