李志伟 преди 3 години
родител
ревизия
6ff73f508c
променени са 5 файла, в които са добавени 218 реда и са изтрити 52 реда
  1. 0
    1
      src/components/GameCharacter/edit.vue
  2. 129
    0
      src/components/Question/drawer.vue
  3. 62
    41
      src/components/Question/edit.vue
  4. 11
    3
      src/components/Question/index.vue
  5. 16
    7
      src/views/gameManage/edit.vue

+ 0
- 1
src/components/GameCharacter/edit.vue Целия файл

@@ -61,7 +61,6 @@ export default {
61 61
       }
62 62
     },
63 63
     gameId: function() {
64
-      console.log(this.gameId)
65 64
       if (this.gameId) {
66 65
         this.form.gameId = this.gameId
67 66
       }

+ 129
- 0
src/components/Question/drawer.vue Целия файл

@@ -0,0 +1,129 @@
1
+<template>
2
+  <div>
3
+    <el-drawer
4
+      ref="drawer"
5
+      title="添加答案"
6
+      :before-close="handleClose"
7
+      :visible.sync="dialog"
8
+      direction="ltr"
9
+      custom-class="demo-drawer"
10
+    >
11
+      <div class="demo-drawer__content">
12
+        <el-form :model="form" style="margin:20px">
13
+          <el-form-item label="选项:" :label-width="formLabelWidth">
14
+            <el-select
15
+              v-model="form.option"
16
+              filterable
17
+              allow-create
18
+              default-first-option
19
+              placeholder="请选择选项"
20
+            >
21
+              <el-option
22
+                v-for="item in options"
23
+                :key="item.value"
24
+                :label="item.label"
25
+                :value="item.value"
26
+              />
27
+            </el-select>
28
+          </el-form-item>
29
+          <el-form-item label="内容详情" :label-width="formLabelWidth">
30
+            <el-input v-model="form.content" autocomplete="off" />
31
+          </el-form-item>
32
+          <el-form-item label="匹配特征:" :label-width="formLabelWidth">
33
+            <el-select
34
+              v-model="form.characterList"
35
+              multiple
36
+              filterable
37
+              default-first-option
38
+              placeholder="请选择特征"
39
+              style="width:100%"
40
+            >
41
+              <el-option
42
+                v-for="item in wordList"
43
+                :key="item.characterId"
44
+                :label="item.name"
45
+                :value="item.characterId"
46
+              />
47
+            </el-select>
48
+          </el-form-item>
49
+          <el-form-item style="text-align:center">
50
+            <el-button @click="cancelForm" size="mini">取 消</el-button>
51
+            <el-button type="primary" size="mini" @click="$refs.drawer.closeDrawer()">确 定</el-button>
52
+          </el-form-item>
53
+        </el-form>
54
+      </div>
55
+    </el-drawer>
56
+  </div>
57
+</template>
58
+<script>
59
+export default {
60
+  props: {
61
+    wordList: Array,
62
+    dialog: Boolean
63
+  },
64
+  data() {
65
+    return {
66
+      form: {
67
+        option: undefined,
68
+        content: undefined,
69
+        characterList: []
70
+      },
71
+      formLabelWidth: '120px',
72
+      options: [
73
+        {
74
+          value: 'A',
75
+          label: 'A'
76
+        },
77
+        {
78
+          value: 'B',
79
+          label: 'B'
80
+        },
81
+        {
82
+          value: 'C',
83
+          label: 'C'
84
+        },
85
+        {
86
+          value: 'D',
87
+          label: 'D'
88
+        },
89
+        {
90
+          value: '对',
91
+          label: '对'
92
+        },
93
+        {
94
+          value: '错',
95
+          label: '错'
96
+        }
97
+      ]
98
+    }
99
+  },
100
+  methods: {
101
+    handleClose(done) {
102
+      this.$confirm('确定要添加这条答案吗?')
103
+        .then(_ => {
104
+          const list = this.wordList.filter(item => {
105
+            this.form.characterList.some(v => v === item.characterId)
106
+          })
107
+          this.form.characterList = list
108
+          this.$emit('handleEditDrawer', this.form)
109
+          this.form = {
110
+            option: undefined,
111
+            content: undefined,
112
+            characterList: []
113
+          }
114
+        })
115
+        .catch(_ => {})
116
+    },
117
+    cancelForm() {
118
+      this.$emit('handleCloseDrawer', true)
119
+      this.form = {
120
+        option: undefined,
121
+        content: undefined,
122
+        characterList: []
123
+      }
124
+    }
125
+  }
126
+}
127
+</script>
128
+<style>
129
+</style>

+ 62
- 41
src/components/Question/edit.vue Целия файл

@@ -22,14 +22,14 @@
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
25
+          <!-- <AddAnswerMatching
26 26
             :characterId="characterId"
27 27
             :value="answer"
28 28
             :wordList="wordList"
29 29
             @change="handleChange"
30 30
             @handleDelete="() => handleDelete(answer)"
31 31
             @handleWordListChange="handleWordListChange"
32
-          />
32
+          /> -->
33 33
         </div>
34 34
       </el-form-item>
35 35
       <el-form-item label="正确选项:">
@@ -55,21 +55,26 @@
55 55
         <el-button @click="$router.go(-1)">返回</el-button>
56 56
       </el-form-item>
57 57
     </el-form>
58
+    <QuestionDrawer :dialog="dialog" :wordList='wordList' @handleCloseDrawer='handleCloseDrawer' @handleEditDrawer='handleEditDrawer' />
58 59
   </div>
59 60
 </template>
60 61
 <script>
61 62
 
62 63
 import { saveQuestion, updateQuestion, getQuestionDetail } from '@/api/question'
63
-import AddAnswerMatching from '@/components/AddAnswerMatching/index.vue'
64
-import { getCharacterLibDetail } from '@/api/characterLib'
64
+import { getGameCharacterList } from '@/api/gameCharacter'
65
+import QuestionDrawer from '@/components/Question/drawer.vue'
66
+
67
+// import AddAnswerMatching from '@/components/AddAnswerMatching/index.vue'
68
+// import { getCharacterLibDetail } from '@/api/characterLib'
65 69
 
66 70
 export default {
67 71
   components: {
68
-    AddAnswerMatching
72
+    QuestionDrawer
73
+    // AddAnswerMatching
69 74
   },
70 75
   props: {
71 76
     gameId: String,
72
-    characterId: String,
77
+    // characterId: String,
73 78
     questionId: String
74 79
   },
75 80
   data() {
@@ -85,8 +90,9 @@ export default {
85 90
       },
86 91
       // 正确答案数组
87 92
       rightList: [],
88
-      // 修饰词数据源
89
-      wordList: []
93
+      // 特征数据源
94
+      wordList: [],
95
+      dialog: false
90 96
     }
91 97
   },
92 98
   watch: {
@@ -115,20 +121,34 @@ export default {
115 121
     },
116 122
     gameId() {
117 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)
129
+      })
118 130
     }
