index.vue 2.1 KB
Newer Older
V
vben 已提交
1 2 3 4 5 6 7 8
<template>
  <div class="high-form">
    <a-page-header title="高级表单" :ghost="false">
      高级表单常见于一次性输入和提交大批量数据的场景。
    </a-page-header>

    <div class="m-5">
      <a-card title="仓库管理" :bordered="false">
V
vben 已提交
9
        <BasicForm @register="register" />
V
vben 已提交
10 11
      </a-card>
      <a-card title="任务管理" :bordered="false" class="mt-5">
V
vben 已提交
12
        <BasicForm @register="registerTask" />
V
vben 已提交
13 14 15 16 17 18
      </a-card>
      <a-card title="成员管理" :bordered="false" class="mt-5">
        <PersonTable ref="tableRef" />
      </a-card>
    </div>

V
vben 已提交
19
    <PageFooter>
V
vben 已提交
20 21 22
      <template #right>
        <a-button type="primary" @click="submitAll">提交</a-button>
      </template>
V
vben 已提交
23
    </PageFooter>
V
vben 已提交
24 25 26 27 28 29
  </div>
</template>
<script lang="ts">
  import { BasicForm, useForm } from '/@/components/Form';
  import { defineComponent, ref } from 'vue';
  import PersonTable from './PersonTable.vue';
V
vben 已提交
30
  import { PageFooter } from '/@/components/Page';
31

V
vben 已提交
32 33 34
  import { schemas, taskSchemas } from './data';

  export default defineComponent({
V
vben 已提交
35
    components: { BasicForm, PersonTable, PageFooter },
V
vben 已提交
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 70 71 72 73 74
    setup() {
      const tableRef = ref<{ getDataSource: () => any } | null>(null);

      const [register, { validate }] = useForm({
        baseColProps: {
          span: 6,
        },
        schemas: schemas,
        showActionButtonGroup: false,
      });

      const [registerTask, { validate: validateTaskForm }] = useForm({
        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) {}
      }

      return { register, registerTask, submitAll, tableRef };
    },
  });
</script>
<style lang="less" scoped>
  .high-form {
    padding-bottom: 48px;
  }
</style>