edit.vue 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="body_edit">
  3. <el-tabs v-model="activeName">
  4. <el-tab-pane label="游戏详情" name="game">
  5. <h2 style="text-align: center">游戏{{ gameId ? "编辑" : "新增" }}</h2>
  6. <el-form ref="form" class="gameForm" :model="gameForm" label-width="150px" size="mini">
  7. <el-form-item label="游戏名称:">
  8. <el-input v-model="gameForm.title" />
  9. </el-form-item>
  10. <el-form-item label="游戏图标:">
  11. <UploadImage :icon="gameForm.gameImage" @handleChange="handleChange" @handleDeleteIcon="handleDeleteIcon" />
  12. </el-form-item>
  13. <el-form-item label="游戏类型:">
  14. <el-select
  15. v-model="gameForm.resultMode"
  16. filterable
  17. default-first-option
  18. placeholder="请选择"
  19. :disabled="gameId ? true : false"
  20. >
  21. <el-option
  22. v-for="item in resultList"
  23. :key="item.value"
  24. :label="item.label"
  25. :value="item.value"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item class="editBottomItem">
  30. <el-button type="primary" @click="onSubmit">保存</el-button>
  31. <el-button @click="onCancel">取消</el-button>
  32. </el-form-item>
  33. </el-form>
  34. </el-tab-pane>
  35. <el-tab-pane
  36. label="关联特征"
  37. name="game-character"
  38. :disabled="gameId ? false : true"
  39. >
  40. <el-row :gutter="20" style="padding-top: 20px">
  41. <el-col :span="12">
  42. <GameCharacter
  43. ref="GameCharacter"
  44. :gameId='gameId'
  45. @handleAddGameCharacter='characterId = undefined'
  46. @handleCloseGameCharacter='characterId = undefined'
  47. @handleEditGameCharacter='handleEditGameCharacter'
  48. />
  49. </el-col>
  50. <el-col :span="12">
  51. <GameCharacterEdit :characterId='characterId' :gameId='gameId' @handleRefreshGameCharacter='handleRefreshGameCharacter' @handleEditGameCharacter='handleEditGameCharacter' />
  52. </el-col>
  53. </el-row>
  54. </el-tab-pane>
  55. <el-tab-pane
  56. label="游戏题库"
  57. name="question"
  58. :disabled="gameId ? false : true"
  59. >
  60. <el-row :gutter="20" style="padding-top: 20px">
  61. <el-col :span="12">
  62. <Question
  63. ref="Question"
  64. :gameId='gameId'
  65. @handleAddQuestion='questionId = undefined'
  66. @handleCloseQuestion='questionId = undefined'
  67. @handleEditQuestion='handleEditQuestion'
  68. />
  69. </el-col>
  70. <el-col :span="12">
  71. <QuestionEdit ref="QuestionEdit" :questionId='questionId' :gameId='gameId' @handleRefreshQuestion='handleRefreshQuestion' @handleEditQuestion='handleEditQuestion' />
  72. </el-col>
  73. </el-row>
  74. </el-tab-pane>
  75. </el-tabs>
  76. </div>
  77. </template>
  78. <script>
  79. import { saveGame, UpdateGame, getGameDetail } from '@/api/game'
  80. import UploadImage from '@/components/UploadImage/index.vue'
  81. import GameCharacter from '@/components/GameCharacter/index.vue'
  82. import GameCharacterEdit from '@/components/GameCharacter/edit.vue'
  83. import Question from '@/components/Question/index.vue'
  84. import QuestionEdit from '@/components/Question/edit.vue'
  85. export default {
  86. components: {
  87. UploadImage,
  88. GameCharacter,
  89. GameCharacterEdit,
  90. Question,
  91. QuestionEdit
  92. },
  93. data() {
  94. return {
  95. gameForm: {
  96. title: undefined,
  97. gameImage: undefined,
  98. resultMode: undefined
  99. },
  100. resultList: [
  101. {
  102. value: 'examination',
  103. label: '测试'
  104. },
  105. {
  106. value: 'character_matched',
  107. label: '匹配'
  108. }
  109. ],
  110. gameId: undefined,
  111. activeName: 'game',
  112. questionId: undefined,
  113. characterId: undefined
  114. }
  115. },
  116. watch: {
  117. '$route.query.id': {
  118. handler(val) {
  119. if (val) { // 有值代表是编辑状态 查询详情 没有值就是新增
  120. this.gameId = val
  121. getGameDetail(val).then((res) => {
  122. this.gameForm = res.data
  123. })
  124. }
  125. },
  126. immediate: true // 页面加载时就启动
  127. }
  128. },
  129. methods: {
  130. onCancel() {
  131. this.$router.go(-1)
  132. },
  133. onSubmit() {
  134. if (this.gameForm.title && this.gameForm.resultMode) {
  135. if (this.gameId) {
  136. const data = { ...this.gameForm }
  137. if (!data.gameImage) {
  138. data.gameImage = ''
  139. }
  140. UpdateGame(data, this.gameId).then((res) => {
  141. this.$message('修改成功')
  142. this.$router.go(-1)
  143. })
  144. } else {
  145. saveGame(this.gameForm).then((res) => {
  146. this.$message('保存成功')
  147. this.$router.replace({
  148. name: 'gameEdit',
  149. query: { id: res.data.gameId }
  150. })
  151. })
  152. }
  153. } else {
  154. this.$message('请输入游戏名称和游戏类型')
  155. }
  156. },
  157. handleChange(val) {
  158. this.gameForm.gameImage = val
  159. },
  160. handleDeleteIcon() {
  161. this.gameForm.gameImage = ''
  162. },
  163. // 特征页面方法
  164. // 改变编辑特征页面的初始值
  165. handleEditGameCharacter(val) {
  166. this.characterId = val
  167. },
  168. handleRefreshGameCharacter() {
  169. this.$refs.GameCharacter.onSearch()
  170. },
  171. handleEditQuestion(val) {
  172. this.questionId = val
  173. },
  174. handleRefreshQuestion() {
  175. this.$refs.Question.onSearch()
  176. }
  177. }
  178. }
  179. </script>
  180. <style>
  181. .gameForm{
  182. width: 700px;
  183. margin: auto;
  184. }
  185. .editBottomItem > div {
  186. margin: 0 !important;
  187. text-align: center;
  188. }
  189. </style>