FormModal.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 { message } from 'ant-design-vue';
  14. import { reject } from 'lodash';
  15. import { inject, nextTick, watch } from 'vue';
  16. import { BasicForm, useForm } from '/@/components/Form/index';
  17. // 声明Emits
  18. const emit = defineEmits(['saveOrUpdate']);
  19. const testData = inject('formData') as any;
  20. //表单配置
  21. const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
  22. schemas: inject('formSchema'),
  23. showActionButtonGroup: false,
  24. });
  25. watch(
  26. testData,
  27. (newV) => {
  28. nextTick(() => {
  29. setFieldsValue({ ...newV });
  30. });
  31. },
  32. { immediate: true }
  33. );
  34. // 重置表单
  35. async function onReset() {
  36. await resetFields();
  37. await setFieldsValue({ ...testData });
  38. }
  39. //表单提交事件
  40. async function handleSubmit(v) {
  41. try {
  42. let values = await validate();
  43. emit('saveOrUpdate', values);
  44. } finally {
  45. // setModalProps({ confirmLoading: false });
  46. }
  47. }
  48. </script>
  49. <style lang="less" scoped>
  50. .j-box-bottom-button-float {
  51. border: none !important;
  52. padding-bottom: 30px;
  53. left: 0px !important;
  54. right: 0px !important;
  55. bottom: 0px !important;
  56. }
  57. </style>