李志伟 3 anos atrás
pai
commit
18632627f7

+ 4
- 0
src/components/GameCharacter/edit.vue Ver arquivo

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

+ 6
- 0
src/components/GameCharacter/index.vue Ver arquivo

73
         gameId: this.gameId
73
         gameId: this.gameId
74
       }).then((res) => {
74
       }).then((res) => {
75
         this.tableData = res.data.records
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
     dateChange(val) {
84
     dateChange(val) {

+ 6
- 4
src/components/Question/drawer.vue Ver arquivo

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

+ 51
- 67
src/components/Question/edit.vue Ver arquivo

22
         <el-button type="primary" @click="onAddAnswer">添加答案</el-button>
22
         <el-button type="primary" @click="onAddAnswer">添加答案</el-button>
23
 
23
 
24
         <div v-for="(answer, index) in form.answerList" :key="index">
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
         </div>
39
         </div>
34
       </el-form-item>
40
       </el-form-item>
35
       <el-form-item label="正确选项:">
41
       <el-form-item label="正确选项:">
36
         <!-- <el-input v-model="form.option"></el-input> -->
42
         <!-- <el-input v-model="form.option"></el-input> -->
37
         <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
43
         <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
38
         <el-select
44
         <el-select
39
-          v-model="rightList"
45
+          v-model="form.rightAnswer"
40
           multiple
46
           multiple
41
           filterable
47
           filterable
42
           default-first-option
48
           default-first-option
43
           placeholder="请选择"
49
           placeholder="请选择"
44
         >
50
         >
45
           <el-option
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
         </el-select>
57
         </el-select>
52
       </el-form-item>
58
       </el-form-item>
55
         <el-button @click="$router.go(-1)">返回</el-button>
61
         <el-button @click="$router.go(-1)">返回</el-button>
56
       </el-form-item>
62
       </el-form-item>
57
     </el-form>
63
     </el-form>
58
-    <QuestionDrawer :dialog="dialog" :wordList='wordList' @handleCloseDrawer='handleCloseDrawer' @handleEditDrawer='handleEditDrawer' />
64
+    <QuestionDrawer :dialog="dialog" @handleCloseDrawer="handleCloseDrawer" @handleEditDrawer="handleEditDrawer" />
59
   </div>
65
   </div>
60
 </template>
66
 </template>
61
 <script>
67
 <script>
62
 
68
 
63
 import { saveQuestion, updateQuestion, getQuestionDetail } from '@/api/question'
69
 import { saveQuestion, updateQuestion, getQuestionDetail } from '@/api/question'
64
-import { getGameCharacterList } from '@/api/gameCharacter'
65
 import QuestionDrawer from '@/components/Question/drawer.vue'
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
 export default {
72
 export default {
71
   components: {
73
   components: {
72
     QuestionDrawer
74
     QuestionDrawer
73
-    // AddAnswerMatching
74
   },
75
   },
75
   props: {
76
   props: {
76
     gameId: String,
77
     gameId: String,
77
-    // characterId: String,
78
     questionId: String
78
     questionId: String
79
   },
79
   },
80
   data() {
80
   data() {
88
         // 答案列表(包括选项 内容 特征词列表)
88
         // 答案列表(包括选项 内容 特征词列表)
89
         answerList: []
89
         answerList: []
90
       },
90
       },
91
-      // 正确答案数
91
+      // 正确答案数据源
92
       rightList: [],
92
       rightList: [],
93
-      // 特征数据源
94
-      wordList: [],
95
-      dialog: false
93
+      dialog: false,
94
+      isChange: 0
96
     }
95
     }
97
   },
96
   },
98
   watch: {
97
   watch: {
102
         this.rightList = []
101
         this.rightList = []
103
         getQuestionDetail(this.questionId).then((res) => {
102
         getQuestionDetail(this.questionId).then((res) => {
104
           this.form = res.data
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
       } else {
106
       } else {
111
         this.form = {
107
         this.form = {
118
         }
114
         }
119
         this.rightList = []
115
         this.rightList = []
120
       }
116
       }
117
+      if (this.gameId) {
118
+        this.form.gameId = this.gameId
119
+      }
121
     },
120
     },
122
     gameId() {
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
   methods: {
134
   methods: {
133
     onAddAnswer() {
135
     onAddAnswer() {
134
       this.dialog = true
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
     handleCloseDrawer() {
138
     handleCloseDrawer() {
147
       this.dialog = false
139
       this.dialog = false
148
     },
140
     },
149
     handleEditDrawer(val) {
141
     handleEditDrawer(val) {
150
-      console.log(val)
142
+      this.isChange++
143
+      this.form.answerList.push(val)
151
       this.handleCloseDrawer()
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
     onSubmit() {
157
     onSubmit() {
154
-      if (this.form.name) {
158
+      if (this.form.title) {
159
+        this.form.rightAnswer = this.form.rightAnswer.toString()
155
         if (this.questionId) {
160
         if (this.questionId) {
156
           updateQuestion(this.form, this.questionId).then((res) => {
161
           updateQuestion(this.form, this.questionId).then((res) => {
157
             this.$message('修改问题成功')
162
             this.$message('修改问题成功')
170
         this.$message('请输入问题名称')
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
 </script>
180
 </script>

+ 3
- 3
src/main.js Ver arquivo

4
 
4
 
5
 import ElementUI from 'element-ui'
5
 import ElementUI from 'element-ui'
6
 import 'element-ui/lib/theme-chalk/index.css'
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
 import '@/styles/index.scss' // global css
9
 import '@/styles/index.scss' // global css
10
 
10
 
25
  */
25
  */
26
 // if (process.env.NODE_ENV === 'production') {
26
 // if (process.env.NODE_ENV === 'production') {
27
 //   const { mockXHR } = require('../mock')
27
 //   const { mockXHR } = require('../mock')
28
-  // mockXHR()
28
+// mockXHR()
29
 // }
29
 // }
30
 
30
 
31
 // set ElementUI lang to EN
31
 // set ElementUI lang to EN
35
 
35
 
36
 Vue.config.productionTip = false
36
 Vue.config.productionTip = false
37
 
37
 
38
-new Vue({  
38
+new Vue({
39
   el: '#app',
39
   el: '#app',
40
   router,
40
   router,
41
   store,
41
   store,

+ 3
- 1
src/store/index.js Ver arquivo

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

+ 1
- 1
src/store/modules/app.js Ver arquivo

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

+ 30
- 0
src/store/modules/game.js Ver arquivo

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 Ver arquivo

68
             />
68
             />
69
           </el-col>
69
           </el-col>
70
           <el-col :span="11">
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
           </el-col>
72
           </el-col>
73
         </el-row>
73
         </el-row>
74
       </el-tab-pane>
74
       </el-tab-pane>
171
     handleRefreshGameCharacter() {
171
     handleRefreshGameCharacter() {
172
       this.$refs.GameCharacter.onSearch()
172
       this.$refs.GameCharacter.onSearch()
173
     },
173
     },
174
-
175
     handleEditQuestion(val) {
174
     handleEditQuestion(val) {
176
       this.questionId = val
175
       this.questionId = val
177
     },
176
     },