index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <PageWrapper
  3. class="high-form"
  4. title="高级表单"
  5. content=" 高级表单常见于一次性输入和提交大批量数据的场景。"
  6. >
  7. <Card title="仓库管理" :bordered="false">
  8. <BasicForm @register="register" />
  9. </Card>
  10. <Card title="任务管理" :bordered="false" class="!mt-5">
  11. <BasicForm @register="registerTask" />
  12. </Card>
  13. <Card title="成员管理" :bordered="false" class="!mt-5">
  14. <PersonTable ref="tableRef" />
  15. </Card>
  16. <template #rightFooter>
  17. <a-button type="primary" @click="submitAll"> 提交 </a-button>
  18. </template>
  19. </PageWrapper>
  20. </template>
  21. <script lang="ts" setup>
  22. import { BasicForm, useForm } from '@/components/Form';
  23. import { ref } from 'vue';
  24. import PersonTable from './PersonTable.vue';
  25. import { PageWrapper } from '@/components/Page';
  26. import { schemas, taskSchemas } from './data';
  27. import { Card } from 'ant-design-vue';
  28. defineOptions({ name: 'FormHightPage' });
  29. const tableRef = ref<{ getDataSource: () => any } | null>(null);
  30. const [register, { validate }] = useForm({
  31. layout: 'vertical',
  32. baseColProps: {
  33. span: 6,
  34. },
  35. schemas: schemas,
  36. showActionButtonGroup: false,
  37. });
  38. const [registerTask, { validate: validateTaskForm }] = useForm({
  39. layout: 'vertical',
  40. baseColProps: {
  41. span: 6,
  42. },
  43. schemas: taskSchemas,
  44. showActionButtonGroup: false,
  45. });
  46. async function submitAll() {
  47. try {
  48. if (tableRef.value) {
  49. console.log('table data:', tableRef.value.getDataSource());
  50. }
  51. const [values, taskValues] = await Promise.all([validate(), validateTaskForm()]);
  52. console.log('form data:', values, taskValues);
  53. } catch (error) {
  54. console.log(error);
  55. }
  56. }
  57. </script>
  58. <style lang="less" scoped>
  59. .high-form {
  60. padding-bottom: 48px;
  61. }
  62. </style>