feat: add seed data for 14 built-in form components

This commit is contained in:
向宁 2026-05-25 14:08:40 +08:00
parent 37ca47c5ea
commit fa1f8dbef5

View File

@ -9,9 +9,11 @@ public static class SeedData
{
if (db.WorkflowDefinitions.Any()) return;
await SeedComponentsAsync(db);
var systemUserId = Guid.Parse("00000000-0000-0000-0000-000000000001");
// ── 请假表单 ──
// ── 请假表单Formily JSON Schema──
var leaveForm = new FormDefinition
{
Id = Guid.Parse("A0000000-0000-0000-0000-000000000001"),
@ -19,49 +21,64 @@ public static class SeedData
Code = "leave-request",
Description = "员工请假申请表单",
Status = FormStatus.Published,
SchemaJson = """
{
"type": "object",
"properties": {
"leaveType": {
"type": "string",
"title": "请假类型",
"required": true,
"enum": [
{ "label": "年假", "value": "annual" },
{ "label": "事假", "value": "personal" },
{ "label": "病假", "value": "sick" },
{ "label": "婚假", "value": "marriage" },
{ "label": "产假", "value": "maternity" }
],
"x-decorator": "FormItem",
"x-component": "Select"
},
"dateRange": {
"type": "void",
"title": "日期范围",
"x-decorator": "FormItem",
"x-component": "FormGrid",
"properties": {
"startDate": {
"type": "string",
"title": "开始日期",
"required": true,
"x-decorator": "FormItem",
"x-component": "DatePicker"
},
"endDate": {
"type": "string",
"title": "结束日期",
"required": true,
"x-decorator": "FormItem",
"x-component": "DatePicker"
}
}
},
"reason": {
"type": "string",
"title": "请假原因",
"required": true,
"x-decorator": "FormItem",
"x-component": "Input.TextArea",
"x-component-props": { "maxLength": 500 }
}
}
}
""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
};
leaveForm.Fields =
[
new FormDefinitionField
{
Id = Guid.Parse("A0000001-0000-0000-0000-000000000001"),
FormDefinitionId = leaveForm.Id,
FieldKey = "leaveType", Label = "请假类型", FieldType = FieldType.Select,
Required = true, SortOrder = 1,
Config = """{ "options": ["", "", "", "", ""] }""",
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000001-0000-0000-0000-000000000002"),
FormDefinitionId = leaveForm.Id,
FieldKey = "startDate", Label = "开始日期", FieldType = FieldType.Date,
Required = true, SortOrder = 2,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000001-0000-0000-0000-000000000003"),
FormDefinitionId = leaveForm.Id,
FieldKey = "endDate", Label = "结束日期", FieldType = FieldType.Date,
Required = true, SortOrder = 3,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000001-0000-0000-0000-000000000004"),
FormDefinitionId = leaveForm.Id,
FieldKey = "reason", Label = "请假原因", FieldType = FieldType.Textarea,
Required = true, SortOrder = 4,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
];
db.FormDefinitions.Add(leaveForm);
// ── 报销表单 ──
// ── 报销表单Formily JSON Schema──
var expenseForm = new FormDefinition
{
Id = Guid.Parse("A0000000-0000-0000-0000-000000000002"),
@ -69,45 +86,52 @@ public static class SeedData
Code = "expense-claim",
Description = "员工费用报销申请表单",
Status = FormStatus.Published,
SchemaJson = """
{
"type": "object",
"properties": {
"category": {
"type": "string",
"title": "报销类别",
"required": true,
"enum": [
{ "label": "差旅", "value": "travel" },
{ "label": "办公用品", "value": "office" },
{ "label": "交通", "value": "transport" },
{ "label": "餐饮", "value": "meal" },
{ "label": "其他", "value": "other" }
],
"x-decorator": "FormItem",
"x-component": "Select"
},
"amount": {
"type": "number",
"title": "报销金额",
"required": true,
"x-decorator": "FormItem",
"x-component": "InputNumber",
"x-component-props": { "min": 0, "precision": 2 }
},
"description": {
"type": "string",
"title": "费用说明",
"required": true,
"x-decorator": "FormItem",
"x-component": "Input.TextArea"
},
"receipts": {
"type": "array",
"title": "上传发票",
"x-decorator": "FormItem",
"x-component": "Upload",
"x-component-props": { "maxCount": 5, "accept": ".pdf,.jpg,.png" }
}
}
}
""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
};
expenseForm.Fields =
[
new FormDefinitionField
{
Id = Guid.Parse("A0000002-0000-0000-0000-000000000001"),
FormDefinitionId = expenseForm.Id,
FieldKey = "category", Label = "报销类别", FieldType = FieldType.Select,
Required = true, SortOrder = 1,
Config = """{ "options": ["", "", "", "", ""] }""",
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000002-0000-0000-0000-000000000002"),
FormDefinitionId = expenseForm.Id,
FieldKey = "amount", Label = "报销金额", FieldType = FieldType.Number,
Required = true, SortOrder = 2,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000002-0000-0000-0000-000000000003"),
FormDefinitionId = expenseForm.Id,
FieldKey = "description", Label = "费用说明", FieldType = FieldType.Textarea,
Required = true, SortOrder = 3,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new FormDefinitionField
{
Id = Guid.Parse("A0000002-0000-0000-0000-000000000004"),
FormDefinitionId = expenseForm.Id,
FieldKey = "receipts", Label = "上传发票", FieldType = FieldType.FileUpload,
Required = false, SortOrder = 4,
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
];
db.FormDefinitions.Add(expenseForm);
@ -127,6 +151,7 @@ public static class SeedData
DefinitionId = Guid.Parse("B0000000-0000-0000-0000-000000000001"),
NodeType = NodeType.Approval, Name = "直属主管审批",
Config = """{ "assigneeRule": "role:manager" }""",
FormDefinitionId = Guid.Parse("A0000000-0000-0000-0000-000000000001"),
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new()
@ -250,6 +275,7 @@ public static class SeedData
DefinitionId = Guid.Parse("B0000000-0000-0000-0000-000000000002"),
NodeType = NodeType.Approval, Name = "部门主管审批",
Config = """{ "assigneeRule": "role:department-head" }""",
FormDefinitionId = Guid.Parse("A0000000-0000-0000-0000-000000000002"),
CreatedBy = systemUserId, UpdatedBy = systemUserId,
},
new()
@ -343,4 +369,209 @@ public static class SeedData
await db.SaveChangesAsync();
}
private static async Task SeedComponentsAsync(WorkflowDbContext db)
{
if (db.FormComponentRegistries.Any()) return;
var systemUserId = Guid.Parse("00000000-0000-0000-0000-000000000001");
var components = new List<FormComponentRegistry>
{
// ── 基础输入 ──
new()
{
Id = Guid.Parse("D0000001-0000-0000-0000-000000000001"),
Name = "Input",
DisplayName = "输入框",
Category = "基础输入",
Icon = "lucide:text-cursor-input",
SortOrder = 1,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"Input","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"minLength","label":"","type":"number"},{"key":"maxLength","label":"","type":"number"},{"key":"pattern","label":"","type":"string"},{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000002-0000-0000-0000-000000000001"),
Name = "Input.TextArea",
DisplayName = "文本域",
Category = "基础输入",
Icon = "lucide:align-left",
SortOrder = 2,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"rows","label":"","type":"number"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"minLength","label":"","type":"number"},{"key":"maxLength","label":"","type":"number"},{"key":"pattern","label":"","type":"string"},{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000003-0000-0000-0000-000000000001"),
Name = "Input.Password",
DisplayName = "密码框",
Category = "基础输入",
Icon = "lucide:lock",
SortOrder = 3,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"Input.Password","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"minLength","label":"","type":"number"},{"key":"maxLength","label":"","type":"number"},{"key":"pattern","label":"","type":"string"},{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000004-0000-0000-0000-000000000001"),
Name = "Input.Number",
DisplayName = "数字输入",
Category = "基础输入",
Icon = "lucide:hash",
SortOrder = 4,
DefaultSchema = """{"type":"number","title":"","x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"min","label":"","type":"number"},{"key":"max","label":"","type":"number"},{"key":"precision","label":"","type":"number"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
// ── 选择控件 ──
new()
{
Id = Guid.Parse("D0000005-0000-0000-0000-000000000001"),
Name = "Select",
DisplayName = "下拉选择",
Category = "选择控件",
Icon = "lucide:chevrons-up-down",
SortOrder = 10,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"Select","x-component-props":{"placeholder":""},"x-data-source":{"type":"static","options":[]}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"allowClear","label":"","type":"boolean"},{"key":"multiple","label":"","type":"boolean"}],"dataSource":{"supported":true,"types":["static","remote"]},"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000006-0000-0000-0000-000000000001"),
Name = "Radio.Group",
DisplayName = "单选框组",
Category = "选择控件",
Icon = "lucide:circle-dot",
SortOrder = 11,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"Radio.Group","x-component-props":{},"x-data-source":{"type":"static","options":[]}}""",
SupportedProps = """{"basic":[{"key":"optionType","label":"","type":"string"}],"dataSource":{"supported":true,"types":["static"]},"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000007-0000-0000-0000-000000000001"),
Name = "Checkbox.Group",
DisplayName = "复选框组",
Category = "选择控件",
Icon = "lucide:check-square",
SortOrder = 12,
DefaultSchema = """{"type":"array","title":"","x-decorator":"FormItem","x-component":"Checkbox.Group","x-component-props":{},"x-data-source":{"type":"static","options":[]}}""",
SupportedProps = """{"basic":[],"dataSource":{"supported":true,"types":["static"]},"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000008-0000-0000-0000-000000000001"),
Name = "Switch",
DisplayName = "开关",
Category = "选择控件",
Icon = "lucide:toggle-right",
SortOrder = 13,
DefaultSchema = """{"type":"boolean","title":"","x-decorator":"FormItem","x-component":"Switch","x-component-props":{}}""",
SupportedProps = """{"basic":[{"key":"checkedChildren","label":"","type":"string"},{"key":"unCheckedChildren","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
// ── 日期时间 ──
new()
{
Id = Guid.Parse("D0000009-0000-0000-0000-000000000001"),
Name = "DatePicker",
DisplayName = "日期选择",
Category = "日期时间",
Icon = "lucide:calendar",
SortOrder = 20,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"DatePicker","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"format","label":"","type":"string"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000010-0000-0000-0000-000000000001"),
Name = "TimePicker",
DisplayName = "时间选择",
Category = "日期时间",
Icon = "lucide:clock",
SortOrder = 21,
DefaultSchema = """{"type":"string","title":"","x-decorator":"FormItem","x-component":"TimePicker","x-component-props":{"placeholder":""}}""",
SupportedProps = """{"basic":[{"key":"placeholder","label":"","type":"string"},{"key":"format","label":"","type":"string"},{"key":"allowClear","label":"","type":"boolean"}],"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
// ── 文件 ──
new()
{
Id = Guid.Parse("D0000011-0000-0000-0000-000000000001"),
Name = "Upload",
DisplayName = "文件上传",
Category = "文件",
Icon = "lucide:upload",
SortOrder = 30,
DefaultSchema = """{"type":"array","title":"","x-decorator":"FormItem","x-component":"Upload","x-component-props":{"maxCount":1}}""",
SupportedProps = """{"basic":[{"key":"maxCount","label":"","type":"number"},{"key":"accept","label":"","type":"string"},{"key":"multiple","label":"","type":"boolean"}],"validation":[{"key":"customMessage","label":"","type":"string"}]}""",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
// ── 布局容器 ──
new()
{
Id = Guid.Parse("D0000012-0000-0000-0000-000000000001"),
Name = "FormGrid",
DisplayName = "栅格布局",
Category = "布局容器",
Icon = "lucide:grid-3x3",
SortOrder = 40,
DefaultSchema = """{"type":"void","title":"","x-decorator":"FormItem","x-component":"FormGrid","x-component-props":{}}""",
SupportedProps = "{}",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000013-0000-0000-0000-000000000001"),
Name = "FormLayout",
DisplayName = "表单布局",
Category = "布局容器",
Icon = "lucide:layout",
SortOrder = 41,
DefaultSchema = """{"type":"void","title":"","x-decorator":"FormItem","x-component":"FormLayout","x-component-props":{}}""",
SupportedProps = "{}",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
new()
{
Id = Guid.Parse("D0000014-0000-0000-0000-000000000001"),
Name = "Card",
DisplayName = "卡片容器",
Category = "布局容器",
Icon = "lucide:square",
SortOrder = 42,
DefaultSchema = """{"type":"void","title":"","x-decorator":"FormItem","x-component":"Card","x-component-props":{}}""",
SupportedProps = "{}",
CreatedBy = systemUserId,
UpdatedBy = systemUserId,
},
};
db.FormComponentRegistries.AddRange(components);
await db.SaveChangesAsync();
}
}