edit.vue 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div style="padding: 20px">
  3. <h2 style="text-align: center">
  4. 特征实例{{ characterId ? "编辑" : "添加" }}
  5. </h2>
  6. <el-form ref="form" :model="form" label-width="150px" size="mini">
  7. <el-form-item label="实例名称:">
  8. <el-input
  9. v-model="form.name"
  10. placeholder="请输入实例名(必填)"
  11. />
  12. </el-form-item>
  13. <el-form-item label="实例图片:">
  14. <UploadImage :icon="form.thumb" @handleChange="handleChange" @handleDeleteIcon="handleDeleteIcon" />
  15. </el-form-item>
  16. <el-form-item label="实例描述:">
  17. <el-input v-model="form.desc" type="textarea" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click="onSubmit">确定</el-button>
  21. <el-button @click="$router.go(-1)">返回</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. </template>
  26. <script>
  27. import { getGameCharacterDetail, UpdateGameCharacter, saveGameCharacter } from '@/api/gameCharacter'
  28. import UploadImage from '@/components/UploadImage/index.vue'
  29. export default {
  30. components: {
  31. UploadImage
  32. },
  33. props: {
  34. gameId: String,
  35. characterId: String
  36. },
  37. data() {
  38. return {
  39. form: {
  40. gameId: undefined,
  41. name: undefined,
  42. thumb: undefined,
  43. desc: undefined,
  44. characterId: undefined
  45. }
  46. }
  47. },
  48. watch: {
  49. characterId: function() {
  50. if (this.characterId) {
  51. getGameCharacterDetail(this.characterId).then((res) => {
  52. this.form = res.data
  53. })
  54. } else {
  55. this.form = {
  56. name: undefined,
  57. thumb: undefined,
  58. desc: undefined,
  59. characterId: undefined
  60. }
  61. }
  62. if (this.gameId) {
  63. this.form.gameId = this.gameId
  64. }
  65. },
  66. gameId: function() {
  67. if (this.gameId) {
  68. this.form.gameId = this.gameId
  69. }
  70. }
  71. },
  72. methods: {
  73. onSubmit() {
  74. const data = { ...this.form }
  75. data.characterId = this.characterId
  76. if (data.name) {
  77. if (this.characterId) {
  78. if (!data.thumb) {
  79. data.thumb = ''
  80. }
  81. UpdateGameCharacter(data, this.characterId).then((res) => {
  82. this.$message('修改实例成功')
  83. // 告诉父页面实例表需要刷新
  84. this.$emit('handleRefreshGameCharacter', true)
  85. })
  86. } else {
  87. saveGameCharacter(data).then((res) => {
  88. this.$message('添加实例成功')
  89. // 告诉父页面实例表需要刷新
  90. this.$emit('handleRefreshGameCharacter', true)
  91. // 把当前页改为编辑页面
  92. this.$emit('handleEditGameCharacter', res.data.characterId)
  93. })
  94. }
  95. } else {
  96. this.$message('请输入实例名')
  97. }
  98. },
  99. handleChange(val) {
  100. this.form.thumb = val
  101. },
  102. handleDeleteIcon() {
  103. this.form.thumb = ''
  104. }
  105. }
  106. }
  107. </script>
  108. <style>
  109. </style>