- 创建一个组件类,用[PagePlugin]特性标识,框架自动在页面编辑模式下添加插件菜单项
- 菜单分类项目有:模块、表格、表单、详情、列表、图表、模板、AI、其他
[PagePlugin("测试", "file", Category = nameof(PagePluginType.Other), Sort = 1)]
class TestPlugin : PluginBase<TestPluginInfo>
{
protected override async Task OnInitAsync()
{
await base.OnInitAsync();
Draggable = true; // 是否支持区块移动
AddAction("setting", "设置", OnSetting); // 添加设置下拉菜单
}
protected override void BuildPlugin(RenderTreeBuilder builder)
{
builder.Ul(() =>
{
builder.Li("", $"当前页面:{Context?.Current?.Name}");
builder.Li("", $"插件ID:{Plugin?.Id}");
builder.Li("", $"插件类型:{Plugin?.Type}");
builder.Li("", $"插件参数:{Parameter?.Name}");
});
}
private void OnSetting()
{
var model = new FormModel<TestPluginInfo>(this, true)
{
Title = "测试插件配置",
Data = Parameter ?? new TestPluginInfo(),
OnSave = SaveParameterAsync,
OnSaved = d => StateChanged()
};
UI.ShowForm(model);
}
}
public class TestPluginInfo
{
[Form]
[Required]
public string Name { get; set; }
}