ModifyAppModule.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <el-dialog
  3. class="modify-app-module"
  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="60px"
  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 { appModuleInsertOrUpdate } from "../api";
  45. const initModalForm = {
  46. id: "",
  47. appId: null,
  48. name: "",
  49. code: ""
  50. };
  51. export default {
  52. name: "modify-app-module",
  53. props: {
  54. instance: {
  55. type: Object,
  56. default() {
  57. return {};
  58. }
  59. }
  60. },
  61. computed: {
  62. isEdit() {
  63. return !!this.instance.id;
  64. },
  65. title() {
  66. return (this.isEdit ? "编辑" : "新增") + "应用模块";
  67. }
  68. },
  69. data() {
  70. return {
  71. modalIsShow: false,
  72. isSubmit: false,
  73. modalForm: { ...initModalForm },
  74. rules: {
  75. name: [
  76. {
  77. required: true,
  78. message: "请输入名称",
  79. trigger: "change"
  80. },
  81. {
  82. max: 50,
  83. message: "名称不能超过50字符",
  84. trigger: "change"
  85. }
  86. ],
  87. code: [
  88. {
  89. required: true,
  90. message: "请输入编码",
  91. trigger: "change"
  92. },
  93. {
  94. max: 50,
  95. message: "编码不能超过50字符",
  96. trigger: "change"
  97. }
  98. ]
  99. }
  100. };
  101. },
  102. methods: {
  103. initData(val) {
  104. this.modalForm = this.$objAssign(initModalForm, val);
  105. this.$refs.modalFormComp.clearValidate();
  106. },
  107. visibleChange() {
  108. this.initData(this.instance);
  109. },
  110. cancel() {
  111. this.modalIsShow = false;
  112. },
  113. open() {
  114. this.modalIsShow = true;
  115. },
  116. async submit() {
  117. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  118. if (!valid) return;
  119. if (this.isSubmit) return;
  120. this.isSubmit = true;
  121. let datas = { ...this.modalForm };
  122. if (!this.isEdit) datas.enable = true;
  123. const data = await appModuleInsertOrUpdate(datas).catch(() => {});
  124. this.isSubmit = false;
  125. if (!data) return;
  126. this.$message.success(this.title + "成功!");
  127. this.$emit("modified");
  128. this.cancel();
  129. }
  130. }
  131. };
  132. </script>