119 131
   },
120 132
   methods: {
121 133
     onAddAnswer() {
122
-      this.form.answerList.push({
123
-        answerId: undefined,
124
-        questionId: undefined,
125
-        contentType: undefined,
126
-        option: undefined,
127
-        content: undefined,
128
-        characterWordList: [],
129
-        word: undefined,
130
-        wordId: undefined
131
-      })
134
+      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
+    },
146
+    handleCloseDrawer() {
147
+      this.dialog = false
148
+    },
149
+    handleEditDrawer(val) {
150
+      console.log(val)
151
+      this.handleCloseDrawer()
132 152
     },
133 153
     onSubmit() {
134 154
       if (this.form.name) {
@@ -136,40 +156,41 @@ export default {
136 156
           updateQuestion(this.form, this.questionId).then((res) => {
137 157
             this.$message('修改问题成功')
138 158
             // 告诉父页面实例表需要刷新并且关闭当前组件
139
-            this.$emit('handleRefresh', true)
159
+            this.$emit('handleRefreshQuestion', true)
140 160
           })
141 161
         } else {
142 162
           saveQuestion(this.form).then((res) => {
143 163
             this.$message('添加问题成功')
144 164
             // 告诉父页面实例表需要刷新并且关闭当前组件
145
-            this.$emit('handleRefresh', true)
165
+            this.$emit('handleRefreshQuestion', true)
166
+            this.$emit('handleEditQuestion', res.data.questionId)
146 167
           })
147 168
         }
148 169
       } else {
149 170
         this.$message('请输入问题名称')
150 171
       }
151
-    },
152
-    handleChange(answer) {
153
-      const index = this.form.answerList.indexOf(answer)
154
-      this.$set(this.form.answerList, index, answer)
155
-    },
156
-
157
-    handleWordListChange(val, list) {
158
-      getCharacterLibDetail(this.characterId).then((res) => {
159
-        this.wordList = res.data.wordList
160
-      })
161
-      const index = this.form.answerList.indexOf(val)
162
-      val.characterWordList = this.wordList.filter((item) =>
163
-        list.some((v) => v === item.wordId)
164
-      )
165
-      val.characterWordList.map(item => {
166
-        item = { ...item, characterId: this.characterId }
167
-      })
168
-      this.$set(this.form.answerList, index, val)
169
-    },
170
-    handleDelete(answer) {
171
-      this.form.answerList.splice(this.form.answerList.indexOf(answer), 1)
172 172
     }
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
+    // }
173 194
   }
