FormModal.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 } from 'vue';
  14. import { BasicForm, useForm } from '/@/components/Form/index';
  15. // 声明Emits
  16. const props = defineProps({
  17. formSchema: { type: Array },
  18. record: { type: Object },
  19. });
  20. const emit = defineEmits(['saveOrUpdate']);
  21. // const testData = inject('formData') as any;
  22. //表单配置
  23. const [registerForm, { resetFields, setFieldsValue, validate, reload }] = useForm({
  24. schemas: props.formSchema,
  25. showActionButtonGroup: false,
  26. });
  27. watch(
  28. () => props.record,
  29. (newV) => {
  30. nextTick(() => {
  31. setFieldsValue({ ...newV });
  32. });
  33. },
  34. { immediate: true }
  35. );
  36. // 重置表单
  37. async function onReset() {
  38. await resetFields();
  39. await setFieldsValue({ ...props.record });
  40. }
  41. //表单提交事件
  42. async function handleSubmit(v) {
  43. try {
  44. let values = await validate();
  45. emit('saveOrUpdate', values);
  46. } finally {
  47. // setModalProps({ confirmLoading: false });
  48. }
  49. }
  50. </script>
  51. <style lang="less" scoped>
  52. @ventSpace: zxm;
  53. .j-box-bottom-button-float {
  54. border: none !important;
  55. padding-bottom: 30px;
  56. left: 0px !important;
  57. right: 0px !important;
  58. bottom: 0px !important;
  59. }
  60. .vent-form {
  61. max-height: 700px;
  62. overflow-y: auto;
  63. .@{ventSpace}-select-selection-item {
  64. color: rgba(255, 255, 255, 1) !important;
  65. }
  66. }
  67. </style>