李志伟 3 years ago
parent
commit
18632627f7

+ 4
- 0
src/components/GameCharacter/edit.vue View File

@@ -59,6 +59,9 @@ export default {
59 59
           characterId: undefined
60 60
         }
61 61
       }
62
+      if (this.gameId) {
63
+        this.form.gameId = this.gameId
64
+      }
62 65
     },
63 66
     gameId: function() {
64 67
       if (this.gameId) {
@@ -84,6 +87,7 @@ export default {
84 87
             this.$message('添加实例成功')
85 88
             // 告诉父页面实例表需要刷新
86 89
             this.$emit('handleRefreshGameCharacter', true)
90
+            // 把当前页改为编辑页面
87 91
             this.$emit('handleEditGameCharacter', res.data.characterId)
88 92
           })
89 93
         }

+ 6
- 0
src/components/GameCharacter/index.vue View File

@@ -73,6 +73,12 @@ export default {
73 73
         gameId: this.gameId
74 74
       }).then((res) => {
75 75
         this.tableData = res.data.records
76
+        // 讲特征列表写入store 供问题答案特征下拉使用
77
+        const list = []
78
+        this.tableData.map(item => {
79
+          list.push({ characterId: item.characterId, name: item.name })
80
+        })
81
+        this.$store.dispatch('game/setWordListValue', list).then(() => {})
76 82
       })
77 83
     },
