<template>
<curd-form class="center-form" ref="dynamicForm" :fields="fields" :form-schema="formSchema">
<template v-slot:operate-button>
<div style="text-align: center">
<el-button type="primary" @click="submit">提 交</el-button>
<el-button type="default" @click="clear">清 空</el-button>
</div>
</template>
</curd-form>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue"
import PageHeader from "@/components/Layout/PageHeader"
const formSchema = {
formItem: [
{ type: "input", label: "用户名", prop: "username", span: 24 },
{ type: "input", label: "姓名", prop: "name", span: 24 },
{ type: "input-password", label: "密码", prop: "password", span: 24 },
{
type: "select",
label: "角色",
prop: "role",
options: [
{ label: "超级管理员", value: 1 },
{ label: "普通管理员", value: 2 },
],
span: 24,
},
{
type: "radio",
label: "性别",
prop: "sex",
options: [
{ label: "男", value: 1 },
{ label: "女", value: 2 },
],
span: 24,
value: 1,
},
{
type: "input-number",
label: "年龄",
prop: "age",
value: 1,
props: {
controlsPosition: "right",
},
span: 12,
},
],
rules:{
username:[
{ required: true, message:"用户名不能为空", trigger: "blur" }
]
},
labelWidth: 110
}
const fields = {}
const dynamicForm = ref()
const instance = getCurrentInstance()
const submit = () => {
dynamicForm.value.validate((valid) => {
if (valid) {
instance.appContext.config.globalProperties.$message({
type: "success",
message: "提交成功",
})
}
})
}
const clear = () => {
dynamicForm.value.schemaFormRef.resetFields()
}
</script>
<style></style>
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