BasicFormFooter.vue
2.2 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!-- 自定义页脚 -->
<template>
<!-- 自定义表单 -->
<BasicForm @register="registerForm" style="margin-top: 20px">
<template #formHeader>
<div style="margin: 0 auto 20px">
<span>我是自定义按钮</span>
</div>
</template>
<template #formFooter>
<div style="margin: 0 auto">
<a-button type="primary" @click="save" class="mr-2"> 保存 </a-button>
<a-button type="primary" @click="saveDraft" class="mr-2"> 保存草稿 </a-button>
<a-button type="error" @click="reset" class="mr-2"> 重置 </a-button>
</div>
</template>
</BasicForm>
</template>
<script lang="ts" setup>
//引入依赖
import { useForm, BasicForm, FormSchema } from '/@/components/Form';
//自定义表单字段
const formSchemas: FormSchema[] = [
{
label: '员工姓名',
field: 'name',
component: 'Input',
},
{
label: '性别',
field: 'sex',
component: 'Select',
//填写组件的属性
componentProps: {
options: [
{ label: '男', value: 1 },
{ label: '女', value: 2 },
{ label: '未知', value: 3 },
],
},
//默认值
defaultValue: 3,
},
{
label: '年龄',
field: 'age',
component: 'Input',
},
{
label: '入职时间',
subLabel: '( 选填 )',
field: 'entryTime',
component: 'TimePicker',
},
];
/**
* BasicForm绑定注册;
*/
const [registerForm, { validate, resetFields }] = useForm({
schemas: formSchemas,
labelWidth: '150px',
//隐藏操作按钮
showActionButtonGroup: false,
});
/**
* 保存
*/
async function save() {
//使用useForm方法获取表单值
let values = await validate();
console.log(values);
}
/**
* 保存草稿
*/
async function saveDraft() {
//使用useForm方法validate获取表单值
let values = await validate();
console.log(values);
}
/**
* 重置
*/
async function reset() {
//使用useForm方法resetFields清空值
await resetFields();
}
</script>
<style scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
width: 100%;
}
:deep(.ant-picker) {
width: 100%;
}
</style>