3
0

ModifyApp.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <el-dialog
  3. class="modify-app"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10px"
  7. width="540px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. :key="modalForm.id"
  18. label-width="110px"
  19. >
  20. <el-form-item prop="name" label="名称:">
  21. <el-input
  22. v-model.trim="modalForm.name"
  23. placeholder="请输入名称"
  24. clearable
  25. ></el-input>
  26. </el-form-item>
  27. <el-form-item prop="code" label="编码:">
  28. <el-input
  29. v-model.trim="modalForm.code"
  30. placeholder="请输入编码"
  31. clearable
  32. ></el-input>
  33. </el-form-item>
  34. </el-form>
  35. <div slot="footer">
  36. <el-button type="danger" @click="cancel" plain>取消</el-button>
  37. <el-button type="primary" :disabled="isSubmit" @click="submit"
  38. >确认</el-button
  39. >
  40. </div>
  41. </el-dialog>
  42. </template>
  43. <script>
  44. import { appInsertOrUpdate } from "../api";
  45. const initModalForm = {
  46. id: "",
  47. name: "",
  48. code: ""
  49. };
  50. export default {
  51. name: "modify-app",
  52. props: {
  53. instance: {
  54. type: Object,
  55. default() {
  56. return {};
  57. }
  58. }
  59. },
  60. computed: {
  61. isEdit() {
  62. return !!this.instance.id;
  63. },
  64. title() {
  65. return (this.isEdit ? "编辑" : "新增") + "应用";
  66. }
  67. },
  68. data() {
  69. return {
  70. modalIsShow: false,
  71. isSubmit: false,
  72. modalForm: { ...initModalForm },
  73. rules: {
  74. name: [
  75. {
  76. required: true,
  77. message: "请输入应用名称",
  78. trigger: "change"
  79. },
  80. {
  81. max: 50,
  82. message: "名称不能超过50",
  83. trigger: "change"
  84. }
  85. ],
  86. code: [
  87. {
  88. required: true,
  89. message: "请输入应用编码",
  90. trigger: "change"
  91. },
  92. {
  93. max: 50,
  94. message: "编码不能超过50",
  95. trigger: "change"
  96. }
  97. ]
  98. }
  99. };
  100. },
  101. methods: {
  102. initData(val) {
  103. if (val.id) {
  104. this.modalForm = this.$objAssign(initModalForm, val);
  105. } else {
  106. this.modalForm = { ...initModalForm };
  107. }
  108. this.$refs.modalFormComp.clearValidate();
  109. },
  110. visibleChange() {
  111. this.initData(this.instance);
  112. },
  113. cancel() {
  114. this.modalIsShow = false;
  115. },
  116. open() {
  117. this.modalIsShow = true;
  118. },
  119. async submit() {
  120. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  121. if (!valid) return;
  122. if (this.isSubmit) return;
  123. this.isSubmit = true;
  124. let datas = { ...this.modalForm };
  125. const data = await appInsertOrUpdate(datas).catch(() => {
  126. this.isSubmit = false;
  127. });
  128. if (!data) return;
  129. this.isSubmit = false;
  130. this.$message.success(this.title + "成功!");
  131. this.$emit("modified");
  132. this.cancel();
  133. }
  134. }
  135. };
  136. </script>