174 195
 }
175 196
 </script>

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

@@ -27,6 +27,7 @@
27 27
     </div>
28 28
     <el-table stripe :data="tableData" border style="width: 100%">
29 29
       <el-table-column prop="title" label="问题名称" />
30
+      <el-table-column prop="optType" label="答案类型" />
30 31
       <el-table-column prop="createDate" label="创建时间">
31 32
         <template slot-scope="scope">{{
32 33
           scope.row.createDate.substr(0, 10)
@@ -65,21 +66,28 @@ export default {
65 66
       startDate: undefined
66 67
     }
67 68
   },
69
+  watch: {
70
+    gameId() {
71
+      if (this.gameId) {
72
+        this.onSearch()
73
+      }
74
+    }
75
+  },
68 76
   methods: {
69 77
     // 添加问题
70 78
     handleAdd() {
71
-      this.$emit('handleAdd', true)
79
+      this.$emit('handleAddQuestion', true)
72 80
     },
73 81
     handleEdit(row) {
74 82
       // 向外传送数据row.questionId
75
-      this.$emit('handleEdit', row.questionId)
83
+      this.$emit('handleEditQuestion', row.questionId)
76 84
     },
77 85
     handleDelete(row) {
78 86
       deleteQuestion(row.questionId).then(() => {
79 87
         this.$message('删除问题成功')
80 88
         this.onSearch()
81 89
         // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
82
-        this.$emit('handleClose', true)
90
+        this.$emit('handleCloseQuestion', true)
83 91
       })
84 92
     },
85 93
     onSearch() {

+ 16
- 7
src/views/gameManage/edit.vue Целия файл

@@ -59,8 +59,16 @@
59 59
       >
60 60
         <el-row :gutter="20" style="padding-top: 20px">
61 61
           <el-col :span="13">
62
+            <Question
63
+              ref="Question"
64
+              :gameId='gameId'
65
+              @handleAddQuestion='questionId = undefined'
66
+              @handleCloseQuestion='questionId = undefined'
67
+              @handleEditQuestion='handleEditQuestion'
68
+            />
62 69
           </el-col>
63 70
           <el-col :span="11">
71
+            <QuestionEdit :questionId='questionId' :gameId='gameId' @handleRefreshQuestion='handleRefreshQuestion' @handleEditQuestion='handleEditQuestion' />
64 72
           </el-col>
65 73
         </el-row>
66 74
       </el-tab-pane>
@@ -72,11 +80,15 @@ import { saveGame, UpdateGame, getGameDetail } from '@/api/game'
72 80
 import UploadImage from '@/components/UploadImage/index.vue'
73 81
 import GameCharacter from '@/components/GameCharacter/index.vue'
74 82
 import GameCharacterEdit from '@/components/GameCharacter/edit.vue'
83
+import Question from '@/components/Question/index.vue'
84
+import QuestionEdit from '@/components/Question/edit.vue'
75 85
 export default {
76 86
   components: {
77 87
     UploadImage,
78 88
     GameCharacter,
79
-    GameCharacterEdit
89
+    GameCharacterEdit,
90
+    Question,
91
+    QuestionEdit
80 92
   },
81 93
   data() {
82 94
     return {
@@ -160,14 +172,11 @@ export default {
160 172
       this.$refs.GameCharacter.onSearch()
161 173
     },
162 174
 
163
-    handleEdit(val) {
175
+    handleEditQuestion(val) {
164 176
       this.questionId = val
165 177
     },
166
-    handleClose() {
167
-      this.questionId = undefined
168
-    },
169
-    handleRefresh() {
170
-      this.$refs.GameCharacter.onSearch()
178
+    handleRefreshQuestion() {
179
+      this.$refs.Question.onSearch()
171 180
     }
172 181
   }
173 182
 }