ModifyField.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <el-dialog
  3. class="modify-field"
  4. :visible.sync="modalIsShow"
  5. title="新增扩展字段"
  6. top="10vh"
  7. width="448px"
  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. label-position="top"
  18. >
  19. <el-form-item prop="name" label="字段名称:">
  20. <el-input
  21. v-model.trim="modalForm.name"
  22. placeholder="请输入字段名称"
  23. clearable
  24. ></el-input>
  25. </el-form-item>
  26. <el-form-item prop="code" label="字段变量名:">
  27. <el-input
  28. v-model.trim="modalForm.code"
  29. placeholder="请输入字段变量名"
  30. clearable
  31. ></el-input>
  32. </el-form-item>
  33. </el-form>
  34. <div slot="footer">
  35. <el-button type="primary" @click="submit">确认</el-button>
  36. <el-button @click="cancel">取消</el-button>
  37. </div>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. const initModalForm = {
  42. name: "",
  43. code: "",
  44. enable: false,
  45. };
  46. export default {
  47. name: "modify-field",
  48. data() {
  49. return {
  50. modalIsShow: false,
  51. modalForm: {},
  52. rules: {
  53. name: [
  54. {
  55. required: true,
  56. message: "请输入字段名称",
  57. trigger: "change",
  58. },
  59. {
  60. max: 20,
  61. message: "字段名称不能超过20",
  62. trigger: "change",
  63. },
  64. ],
  65. code: [
  66. {
  67. required: true,
  68. pattern: /^[a-zA-Z]{3,30}$/,
  69. message: "字段变量名只能由字母组成,长度在3-30之间",
  70. trigger: "change",
  71. },
  72. ],
  73. },
  74. };
  75. },
  76. methods: {
  77. visibleChange() {
  78. this.modalForm = { ...initModalForm };
  79. this.$nextTick(() => {
  80. this.$refs.modalFormComp.clearValidate();
  81. });
  82. },
  83. cancel() {
  84. this.modalIsShow = false;
  85. },
  86. open() {
  87. this.modalIsShow = true;
  88. },
  89. async submit() {
  90. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  91. if (!valid) return;
  92. this.$emit("confirm", this.modalForm);
  93. this.cancel();
  94. },
  95. },
  96. };
  97. </script>