LazyPage 1.0.0-beta3
This is a prerelease version of LazyPage.
dotnet add package LazyPage --version 1.0.0-beta3
NuGet\Install-Package LazyPage -Version 1.0.0-beta3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LazyPage" Version="1.0.0-beta3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazyPage --version 1.0.0-beta3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LazyPage, 1.0.0-beta3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LazyPage as a Cake Addin
#addin nuget:?package=LazyPage&version=1.0.0-beta3&prerelease
// Install LazyPage as a Cake Tool
#tool nuget:?package=LazyPage&version=1.0.0-beta3&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
通过可视化配置的方式,创建增删改查页面。对于后台管理一些简单的页面,实现无代码或低代码开发增删改查数据页面
LiteAbpUBDTemplate 项目模板集成效果图
一、快速开始
1、添加引用
<PackageReference Include="LazyPage" Version="1.0.0-beta2" />
2、Program.cs 配置启用
//ConfigureServices
builder.Services
.AddLazyPage(options =>
{
//配置数据库连接
options.DatabaseConfigs.Add(new PetaPocoDbConnectionConfig("default", "server=.;Database=db;user=sa;pwd=123456;Trusted_Connection=False;MultipleActiveResultSets=true;"));
options.DefaultDatabaseConfigName = "default";
});
//Configure
app.UseLazyPage();
3、安装ef工具
启动项目,在浏览器中打开路径:/lp/#/config
二、切换数据库(默认MSSQL)
PetaPoco 参考provider names
//添加mysql驱动引用
<PackageReference Include="MySql.Data" Version="8.0.32" />
//使用mysql
options.DatabaseConfigs.Add(new PetaPocoDbConnectionConfig("default", configuration.GetConnectionString("default"),"MySql.Data.MySqlClient"));
//替换服务
builder.Services.Replace(new ServiceDescriptor(typeof(IHandler), typeof(CustomHandle), ServiceLifetime.Scoped));
//继承和重写GetCreateTableSql
public class CustomHandler : DefaultHandler
{
protected override string GetCreateTableSql()
{
//mysql
return $"CREATE TABLE if not exists `{Options.DefaultTableName}` ( `Id` CHAR(36) NOT NULL PRIMARY KEY , `Name` NVARCHAR(128) NULL, `Value` LONGTEXT NULL , `VersionId` CHAR(36) NOT NULL );";
}
}
三、认证和鉴权
//前后端分离,前端请求接口从localStorage读取对应放入认证请求header
builder.Services
.AddLazyPage(options =>
{
options.AddClientBearerAuthorizationHeader("access_token");
//Basic认证
//options.AddClientBasicAuthorizationHeader("access_token");
});
//Cookie方案认证只重写认证和鉴权
public class CustomHandler : DefaultHandler
{
public override Task<bool> AuthenticateAsync(HttpContext context, LazyPageAuthorizationRequirement requirement = null)
{
return base.AuthenticateAsync(context, requirement);
}
public override async Task<bool> AuthorizeAsync(HttpContext context, LazyPageAuthorizationRequirement requirement)
{
if (requirement != null)
{
var user = context.RequestServices.GetRequiredService<ICurrentUser>();
if (user != null && user.IsInRole("admin"))
return true;
//此处只检查了页面的新增、编辑及查看权限,未进行页面中操作权限检查
var permissionService = context.RequestServices.GetRequiredService<PermissionService>();
var readPermission = $"{Options.RootPermissionName}.read".ToLower();
if (requirement.Name == readPermission)
return true;
var createPermission = $"{Options.RootPermissionName}.create".ToLower();
var updatePermission = $"{Options.RootPermissionName}.update".ToLower();
var permissionName = requirement.Name.StartsWith(readPermission) ? $"{readPermission}.{requirement.ConfigId}" : requirement.Name.StartsWith(updatePermission) ? updatePermission : createPermission;
var hasPermission = await permissionService.HasPermissionAsync(user.Roles, permissionName);
return hasPermission;
}
return false;
}
}
四、脚本执行参数
//执行参数加入[当前登录用户]
builder.Services
.AddLazyPage(options =>
{
options.ScriptEnvironmentalArgs.Add("currentUser", "当前登录用户");
});
//重写脚本执行,加入脚本参数所需的值
public override async Task<object> ExecuteScriptAsync(HttpContext context, PageConfig config, PageConfigScript script, IEnumerable<Dictionary<string, object>> args)
{
var environmentalArgs = Options.ScriptEnvironmentalArgs.Where(x => script.Content.Contains($"@lazypage_{x.Key}")).ToList();
if (environmentalArgs.Any())
{
foreach (var kv in environmentalArgs)
{
//获取上方currentUser对应的值
var lazypage_val = "";//GetScriptEnvironmentalValue(kv.Key);
var lazypage_key = $"lazypage_{kv.Key}";
foreach (var arg in args)
{
if (arg.ContainsKey(lazypage_key))
arg[lazypage_key] = lazypage_val;
else
arg.Add(lazypage_key, lazypage_val);
}
}
}
return await base.ExecuteSqlScriptAsync(context, config, script, args);
}
五、加入一条默认配置
public class CustomLazyPageHandle : DefaultHandler
{
//给存储表增加字段,创建时间、创建人...
protected override string GetCreateTableSql()
{
return $"IF NOT EXISTS ( SELECT * FROM sysobjects WHERE name = '{Options.DefaultTableName}' AND xtype = 'U' ) CREATE TABLE [dbo].[{Options.DefaultTableName}] ( [Id] [UNIQUEIDENTIFIER] NOT NULL PRIMARY KEY , [Name] [NVARCHAR](128) NULL , [Value] [NVARCHAR](MAX) NULL , [VersionId] [UNIQUEIDENTIFIER] NOT NULL , [CreationTime] [DATETIME2] NULL , [CreatorId] [UNIQUEIDENTIFIER] NULL , [LastModificationTime] [DATETIME2] NULL , [LastModifierId] [UNIQUEIDENTIFIER] NULL , [DeleterId] [UNIQUEIDENTIFIER] NULL , [DeletionTime] [DATETIME2] NULL , [IsDeleted] [BIT] NOT NULL DEFAULT ( CONVERT([BIT], ( 0 )) ) );";
}
//增加一条默认配置
public override async Task DataSeedAsync()
{
await base.DataSeedAsync();
var id = Guid.Parse("C8FE95DB-197B-49CF-B9F4-EE2A09838541");
var config = await QueryConfigAsync(id);
if (config == null)
{
var db = GetDatabase(Options.DefaultDatabaseConfigName);
var r = await db.InsertAsync(Options.DefaultTableName, new { Id = id, Name = "main", Value = @"{""scripts"":[{""name"":""pager"",""databaseConfigName"":""default"",""content"":""SELECT tb.Id ,\n tb.Name ,\n tb.VersionId ,\n '' AS Creator ,\n tb.CreationTime ,\n tb.LastModificationTime ,\n '' AS LastModifier\nFROM ( SELECT rowNum = ROW_NUMBER() OVER ( ORDER BY dbo.lazypageconfig.LastModificationTime DESC ) ,\n *\n FROM dbo.lazypageconfig\n WHERE dbo.lazypageconfig.Name LIKE '%' + @name + '%'\n ) tb\nWHERE tb.rowNum BETWEEN ( @lazypage_pageindex - 1 ) * @lazypage_pagesize + 1\n AND @lazypage_pageindex * @lazypage_pagesize;\n\t\t\t\t \nSELECT COUNT(1)\nFROM dbo.lazypageconfig\nWHERE Name LIKE '%' + @name + '%';"",""scriptType"":0,""cacheSeconds"":0,""isCustomScript"":false},{""name"":""del"",""databaseConfigName"":""default"",""content"":""DELETE dbo.lazypageconfig WHERE Id=@id"",""scriptType"":1,""cacheSeconds"":0,""isCustomScript"":false}],""views"":[{""id"":0,""type"":0,""name"":""列表"",""title"":"""",""extra"":{""size"":""default"",""sumLabel"":""合计"",""autoSearch"":true,""searchButton"":""筛选"",""elSearchFormProps"":{},""elSearchButtonProps"":{},""elTableProps"":{""stripe"":false,""border"":false,""show-header"":true},""elTableEvents"":{},""elTableExpandRadioGroupProps"":{},""paginationLGLayout"":""prev, pager, next, jumper, sizes, total"",""paginationXSLayout"":""prev, pager, next"",""elPaginationProps"":{""page-size"":10,""page-sizes"":[10,20,50,100]},""elPaginationEvents"":{}},""scriptName"":""pager"",""args"":[{""name"":""name"",""lable"":"""",""desc"":""请输入配置名称关键字"",""dataType"":""text"",""dateType"":""date"",""value"":"""",""referenceValue"":true,""isArray"":false,""order"":0,""scriptName"":"""",""dataSource"":"""",""multiple"":false,""filter"":false,""elSearchFormItemProps"":{},""elSearchFormItemElementProps"":{},""elSearchFormItemElementEvents"":{}}],""columns"":[{""type"":1,""name"":""多选"",""label"":"""",""hide"":true,""elTableColumnProps"":{""sortable"":false,""filter"":false,""width"":""30"",""fixed"":false}},{""type"":0,""name"":""Id"",""label"":""Id"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""Name"",""label"":""配置名称"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""VersionId"",""label"":""版本Id"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""Creator"",""label"":""创建人"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""CreationTime"",""label"":""创建时间"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""LastModificationTime"",""label"":""最后修改时间"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":0,""name"":""LastModifier"",""label"":""最后修改人"",""hide"":false,""order"":0,""sum"":false,""sumUnit"":"""",""formatter"":"""",""render"":"""",""isRender"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}},{""type"":2,""name"":""操作"",""label"":""操作"",""hide"":false,""elTableColumnProps"":{""sortable"":false,""filter"":false,""fixed"":false}}],""operators"":[{""id"":0,""type"":0,""name"":""新增"",""confirm"":"""",""mode"":0,""expand"":false,""scriptName"":"""",""args"":[],""linkedViews"":[],""linkedFrames"":"""",""hide"":"""",""beforeJS"":""function(operator){\n operator.stop();\n window.open('/lp/#/config');\n}"",""js"":"""",""extra"":{""type"":""primary"",""link"":false,""elElementProps"":{}}},{""id"":1,""type"":1,""name"":""编辑"",""confirm"":"""",""mode"":0,""expand"":false,""scriptName"":"""",""args"":[],""linkedViews"":[],""linkedFrames"":"""",""hide"":"""",""beforeJS"":""function(operator){\n operator.stop();\n window.open('/lp/#/config/c8fe95db-197b-49cf-b9f4-ee2a09838541');\n}"",""js"":"""",""extra"":{""type"":""primary"",""link"":true,""elElementProps"":{}}},{""id"":2,""type"":1,""name"":""删除"",""confirm"":""删除以后无法恢复,确定删除吗?"",""mode"":0,""expand"":false,""scriptName"":""del"",""args"":[{""name"":""id"",""value"":"""",""referenceValue"":false,""isArray"":false,""order"":0}],""linkedViews"":[],""linkedFrames"":"""",""hide"":""function(scope,row){ return row.Id=='c8fe95db-197b-49cf-b9f4-ee2a09838541'; }"",""beforeJS"":"""",""js"":""function(operator){\n if(operator.res&&operator.res>0){\n //提示信息\n operator.notification({type: 'success',title: '提示信息',message: '删除成功..'})\n //刷新页面 \n operator.refresh();\n return;\n }\n operator.notification({type: 'error',title: '提示信息',message: '删除失败..'});\n}"",""extra"":{""type"":""danger"",""link"":true,""elElementProps"":{}}}],""defaultOperatorId"":1}],""defaultViewId"":0}", VersionId = Guid.NewGuid(), CreationTime = DateTime.Now, IsDeleted = false });
}
}
//重写保存,增加创建时间、创建人
public override async Task<Guid?> SaveOrUpdateConfigAsync(PageConfig config)
{
var isUpdate = config.Id.HasValue;
var id = await base.SaveOrUpdateConfigAsync(config);
var db = GetDatabase(Options.DefaultDatabaseConfigName);
var user = ServiceProvider.GetRequiredService<ICurrentUser>();
await db.UpdateAsync(Options.DefaultTableName, "Id", isUpdate ? new { Id = config.Id.Value, LastModifierId = user?.Id, LastModificationTime = DateTime.Now } : new { Id = config.Id.Value, CreatorId = user?.Id, CreationTime = DateTime.Now });
return id;
}
}
增加一条默认配置后,可方便操作管理配置(浏览器打开:/lp/#/C8FE95DB-197B-49CF-B9F4-EE2A09838541)
1、列表效果图
2、新增效果图
3、编辑效果图
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Authorization (>= 6.0.8)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Caching.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Caching.Memory (>= 6.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.FileProviders.Embedded (>= 6.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- PetaPoco.Compiled (>= 6.0.524)
- System.Data.SqlClient (>= 4.8.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta3 | 108 | 3/28/2023 |