Blame view

src/views/demo/page/form/basic/index.vue 1.65 KB
1
<template>
2
3
  <PageWrapper
    title="基础表单"
4
    contentBackground
5
    content=" 表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。"
vben authored
6
    contentClass="p-4"
7
8
9
  >
    <BasicForm @register="register" />
  </PageWrapper>
10
11
12
13
14
15
</template>
<script lang="ts">
  import { BasicForm, useForm } from '/@/components/Form';
  import { defineComponent } from 'vue';
  import { schemas } from './data';
  import { useMessage } from '/@/hooks/web/useMessage';
16
17
  import { PageWrapper } from '/@/components/Page';
18
  export default defineComponent({
19
    components: { BasicForm, PageWrapper },
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
    setup() {
      const { createMessage } = useMessage();
      const [register, { validate, setProps }] = useForm({
        labelCol: {
          span: 7,
        },
        wrapperCol: {
          span: 10,
        },
        schemas: schemas,
        actionColOptions: {
          offset: 8,
        },
        submitButtonOptions: {
          text: '提交',
        },
        submitFunc: customSubmitFunc,
      });

      async function customSubmitFunc() {
        try {
          await validate();
          setProps({
            submitButtonOptions: {
              loading: true,
            },
          });
          setTimeout(() => {
            setProps({
              submitButtonOptions: {
                loading: false,
              },
            });
            createMessage.success('提交成功!');
          }, 2000);
        } catch (error) {}
      }

      return { register };
    },
  });
</script>
<style lang="less" scoped>
  .form-wrap {
    padding: 24px;
65
    background-color: @component-background;
66
67
  }
</style>