ConfigEdit.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
  3. <el-form ref="form" label-width="80px" :model="form" :rules="rules">
  4. <el-form-item label="标题" prop="title">
  5. <el-input v-model="form.title" />
  6. </el-form-item>
  7. </el-form>
  8. <div slot="footer" class="dialog-footer">
  9. <el-button @click="close">取 消</el-button>
  10. <el-button type="primary" @click="save">确 定</el-button>
  11. </div>
  12. </el-dialog>
  13. </template>
  14. <script>
  15. import { doEdit } from '@/api/system/config'
  16. export default {
  17. name: 'ConfigEdit',
  18. data() {
  19. return {
  20. form: {
  21. title: '',
  22. },
  23. rules: {
  24. title: [{ required: true, trigger: 'blur', message: '请输入标题' }],
  25. },
  26. title: '',
  27. dialogFormVisible: false,
  28. }
  29. },
  30. created() {},
  31. methods: {
  32. showEdit(row) {
  33. if (!row) {
  34. this.title = '添加'
  35. } else {
  36. this.title = '编辑'
  37. this.form = Object.assign({}, row)
  38. }
  39. this.dialogFormVisible = true
  40. },
  41. close() {
  42. this.$refs['form'].resetFields()
  43. this.form = this.$options.data().form
  44. this.dialogFormVisible = false
  45. },
  46. save() {
  47. this.$refs['form'].validate(async (valid) => {
  48. if (valid) {
  49. const { msg } = await doEdit(this.form)
  50. this.$baseMessage(msg, 'success')
  51. this.$emit('fetch-data')
  52. this.close()
  53. } else {
  54. return false
  55. }
  56. })
  57. },
  58. },
  59. }
  60. </script>