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