FormModal.vue 1.5 KB

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