123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <template>
- <div style="padding: 20px">
- <h2 style="text-align: center">
- 特征实例{{ characterId ? "编辑" : "添加" }}
- </h2>
- <el-form ref="form" :model="form" label-width="150px" size="mini">
- <el-form-item label="实例名称:">
- <el-input
- v-model="form.name"
- placeholder="请输入实例名(必填)"
- />
- </el-form-item>
- <el-form-item label="实例图片:">
- <UploadImage :icon="form.thumb" @handleChange="handleChange" @handleDeleteIcon="handleDeleteIcon" />
- </el-form-item>
- <el-form-item label="实例描述:">
- <el-input v-model="form.desc" type="textarea" />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="onSubmit">确定</el-button>
- <el-button @click="$router.go(-1)">返回</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <script>
- import { getGameCharacterDetail, UpdateGameCharacter, saveGameCharacter } from '@/api/gameCharacter'
- import UploadImage from '@/components/UploadImage/index.vue'
- export default {
- components: {
- UploadImage
- },
- props: {
- gameId: String,
- characterId: String
- },
- data() {
- return {
- form: {
- gameId: undefined,
- name: undefined,
- thumb: undefined,
- desc: undefined,
- characterId: undefined
- }
- }
- },
- watch: {
- characterId: function() {
- if (this.characterId) {
- getGameCharacterDetail(this.characterId).then((res) => {
- this.form = res.data
- })
- } else {
- this.form = {
- name: undefined,
- thumb: undefined,
- desc: undefined,
- characterId: undefined
- }
- }
- if (this.gameId) {
- this.form.gameId = this.gameId
- }
- },
- gameId: function() {
- if (this.gameId) {
- this.form.gameId = this.gameId
- }
- }
- },
- methods: {
- onSubmit() {
- const data = { ...this.form }
- data.characterId = this.characterId
- if (data.name) {
- if (this.characterId) {
- if (!data.thumb) {
- data.thumb = ''
- }
- UpdateGameCharacter(data, this.characterId).then((res) => {
- this.$message('修改实例成功')
- // 告诉父页面实例表需要刷新
- this.$emit('handleRefreshGameCharacter', true)
- })
- } else {
- saveGameCharacter(data).then((res) => {
- this.$message('添加实例成功')
- // 告诉父页面实例表需要刷新
- this.$emit('handleRefreshGameCharacter', true)
- // 把当前页改为编辑页面
- this.$emit('handleEditGameCharacter', res.data.characterId)
- })
- }
- } else {
- this.$message('请输入实例名')
- }
- },
- handleChange(val) {
- this.form.thumb = val
- },
- handleDeleteIcon() {
- this.form.thumb = ''
- }
- }
- }
- </script>
- <style>
- </style>
|