78 84
     dateChange(val) {

+ 6
- 4
src/components/Question/drawer.vue View File

@@ -58,7 +58,6 @@
58 58
 <script>
59 59
 export default {
60 60
   props: {
61
-    wordList: Array,
62 61
     dialog: Boolean
63 62
   },
64 63
   data() {
@@ -97,13 +96,16 @@ export default {
97 96
       ]
98 97
     }
99 98
   },
99
+  computed: {
100
+    wordList() {
101
+      return this.$store.state.game.wordList
102
+    }
103
+  },
100 104
   methods: {
101 105
     handleClose(done) {
102 106
       this.$confirm('确定要添加这条答案吗?')
103 107
         .then(_ => {
104
-          const list = this.wordList.filter(item => {
105
-            this.form.characterList.some(v => v === item.characterId)
106
-          })
108
+          const list = this.wordList.filter(item => this.form.characterList.includes(item.characterId))
107 109
           this.form.characterList = list
108 110
           this.$emit('handleEditDrawer', this.form)
109 111
           this.form = {

+ 51
- 67
src/components/Question/edit.vue View File

@@ -22,31 +22,37 @@
22 22
         <el-button type="primary" @click="onAddAnswer">添加答案</el-button>
23 23
 
24 24
         <div v-for="(answer, index) in form.answerList" :key="index">
25
-          <!-- <AddAnswerMatching
26
-            :characterId="characterId"
27
-            :value="answer"
28
-            :wordList="wordList"
29
-            @change="handleChange"
30
-            @handleDelete="() => handleDelete(answer)"
31
-            @handleWordListChange="handleWordListChange"
32
-          /> -->
25
+          <el-row :gutter="20" style="padding-top: 20px">
26
+            <el-col :span="1">
27
+              {{ answer.option }}
28
+            </el-col>
29
+            <el-col :span="10">{{ answer.content }}</el-col>
30
+          </el-row>
31
+          <el-row :gutter="20">
32
+            <el-col :span="20">
33
+              {{ handleToString(answer.characterList) }}
34
+            </el-col>
35
+            <el-col :span="1">
36
+              <el-button type="danger" @click="()=>handleDelete(index)">X</el-button>
37
+            </el-col>
38
+          </el-row>
33 39
         </div>
34 40
       </el-form-item>
35 41
       <el-form-item label="正确选项:">
36 42
         <!-- <el-input v-model="form.option"></el-input> -->
37 43
         <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
38 44
         <el-select
39
-          v-model="rightList"
45
+          v-model="form.rightAnswer"
40 46
           multiple
41 47
           filterable
42 48
           default-first-option
43 49
           placeholder="请选择"
44 50
         >
45 51
           <el-option
46
-            v-for="item in form.answerList"
47
-            :key="item.option"
48
-            :label="item.option"
49
-            :value="item.option"
52
+            v-for="item in rightList"
53
+            :key="item"
54
+            :label="item"
55
+            :value="item"
50 56
           />
51 57
         </el-select>
52 58
       </el-form-item>
@@ -55,26 +61,20 @@
55 61
         <el-button @click="$router.go(-1)">返回</el-button>
56 62
       </el-form-item>
57 63
     </el-form>
58
-    <QuestionDrawer :dialog="dialog" :wordList='wordList' @handleCloseDrawer='handleCloseDrawer' @handleEditDrawer='handleEditDrawer' />
64
+    <QuestionDrawer :dialog="dialog" @handleCloseDrawer="handleCloseDrawer" @handleEditDrawer="handleEditDrawer" />
59 65
   </div>
60 66
 </template>
61 67
 <script>
62 68
 
63 69
 import { saveQuestion, updateQuestion, getQuestionDetail } from '@/api/question'
64
-import { getGameCharacterList } from '@/api/gameCharacter'
65 70
 import QuestionDrawer from '@/components/Question/drawer.vue'
66 71
 
67
-// import AddAnswerMatching from '@/components/AddAnswerMatching/index.vue'
68
-// import { getCharacterLibDetail } from '@/api/characterLib'
69
-
70 72
 export default {
71 73
   components: {
72 74
     QuestionDrawer
73
-    // AddAnswerMatching
74 75
   },
75 76
   props: {
76 77
     gameId: String,
77
-    // characterId: String,
78 78
     questionId: String
79 79
   },
80 80
   data() {
@@ -88,11 +88,10 @@ export default {
88 88
         // 答案列表(包括选项 内容 特征词列表)
89 89
         answerList: []
90 90
       },
91
-      // 正确答案数
91
+      // 正确答案数据源
92 92
       rightList: [],
93
-      // 特征数据源
94
-      wordList: [],
95
-      dialog: false
93
+      dialog: false,
94
+      isChange: 0
96 95
     }
97 96
   },
98 97
   watch: {
@@ -102,10 +101,7 @@ export default {
102 101
         this.rightList = []
103 102
         getQuestionDetail(this.questionId).then((res) => {
104 103
           this.form = res.data
105
-          const list = res.data.answerList
106
-          list.map((item) => {
107
-            this.rightList.push(item.wordId)
108
-          })
104
+          this.form.rightAnswer = res.data.rightAnswer.split(',')
109 105
         })
110 106
       } else {
111 107
         this.form = {
@@ -118,40 +114,49 @@ export default {
118 114
         }
119 115
         this.rightList = []
120 116
       }
117
+      if (this.gameId) {
118
+        this.form.gameId = this.gameId
119
+      }
121 120
     },
122 121
     gameId() {
123
-      this.form.gameId = this.gameId
124
-      getGameCharacterList({ gameId: this.gameId }).then((res) => {
125
-        res.data.records.map(item => {
126
-          this.wordList.push({ characterId: item.characterId, name: item.name })
127
-        })
128
-        console.log(this.wordList)
122
+      if (this.gameId) {
123
+        this.form.gameId = this.gameId
124
+      }
125
+    },
126
+    isChange() {
127
+      const list = []
128
+      this.form.answerList.map(item => {
129
+        list.push(item.option)
129 130
       })
131
+      this.rightList = list
130 132
     }
131 133
   },
132 134
   methods: {
133 135
     onAddAnswer() {
134 136
       this.dialog = true
135
-      // this.form.answerList.push({
136
-      //   answerId: undefined,
137
-      //   questionId: undefined,
138
-      //   contentType: undefined,
139
-      //   option: undefined,
140
-      //   content: undefined,
141
-      //   characterWordList: [],
142
-      //   word: undefined,
143
-      //   wordId: undefined
144
-      // })
145 137
     },
146 138
     handleCloseDrawer() {
147 139
       this.dialog = false
148 140
     },
149 141
     handleEditDrawer(val) {
150
-      console.log(val)
142
+      this.isChange++
143
+      this.form.answerList.push(val)
151 144
       this.handleCloseDrawer()
152 145
     },
146
+    handleDelete(index) {
147
+      this.isChange--
148
+      this.form.answerList.splice(index, 1)
149
+    },
150
+    handleToString(list) {
151
+      const nameList = []
152
+      list?.map(item => {
153
+        nameList.push(item.name)
154
+      })
155
+      return nameList.toString()
156
+    },
153 157
     onSubmit() {
154
-      if (this.form.name) {
158
+      if (this.form.title) {
159
+        this.form.rightAnswer = this.form.rightAnswer.toString()
155 160
         if (this.questionId) {
156 161
           updateQuestion(this.form, this.questionId).then((res) => {
157 162
             this.$message('修改问题成功')
@@ -170,27 +175,6 @@ export default {
170 175
         this.$message('请输入问题名称')
171 176
       }
172 177
     }
173
-    // handleChange(answer) {
174
-    //   const index = this.form.answerList.indexOf(answer)
175
-    //   this.$set(this.form.answerList, index, answer)
176
-    // },
177
-
178
-    // handleWordListChange(val, list) {
179
-    //   getCharacterLibDetail(this.characterId).then((res) => {
180
-    //     this.wordList = res.data.wordList
181
-    //   })
182
-    //   const index = this.form.answerList.indexOf(val)
183
-    //   val.characterWordList = this.wordList.filter((item) =>
184
-    //     list.some((v) => v === item.wordId)
185
-    //   )
186
-    //   val.characterWordList.map(item => {
187
-    //     item = { ...item, characterId: this.characterId }
188
-    //   })
189
-    //   this.$set(this.form.answerList, index, val)
190
-    // },
191
-    // handleDelete(answer) {
192
-    //   this.form.answerList.splice(this.form.answerList.indexOf(answer), 1)
193
-    // }
194 178
   }
195 179
 }
196 180
 </script>

+ 3
- 3
src/main.js View File

@@ -4,7 +4,7 @@ import 'normalize.css/normalize.css' // A modern alternative to CSS resets
4 4
 
5 5
 import ElementUI from 'element-ui'
6 6
 import 'element-ui/lib/theme-chalk/index.css'
7
-import locale from 'element-ui/lib/locale/lang/en' // lang i18n
7
+// import locale from 'element-ui/lib/locale/lang/en' // lang i18n
8 8
 
9 9
 import '@/styles/index.scss' // global css
10 10
 
@@ -25,7 +25,7 @@ import '@/permission' // permission control
25 25
  */
26 26
 // if (process.env.NODE_ENV === 'production') {
27 27
 //   const { mockXHR } = require('../mock')
28
-  // mockXHR()
28
+// mockXHR()
29 29
 // }
30 30
 
31 31
 // set ElementUI lang to EN
@@ -35,7 +35,7 @@ Vue.use(ElementUI)
35 35
 
36 36
 Vue.config.productionTip = false
37 37
 
38
-new Vue({  
38
+new Vue({
39 39
   el: '#app',
40 40
   router,
41 41
   store,

+ 3
- 1
src/store/index.js View File

@@ -4,6 +4,7 @@ import getters from './getters'
4 4
 import app from './modules/app'
5 5
 import settings from './modules/settings'
6 6
 import user from './modules/user'
7
+import game from './modules/game'
7 8
 
8 9
 Vue.use(Vuex)
9 10
 
@@ -11,7 +12,8 @@ const store = new Vuex.Store({
11 12
   modules: {
12 13
     app,
13 14
     settings,
14
-    user
15
+    user,
16
+    game
15 17
   },
16 18
   getters
17 19
 })

+ 1
- 1
src/store/modules/app.js View File

@@ -8,7 +8,7 @@ const state = {
8 8
   device: 'desktop'
9 9
 }
10 10
 
11
-//定义Mutations
11
+// 定义Mutations
12 12
 const mutations = {
13 13
   TOGGLE_SIDEBAR: state => {
14 14
     state.sidebar.opened = !state.sidebar.opened

+ 30
- 0
src/store/modules/game.js View File

@@ -0,0 +1,30 @@
1
+const state = {
2
+  wordList: []// 设置初始特征列表
3
+}
4
+
5
+const getters = {
6
+  getwordList(state) {
7
+    return state.wordList // 返回当前特征列表
8
+  }
9
+}
10
+
11
+// 定义Mutations
12
+const mutations = {
13
+  setWordList(state, val) {
14
+    state.wordList = val // 改变当前特征列表
15
+  }
16
+}
17
+
18
+const actions = {
19
+  setWordListValue({ commit, state }, val) {
20
+    commit('setWordList', val)// 调用mutations方法
21
+  }
22
+}
23
+
24
+export default {
25
+  namespaced: true,
26
+  state,
27
+  getters,
28
+  mutations,
29
+  actions
30
+}

+ 1
- 2
src/views/gameManage/edit.vue View File

@@ -68,7 +68,7 @@
68 68
             />
69 69
           </el-col>
70 70
           <el-col :span="11">
71
-            <QuestionEdit :questionId='questionId' :gameId='gameId' @handleRefreshQuestion='handleRefreshQuestion' @handleEditQuestion='handleEditQuestion' />
71
+            <QuestionEdit ref="QuestionEdit" :questionId='questionId' :gameId='gameId' @handleRefreshQuestion='handleRefreshQuestion' @handleEditQuestion='handleEditQuestion' />
72 72
           </el-col>
73 73
         </el-row>
74 74
       </el-tab-pane>
@@ -171,7 +171,6 @@ export default {
171 171
     handleRefreshGameCharacter() {
172 172
       this.$refs.GameCharacter.onSearch()
173 173
     },
174
-
175 174
     handleEditQuestion(val) {
176 175
       this.questionId = val
177 176
     },