FormModal.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="vent-form">
  3. <BasicForm @register="registerForm" />
  4. <div class="j-box-bottom-button offset-20" style="margin-top: 30px">
  5. <div class="j-box-bottom-button-float">
  6. <a-button preIcon="ant-design:sync-outlined" @click="onReset">重置</a-button>
  7. <a-button type="primary" preIcon="ant-design:save-filled" @click="handleSubmit">保存</a-button>
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. <script lang="ts" setup>
  13. import { inject, nextTick, watch, unref, onMounted } from 'vue';
  14. import { BasicForm, useForm } from '/@/components/Form/index';
  15. // 声明Emits
  16. const emit = defineEmits(['saveOrUpdate']);
  17. const testData = inject('formData') as any;
  18. const props = defineProps({
  19. deviceType: { type: String },
  20. record: { type: Object },
  21. });
  22. const existingSchemas = unref(inject('formSchema')) || [];
  23. //表单配置
  24. const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
  25. schemas: existingSchemas as any[],
  26. showActionButtonGroup: false,
  27. });
  28. watch(
  29. testData,
  30. (newV) => {
  31. nextTick(() => {
  32. setFieldsValue({ ...newV });
  33. });
  34. },
  35. { immediate: true }
  36. );
  37. // 重置表单
  38. async function onReset() {
  39. await resetFields();
  40. await setFieldsValue({ ...testData });
  41. }
  42. //表单提交事件
  43. async function handleSubmit(v) {
  44. try {
  45. let values = await validate();
  46. emit('saveOrUpdate', values);
  47. } finally {
  48. // setModalProps({ confirmLoading: false });
  49. }
  50. }
  51. </script>
  52. <style lang="less" scoped>
  53. @ventSpace: zxm;
  54. .j-box-bottom-button-float {
  55. border: none !important;
  56. padding-bottom: 30px;
  57. left: 0px !important;
  58. right: 0px !important;
  59. bottom: 0px !important;
  60. }
  61. .vent-form {
  62. // width: 100%;
  63. max-height: 700px;
  64. overflow-y: auto;
  65. .@{ventSpace}-select-selection-item {
  66. color: rgba(255, 255, 255, 1) !important;
  67. }
  68. }
  69. </style>