ModifyFlow.vue 3.4 KB

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