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