index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div>
  3. <a-page-header title="基础表单" :ghost="false">
  4. 表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。
  5. </a-page-header>
  6. <div class="m-5 form-wrap">
  7. <BasicForm @register="register" />
  8. </div>
  9. </div>
  10. </template>
  11. <script lang="ts">
  12. import { BasicForm, useForm } from '/@/components/Form';
  13. import { defineComponent } from 'vue';
  14. import { schemas } from './data';
  15. import { useMessage } from '/@/hooks/web/useMessage';
  16. export default defineComponent({
  17. components: { BasicForm },
  18. setup() {
  19. const { createMessage } = useMessage();
  20. const [register, { validate, setProps }] = useForm({
  21. labelCol: {
  22. span: 7,
  23. },
  24. wrapperCol: {
  25. span: 10,
  26. },
  27. schemas: schemas,
  28. actionColOptions: {
  29. offset: 8,
  30. },
  31. submitButtonOptions: {
  32. text: '提交',
  33. },
  34. submitFunc: customSubmitFunc,
  35. });
  36. async function customSubmitFunc() {
  37. try {
  38. await validate();
  39. setProps({
  40. submitButtonOptions: {
  41. loading: true,
  42. },
  43. });
  44. setTimeout(() => {
  45. setProps({
  46. submitButtonOptions: {
  47. loading: false,
  48. },
  49. });
  50. createMessage.success('提交成功!');
  51. }, 2000);
  52. } catch (error) {}
  53. }
  54. return { register };
  55. },
  56. });
  57. </script>
  58. <style lang="less" scoped>
  59. .form-wrap {
  60. padding: 24px;
  61. background: #fff;
  62. }
  63. </style>