Merge pull request '代码生成: vxe-table 列表模板 完成度 99.99%' (#13) from orzsoft_admin/Admin.NET.Pro:main into main
Reviewed-on: http://101.43.53.74:3000/Admin.NET/Admin.NET.Pro/pulls/13
This commit is contained in:
commit
7bc0160c0e
@ -1,452 +1,452 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core;
|
||||
|
||||
public static class SqlSugarSetup
|
||||
{
|
||||
// 多租户实例
|
||||
public static ITenant ITenant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar 上下文初始化
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static void AddSqlSugar(this IServiceCollection services)
|
||||
{
|
||||
// 注册雪花Id
|
||||
var snowIdOpt = App.GetConfig<SnowIdOptions>("SnowId", true);
|
||||
YitIdHelper.SetIdGenerator(snowIdOpt);
|
||||
|
||||
// 自定义 SqlSugar 雪花ID算法
|
||||
SnowFlakeSingle.WorkId = snowIdOpt.WorkerId;
|
||||
StaticConfig.CustomSnowFlakeFunc = () =>
|
||||
{
|
||||
return YitIdHelper.NextId();
|
||||
};
|
||||
|
||||
var dbOptions = App.GetConfig<DbConnectionOptions>("DbConnection", true);
|
||||
dbOptions.ConnectionConfigs.ForEach(SetDbConfig);
|
||||
|
||||
SqlSugarScope sqlSugar = new(dbOptions.ConnectionConfigs.Adapt<List<ConnectionConfig>>(), db =>
|
||||
{
|
||||
dbOptions.ConnectionConfigs.ForEach(config =>
|
||||
{
|
||||
var dbProvider = db.GetConnectionScope(config.ConfigId);
|
||||
SetDbAop(dbProvider, dbOptions.EnableConsoleSql);
|
||||
SetDbDiffLog(dbProvider, config);
|
||||
});
|
||||
});
|
||||
ITenant = sqlSugar;
|
||||
|
||||
services.AddSingleton<ISqlSugarClient>(sqlSugar); // 单例注册
|
||||
services.AddScoped(typeof(SqlSugarRepository<>)); // 仓储注册
|
||||
services.AddUnitOfWork<SqlSugarUnitOfWork>(); // 事务与工作单元注册
|
||||
|
||||
// 初始化数据库表结构及种子数据
|
||||
dbOptions.ConnectionConfigs.ForEach(config =>
|
||||
{
|
||||
InitDatabase(sqlSugar, config);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置连接属性
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public static void SetDbConfig(DbConnectionConfig config)
|
||||
{
|
||||
var configureExternalServices = new ConfigureExternalServices
|
||||
{
|
||||
EntityNameService = (type, entity) => // 处理表
|
||||
{
|
||||
entity.IsDisabledDelete = true; // 禁止删除非 sqlsugar 创建的列
|
||||
// 只处理贴了特性[SugarTable]表
|
||||
if (!type.GetCustomAttributes<SugarTable>().Any())
|
||||
return;
|
||||
if (config.DbSettings.EnableUnderLine && !entity.DbTableName.Contains('_'))
|
||||
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName); // 驼峰转下划线
|
||||
},
|
||||
EntityService = (type, column) => // 处理列
|
||||
{
|
||||
// 只处理贴了特性[SugarColumn]列
|
||||
if (!type.GetCustomAttributes<SugarColumn>().Any())
|
||||
return;
|
||||
if (new NullabilityInfoContext().Create(type).WriteState is NullabilityState.Nullable)
|
||||
column.IsNullable = true;
|
||||
if (config.DbSettings.EnableUnderLine && !column.IsIgnore && !column.DbColumnName.Contains('_'))
|
||||
column.DbColumnName = UtilMethods.ToUnderLine(column.DbColumnName); // 驼峰转下划线
|
||||
},
|
||||
DataInfoCacheService = new SqlSugarCache(),
|
||||
};
|
||||
config.ConfigureExternalServices = configureExternalServices;
|
||||
config.InitKeyType = InitKeyType.Attribute;
|
||||
config.IsAutoCloseConnection = true;
|
||||
config.MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
IsAutoRemoveDataCache = true, // 启用自动删除缓存,所有增删改会自动调用.RemoveDataCache()
|
||||
IsAutoDeleteQueryFilter = true, // 启用删除查询过滤器
|
||||
IsAutoUpdateQueryFilter = true, // 启用更新查询过滤器
|
||||
SqlServerCodeFirstNvarchar = true // 采用Nvarchar
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Aop
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="enableConsoleSql"></param>
|
||||
public static void SetDbAop(SqlSugarScopeProvider db, bool enableConsoleSql)
|
||||
{
|
||||
// 设置超时时间
|
||||
db.Ado.CommandTimeOut = 30;
|
||||
|
||||
// 打印SQL语句
|
||||
if (enableConsoleSql)
|
||||
{
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
//// 若参数值超过100个字符则进行截取
|
||||
//foreach (var par in pars)
|
||||
//{
|
||||
// if (par.DbType != System.Data.DbType.String || par.Value == null) continue;
|
||||
// if (par.Value.ToString().Length > 100)
|
||||
// par.Value = string.Concat(par.Value.ToString()[..100], "......");
|
||||
//}
|
||||
|
||||
var log = $"【{DateTime.Now}——执行SQL】\r\n{UtilMethods.GetNativeSql(sql, pars)}\r\n";
|
||||
var originColor = Console.ForegroundColor;
|
||||
if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(log);
|
||||
Console.ForegroundColor = originColor;
|
||||
App.PrintToMiniProfiler("SqlSugar", "Info", log);
|
||||
};
|
||||
db.Aop.OnError = ex =>
|
||||
{
|
||||
if (ex.Parametres == null) return;
|
||||
var log = $"【{DateTime.Now}——错误SQL】\r\n{UtilMethods.GetNativeSql(ex.Sql, (SugarParameter[])ex.Parametres)}\r\n";
|
||||
Log.Error(log, ex);
|
||||
App.PrintToMiniProfiler("SqlSugar", "Error", log);
|
||||
};
|
||||
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
//// 若参数值超过100个字符则进行截取
|
||||
//foreach (var par in pars)
|
||||
//{
|
||||
// if (par.DbType != System.Data.DbType.String || par.Value == null) continue;
|
||||
// if (par.Value.ToString().Length > 100)
|
||||
// par.Value = string.Concat(par.Value.ToString()[..100], "......");
|
||||
//}
|
||||
|
||||
// 执行时间超过5秒时
|
||||
if (db.Ado.SqlExecutionTime.TotalSeconds > 5)
|
||||
{
|
||||
var fileName = db.Ado.SqlStackTrace.FirstFileName; // 文件名
|
||||
var fileLine = db.Ado.SqlStackTrace.FirstLine; // 行号
|
||||
var firstMethodName = db.Ado.SqlStackTrace.FirstMethodName; // 方法名
|
||||
var log = $"【{DateTime.Now}——超时SQL】\r\n【所在文件名】:{fileName}\r\n【代码行数】:{fileLine}\r\n【方法名】:{firstMethodName}\r\n" + $"【SQL语句】:{UtilMethods.GetNativeSql(sql, pars)}";
|
||||
Log.Warning(log);
|
||||
App.PrintToMiniProfiler("SqlSugar", "Slow", log);
|
||||
}
|
||||
};
|
||||
}
|
||||
// 数据审计
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
// 新增/插入
|
||||
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||
{
|
||||
// 若主键是长整型且空且不是自增类型则赋值雪花Id
|
||||
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
||||
{
|
||||
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||
if (id == null || (long)id == 0)
|
||||
entityInfo.SetValue(YitIdHelper.NextId());
|
||||
}
|
||||
// 若创建时间为空则赋值当前时间
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateTime) && entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue) == null)
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
// 若当前用户非空(web线程时)
|
||||
if (App.User != null)
|
||||
{
|
||||
dynamic entityValue = entityInfo.EntityValue;
|
||||
if (entityInfo.PropertyName == nameof(EntityTenantId.TenantId))
|
||||
{
|
||||
if (entityValue.TenantId == null || entityValue.TenantId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.TenantId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserId))
|
||||
{
|
||||
if (entityValue.CreateUserId == null || entityValue.CreateUserId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.UserId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserName))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entityValue.CreateUserName))
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.RealName)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBaseData.CreateOrgId))
|
||||
{
|
||||
if (entityValue.CreateOrgId == null || entityValue.CreateOrgId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBaseData.CreateOrgName))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entityValue.CreateOrgName))
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgName)?.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 编辑/更新
|
||||
else if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
||||
{
|
||||
if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime))
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserId))
|
||||
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.UserId)?.Value);
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserName))
|
||||
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.RealName)?.Value);
|
||||
}
|
||||
};
|
||||
|
||||
// 超管排除其他过滤器
|
||||
if (App.User?.FindFirst(ClaimConst.AccountType)?.Value == ((int)AccountTypeEnum.SuperAdmin).ToString())
|
||||
return;
|
||||
|
||||
// 配置假删除过滤器
|
||||
db.QueryFilter.AddTableFilter<IDeletedFilter>(u => u.IsDelete == false);
|
||||
|
||||
// 配置租户过滤器
|
||||
var tenantId = App.User?.FindFirst(ClaimConst.TenantId)?.Value;
|
||||
if (!string.IsNullOrWhiteSpace(tenantId))
|
||||
db.QueryFilter.AddTableFilter<ITenantIdFilter>(u => u.TenantId == long.Parse(tenantId));
|
||||
|
||||
// 配置用户机构(数据范围)过滤器
|
||||
SqlSugarFilter.SetOrgEntityFilter(db);
|
||||
|
||||
// 配置自定义过滤器
|
||||
SqlSugarFilter.SetCustomEntityFilter(db);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启库表差异化日志
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="config"></param>
|
||||
private static void SetDbDiffLog(SqlSugarScopeProvider db, DbConnectionConfig config)
|
||||
{
|
||||
if (!config.DbSettings.EnableDiffLog) return;
|
||||
|
||||
db.Aop.OnDiffLogEvent = async u =>
|
||||
{
|
||||
var logDiff = new SysLogDiff
|
||||
{
|
||||
// 操作后记录(字段描述、列名、值、表名、表描述)
|
||||
AfterData = JSON.Serialize(u.AfterData),
|
||||
// 操作前记录(字段描述、列名、值、表名、表描述)
|
||||
BeforeData = JSON.Serialize(u.BeforeData),
|
||||
// 传进来的对象(如果对象为空,则使用首个数据的表名作为业务对象)
|
||||
BusinessData = u.BusinessData == null ? u.AfterData.FirstOrDefault()?.TableName : JSON.Serialize(u.BusinessData),
|
||||
// 枚举(insert、update、delete)
|
||||
DiffType = u.DiffType.ToString(),
|
||||
Sql = UtilMethods.GetNativeSql(u.Sql, u.Parameters),
|
||||
Parameters = JSON.Serialize(u.Parameters),
|
||||
Elapsed = u.Time == null ? 0 : (long)u.Time.Value.TotalMilliseconds
|
||||
};
|
||||
var logDb = ITenant.IsAnyConnection(SqlSugarConst.LogConfigId) ? ITenant.GetConnectionScope(SqlSugarConst.LogConfigId) : db;
|
||||
await logDb.CopyNew().Insertable(logDiff).ExecuteCommandAsync();
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(DateTime.Now + $"\r\n*****开始差异日志*****\r\n{Environment.NewLine}{JSON.Serialize(logDiff)}{Environment.NewLine}*****结束差异日志*****\r\n");
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化数据库
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="config"></param>
|
||||
private static void InitDatabase(SqlSugarScope db, DbConnectionConfig config)
|
||||
{
|
||||
SqlSugarScopeProvider dbProvider = db.GetConnectionScope(config.ConfigId);
|
||||
|
||||
// 初始化/创建数据库
|
||||
if (config.DbSettings.EnableInitDb)
|
||||
{
|
||||
if (config.DbType != SqlSugar.DbType.Oracle)
|
||||
dbProvider.DbMaintenance.CreateDatabase();
|
||||
}
|
||||
|
||||
// 初始化表结构
|
||||
if (config.TableSettings.EnableInitTable)
|
||||
{
|
||||
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false))
|
||||
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any())
|
||||
.WhereIF(config.TableSettings.EnableIncreTable, u => u.IsDefined(typeof(IncreTableAttribute), false)).ToList();
|
||||
|
||||
if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性)
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttributes<SysTableAttribute>().Any() || (!u.GetCustomAttributes<LogTableAttribute>().Any() && !u.GetCustomAttributes<TenantAttribute>().Any())).ToList();
|
||||
else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttributes<LogTableAttribute>().Any()).ToList();
|
||||
else
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库
|
||||
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
|
||||
dbProvider.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
dbProvider.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化种子数据
|
||||
if (config.SeedSettings.EnableInitSeed)
|
||||
{
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false))
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? (u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0] as SeedDataAttribute).Order : 0).ToList();
|
||||
|
||||
foreach (var seedType in seedDataTypes)
|
||||
{
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
|
||||
if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性)
|
||||
{
|
||||
if (entityType.GetCustomAttribute<SysTableAttribute>() == null && (entityType.GetCustomAttribute<LogTableAttribute>() != null || entityType.GetCustomAttribute<TenantAttribute>() != null))
|
||||
continue;
|
||||
}
|
||||
else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库
|
||||
{
|
||||
if (entityType.GetCustomAttribute<LogTableAttribute>() == null)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var att = entityType.GetCustomAttribute<TenantAttribute>(); // 自定义的库
|
||||
if (att == null || att.configId.ToString() != config.ConfigId.ToString()) continue;
|
||||
}
|
||||
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
var hasDataMethod = seedType.GetMethod("HasData");
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
|
||||
if (seedData == null) continue;
|
||||
|
||||
var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType);
|
||||
if (entityInfo.Columns.Any(u => u.IsPrimarykey))
|
||||
{
|
||||
// 按主键进行批量增加和更新
|
||||
var storage = dbProvider.StorageableByObject(seedData.ToList()).ToStorage();
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
|
||||
storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(c => c.PropertyName).ToArray()).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无主键则只进行插入
|
||||
if (!dbProvider.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any())
|
||||
dbProvider.InsertableByObject(seedData.ToList()).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化租户业务数据库
|
||||
/// </summary>
|
||||
/// <param name="iTenant"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void InitTenantDatabase(ITenant iTenant, DbConnectionConfig config)
|
||||
{
|
||||
SetDbConfig(config);
|
||||
|
||||
if (!iTenant.IsAnyConnection(config.ConfigId.ToString()))
|
||||
iTenant.AddConnection(config);
|
||||
var db = iTenant.GetConnectionScope(config.ConfigId.ToString());
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
|
||||
// 初始化租户库表结构-获取所有业务应用表(排除系统表、日志表、特定库表)
|
||||
var entityTypes = App.EffectiveTypes
|
||||
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any())
|
||||
.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) &&
|
||||
!u.IsDefined(typeof(SysTableAttribute), false) && !u.IsDefined(typeof(LogTableAttribute), false) && !u.IsDefined(typeof(TenantAttribute), false)).ToList();
|
||||
if (!entityTypes.Any()) return;
|
||||
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();
|
||||
if (splitTable == null)
|
||||
db.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
db.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
|
||||
// 初始化业务应用种子数据
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.Where(u => u.IsDefined(typeof(AppSeedAttribute), false))
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? (u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0] as SeedDataAttribute).Order : 0).ToList();
|
||||
|
||||
foreach (var seedType in seedDataTypes)
|
||||
{
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
var hasDataMethod = seedType.GetMethod("HasData");
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>().ToList();
|
||||
if (seedData == null) continue;
|
||||
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
||||
var dbConfigId = config.ConfigId.ToLong();
|
||||
// 若实体包含租户Id字段,则设置为当前租户Id
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(EntityTenantId.TenantId)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId)).SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Pid字段,则设置为当前租户Id
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(SysOrg.Pid)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid)).SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Id字段,则设置为当前租户Id递增1
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(EntityBaseId.Id)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id)).SetValue(sd, ++dbConfigId);
|
||||
}
|
||||
}
|
||||
|
||||
// 若实体是系统内置,则切换至默认库
|
||||
if (entityType.GetCustomAttribute<SysTableAttribute>() != null)
|
||||
db = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
|
||||
|
||||
if (entityInfo.Columns.Any(u => u.IsPrimarykey))
|
||||
{
|
||||
// 按主键进行批量增加和更新
|
||||
var storage = db.StorageableByObject(seedData).ToStorage();
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
|
||||
storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(c => c.PropertyName).ToArray()).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无主键则只进行插入
|
||||
if (!db.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any())
|
||||
db.InsertableByObject(seedData).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core;
|
||||
|
||||
public static class SqlSugarSetup
|
||||
{
|
||||
// 多租户实例
|
||||
public static ITenant ITenant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar 上下文初始化
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static void AddSqlSugar(this IServiceCollection services)
|
||||
{
|
||||
// 注册雪花Id
|
||||
var snowIdOpt = App.GetConfig<SnowIdOptions>("SnowId", true);
|
||||
YitIdHelper.SetIdGenerator(snowIdOpt);
|
||||
|
||||
// 自定义 SqlSugar 雪花ID算法
|
||||
SnowFlakeSingle.WorkId = snowIdOpt.WorkerId;
|
||||
StaticConfig.CustomSnowFlakeFunc = () =>
|
||||
{
|
||||
return YitIdHelper.NextId();
|
||||
};
|
||||
|
||||
var dbOptions = App.GetConfig<DbConnectionOptions>("DbConnection", true);
|
||||
dbOptions.ConnectionConfigs.ForEach(SetDbConfig);
|
||||
|
||||
SqlSugarScope sqlSugar = new(dbOptions.ConnectionConfigs.Adapt<List<ConnectionConfig>>(), db =>
|
||||
{
|
||||
dbOptions.ConnectionConfigs.ForEach(config =>
|
||||
{
|
||||
var dbProvider = db.GetConnectionScope(config.ConfigId);
|
||||
SetDbAop(dbProvider, dbOptions.EnableConsoleSql);
|
||||
SetDbDiffLog(dbProvider, config);
|
||||
});
|
||||
});
|
||||
ITenant = sqlSugar;
|
||||
|
||||
services.AddSingleton<ISqlSugarClient>(sqlSugar); // 单例注册
|
||||
services.AddScoped(typeof(SqlSugarRepository<>)); // 仓储注册
|
||||
services.AddUnitOfWork<SqlSugarUnitOfWork>(); // 事务与工作单元注册
|
||||
|
||||
// 初始化数据库表结构及种子数据
|
||||
dbOptions.ConnectionConfigs.ForEach(config =>
|
||||
{
|
||||
InitDatabase(sqlSugar, config);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置连接属性
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public static void SetDbConfig(DbConnectionConfig config)
|
||||
{
|
||||
var configureExternalServices = new ConfigureExternalServices
|
||||
{
|
||||
EntityNameService = (type, entity) => // 处理表
|
||||
{
|
||||
entity.IsDisabledDelete = true; // 禁止删除非 sqlsugar 创建的列
|
||||
// 只处理贴了特性[SugarTable]表
|
||||
if (!type.GetCustomAttributes<SugarTable>().Any())
|
||||
return;
|
||||
if (config.DbSettings.EnableUnderLine && !entity.DbTableName.Contains('_'))
|
||||
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName); // 驼峰转下划线
|
||||
},
|
||||
EntityService = (type, column) => // 处理列
|
||||
{
|
||||
// 只处理贴了特性[SugarColumn]列
|
||||
if (!type.GetCustomAttributes<SugarColumn>().Any())
|
||||
return;
|
||||
if (new NullabilityInfoContext().Create(type).WriteState is NullabilityState.Nullable)
|
||||
column.IsNullable = true;
|
||||
if (config.DbSettings.EnableUnderLine && !column.IsIgnore && !column.DbColumnName.Contains('_'))
|
||||
column.DbColumnName = UtilMethods.ToUnderLine(column.DbColumnName); // 驼峰转下划线
|
||||
},
|
||||
DataInfoCacheService = new SqlSugarCache(),
|
||||
};
|
||||
config.ConfigureExternalServices = configureExternalServices;
|
||||
config.InitKeyType = InitKeyType.Attribute;
|
||||
config.IsAutoCloseConnection = true;
|
||||
config.MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
IsAutoRemoveDataCache = true, // 启用自动删除缓存,所有增删改会自动调用.RemoveDataCache()
|
||||
IsAutoDeleteQueryFilter = true, // 启用删除查询过滤器
|
||||
IsAutoUpdateQueryFilter = true, // 启用更新查询过滤器
|
||||
SqlServerCodeFirstNvarchar = true // 采用Nvarchar
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Aop
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="enableConsoleSql"></param>
|
||||
public static void SetDbAop(SqlSugarScopeProvider db, bool enableConsoleSql)
|
||||
{
|
||||
// 设置超时时间
|
||||
db.Ado.CommandTimeOut = 30;
|
||||
|
||||
// 打印SQL语句
|
||||
if (enableConsoleSql)
|
||||
{
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
//// 若参数值超过100个字符则进行截取
|
||||
//foreach (var par in pars)
|
||||
//{
|
||||
// if (par.DbType != System.Data.DbType.String || par.Value == null) continue;
|
||||
// if (par.Value.ToString().Length > 100)
|
||||
// par.Value = string.Concat(par.Value.ToString()[..100], "......");
|
||||
//}
|
||||
|
||||
var log = $"【{DateTime.Now}——执行SQL】\r\n{UtilMethods.GetNativeSql(sql, pars)}\r\n";
|
||||
var originColor = Console.ForegroundColor;
|
||||
if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(log);
|
||||
Console.ForegroundColor = originColor;
|
||||
App.PrintToMiniProfiler("SqlSugar", "Info", log);
|
||||
};
|
||||
db.Aop.OnError = ex =>
|
||||
{
|
||||
if (ex.Parametres == null) return;
|
||||
var log = $"【{DateTime.Now}——错误SQL】\r\n{UtilMethods.GetNativeSql(ex.Sql, (SugarParameter[])ex.Parametres)}\r\n";
|
||||
Log.Error(log, ex);
|
||||
App.PrintToMiniProfiler("SqlSugar", "Error", log);
|
||||
};
|
||||
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
//// 若参数值超过100个字符则进行截取
|
||||
//foreach (var par in pars)
|
||||
//{
|
||||
// if (par.DbType != System.Data.DbType.String || par.Value == null) continue;
|
||||
// if (par.Value.ToString().Length > 100)
|
||||
// par.Value = string.Concat(par.Value.ToString()[..100], "......");
|
||||
//}
|
||||
|
||||
// 执行时间超过5秒时
|
||||
if (db.Ado.SqlExecutionTime.TotalSeconds > 5)
|
||||
{
|
||||
var fileName = db.Ado.SqlStackTrace.FirstFileName; // 文件名
|
||||
var fileLine = db.Ado.SqlStackTrace.FirstLine; // 行号
|
||||
var firstMethodName = db.Ado.SqlStackTrace.FirstMethodName; // 方法名
|
||||
var log = $"【{DateTime.Now}——超时SQL】\r\n【所在文件名】:{fileName}\r\n【代码行数】:{fileLine}\r\n【方法名】:{firstMethodName}\r\n" + $"【SQL语句】:{UtilMethods.GetNativeSql(sql, pars)}";
|
||||
Log.Warning(log);
|
||||
App.PrintToMiniProfiler("SqlSugar", "Slow", log);
|
||||
}
|
||||
};
|
||||
}
|
||||
// 数据审计
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
// 新增/插入
|
||||
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||
{
|
||||
// 若主键是长整型且空且不是自增类型则赋值雪花Id
|
||||
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
||||
{
|
||||
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||
if (id == null || (long)id == 0)
|
||||
entityInfo.SetValue(YitIdHelper.NextId());
|
||||
}
|
||||
// 若创建时间为空则赋值当前时间
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateTime) && entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue) == null)
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
// 若当前用户非空(web线程时)
|
||||
if (App.User != null)
|
||||
{
|
||||
dynamic entityValue = entityInfo.EntityValue;
|
||||
if (entityInfo.PropertyName == nameof(EntityTenantId.TenantId))
|
||||
{
|
||||
if (entityValue.TenantId == null || entityValue.TenantId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.TenantId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserId))
|
||||
{
|
||||
if (entityValue.CreateUserId == null || entityValue.CreateUserId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.UserId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserName))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entityValue.CreateUserName))
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.RealName)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBaseData.CreateOrgId))
|
||||
{
|
||||
if (entityValue.CreateOrgId == null || entityValue.CreateOrgId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgId)?.Value);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBaseData.CreateOrgName))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entityValue.CreateOrgName))
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgName)?.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 编辑/更新
|
||||
else if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
||||
{
|
||||
if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime))
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserId))
|
||||
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.UserId)?.Value);
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserName))
|
||||
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.RealName)?.Value);
|
||||
}
|
||||
};
|
||||
|
||||
// 超管排除其他过滤器
|
||||
if (App.User?.FindFirst(ClaimConst.AccountType)?.Value == ((int)AccountTypeEnum.SuperAdmin).ToString())
|
||||
return;
|
||||
|
||||
// 配置假删除过滤器
|
||||
db.QueryFilter.AddTableFilter<IDeletedFilter>(u => u.IsDelete == false);
|
||||
|
||||
// 配置租户过滤器
|
||||
var tenantId = App.User?.FindFirst(ClaimConst.TenantId)?.Value;
|
||||
if (!string.IsNullOrWhiteSpace(tenantId))
|
||||
db.QueryFilter.AddTableFilter<ITenantIdFilter>(u => u.TenantId == long.Parse(tenantId));
|
||||
|
||||
// 配置用户机构(数据范围)过滤器
|
||||
SqlSugarFilter.SetOrgEntityFilter(db);
|
||||
|
||||
// 配置自定义过滤器
|
||||
SqlSugarFilter.SetCustomEntityFilter(db);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启库表差异化日志
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="config"></param>
|
||||
private static void SetDbDiffLog(SqlSugarScopeProvider db, DbConnectionConfig config)
|
||||
{
|
||||
if (!config.DbSettings.EnableDiffLog) return;
|
||||
|
||||
db.Aop.OnDiffLogEvent = async u =>
|
||||
{
|
||||
var logDiff = new SysLogDiff
|
||||
{
|
||||
// 操作后记录(字段描述、列名、值、表名、表描述)
|
||||
AfterData = JSON.Serialize(u.AfterData),
|
||||
// 操作前记录(字段描述、列名、值、表名、表描述)
|
||||
BeforeData = JSON.Serialize(u.BeforeData),
|
||||
// 传进来的对象(如果对象为空,则使用首个数据的表名作为业务对象)
|
||||
BusinessData = u.BusinessData == null ? u.AfterData.FirstOrDefault()?.TableName : JSON.Serialize(u.BusinessData),
|
||||
// 枚举(insert、update、delete)
|
||||
DiffType = u.DiffType.ToString(),
|
||||
Sql = UtilMethods.GetNativeSql(u.Sql, u.Parameters),
|
||||
Parameters = JSON.Serialize(u.Parameters),
|
||||
Elapsed = u.Time == null ? 0 : (long)u.Time.Value.TotalMilliseconds
|
||||
};
|
||||
var logDb = ITenant.IsAnyConnection(SqlSugarConst.LogConfigId) ? ITenant.GetConnectionScope(SqlSugarConst.LogConfigId) : db;
|
||||
await logDb.CopyNew().Insertable(logDiff).ExecuteCommandAsync();
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(DateTime.Now + $"\r\n*****开始差异日志*****\r\n{Environment.NewLine}{JSON.Serialize(logDiff)}{Environment.NewLine}*****结束差异日志*****\r\n");
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化数据库
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="config"></param>
|
||||
private static void InitDatabase(SqlSugarScope db, DbConnectionConfig config)
|
||||
{
|
||||
SqlSugarScopeProvider dbProvider = db.GetConnectionScope(config.ConfigId);
|
||||
|
||||
// 初始化/创建数据库
|
||||
if (config.DbSettings.EnableInitDb)
|
||||
{
|
||||
if (config.DbType != SqlSugar.DbType.Oracle)
|
||||
dbProvider.DbMaintenance.CreateDatabase();
|
||||
}
|
||||
|
||||
// 初始化表结构
|
||||
if (config.TableSettings.EnableInitTable)
|
||||
{
|
||||
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false))
|
||||
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any())
|
||||
.WhereIF(config.TableSettings.EnableIncreTable, u => u.IsDefined(typeof(IncreTableAttribute), false)).ToList();
|
||||
|
||||
if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性)
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttributes<SysTableAttribute>().Any() || (!u.GetCustomAttributes<LogTableAttribute>().Any() && !u.GetCustomAttributes<TenantAttribute>().Any())).ToList();
|
||||
else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttributes<LogTableAttribute>().Any()).ToList();
|
||||
else
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库
|
||||
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
|
||||
dbProvider.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
dbProvider.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化种子数据
|
||||
if (config.SeedSettings.EnableInitSeed)
|
||||
{
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false))
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? (u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0] as SeedDataAttribute).Order : 0).ToList();
|
||||
|
||||
foreach (var seedType in seedDataTypes)
|
||||
{
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
|
||||
if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性)
|
||||
{
|
||||
if (entityType.GetCustomAttribute<SysTableAttribute>() == null && (entityType.GetCustomAttribute<LogTableAttribute>() != null || entityType.GetCustomAttribute<TenantAttribute>() != null))
|
||||
continue;
|
||||
}
|
||||
else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库
|
||||
{
|
||||
if (entityType.GetCustomAttribute<LogTableAttribute>() == null)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var att = entityType.GetCustomAttribute<TenantAttribute>(); // 自定义的库
|
||||
if (att == null || att.configId.ToString() != config.ConfigId.ToString()) continue;
|
||||
}
|
||||
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
var hasDataMethod = seedType.GetMethod("HasData");
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
|
||||
if (seedData == null) continue;
|
||||
|
||||
var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType);
|
||||
if (entityInfo.Columns.Any(u => u.IsPrimarykey))
|
||||
{
|
||||
// 按主键进行批量增加和更新
|
||||
var storage = dbProvider.StorageableByObject(seedData.ToList()).ToStorage();
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
|
||||
storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(c => c.PropertyName).ToArray()).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无主键则只进行插入
|
||||
if (!dbProvider.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any())
|
||||
dbProvider.InsertableByObject(seedData.ToList()).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化租户业务数据库
|
||||
/// </summary>
|
||||
/// <param name="iTenant"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void InitTenantDatabase(ITenant iTenant, DbConnectionConfig config)
|
||||
{
|
||||
SetDbConfig(config);
|
||||
|
||||
if (!iTenant.IsAnyConnection(config.ConfigId.ToString()))
|
||||
iTenant.AddConnection(config);
|
||||
var db = iTenant.GetConnectionScope(config.ConfigId.ToString());
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
|
||||
// 初始化租户库表结构-获取所有业务应用表(排除系统表、日志表、特定库表)
|
||||
var entityTypes = App.EffectiveTypes
|
||||
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any())
|
||||
.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) &&
|
||||
!u.IsDefined(typeof(SysTableAttribute), false) && !u.IsDefined(typeof(LogTableAttribute), false) && !u.IsDefined(typeof(TenantAttribute), false)).ToList();
|
||||
if (!entityTypes.Any()) return;
|
||||
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();
|
||||
if (splitTable == null)
|
||||
db.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
db.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
|
||||
// 初始化业务应用种子数据
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.Where(u => u.IsDefined(typeof(AppSeedAttribute), false))
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? (u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0] as SeedDataAttribute).Order : 0).ToList();
|
||||
|
||||
foreach (var seedType in seedDataTypes)
|
||||
{
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
var hasDataMethod = seedType.GetMethod("HasData");
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>().ToList();
|
||||
if (seedData == null) continue;
|
||||
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
||||
var dbConfigId = config.ConfigId.ToLong();
|
||||
// 若实体包含租户Id字段,则设置为当前租户Id
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(EntityTenantId.TenantId)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId)).SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Pid字段,则设置为当前租户Id
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(SysOrg.Pid)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid)).SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Id字段,则设置为当前租户Id递增1
|
||||
if (entityInfo.Columns.Any(u => u.PropertyName == nameof(EntityBaseId.Id)))
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id)).SetValue(sd, ++dbConfigId);
|
||||
}
|
||||
}
|
||||
|
||||
// 若实体是系统内置,则切换至默认库
|
||||
if (entityType.GetCustomAttribute<SysTableAttribute>() != null)
|
||||
db = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
|
||||
|
||||
if (entityInfo.Columns.Any(u => u.IsPrimarykey))
|
||||
{
|
||||
// 按主键进行批量增加和更新
|
||||
var storage = db.StorageableByObject(seedData).ToStorage();
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
|
||||
storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(c => c.PropertyName).ToArray()).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无主键则只进行插入
|
||||
if (!db.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any())
|
||||
db.InsertableByObject(seedData).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,370 +1,409 @@
|
||||
@{
|
||||
var pkField = Model.TableField.Where(c => c.ColumnKey == "True").FirstOrDefault();
|
||||
string pkFieldName = null;
|
||||
if(pkField != null && !string.IsNullOrEmpty(pkField.PropertyName))
|
||||
{
|
||||
pkFieldName = LowerFirstLetter(pkField.PropertyName);
|
||||
}
|
||||
Dictionary<string, int> definedObjects = new Dictionary<string, int>();
|
||||
bool haveLikeCdt = false;
|
||||
foreach (var column in Model.TableField){
|
||||
if (column.QueryWhether == "Y" && column.QueryType == "like"){
|
||||
haveLikeCdt = true;
|
||||
}
|
||||
}
|
||||
string LowerFirstLetter(string text)
|
||||
{
|
||||
return text.ToString()[..1].ToLower() + text[1..]; // 首字母小写
|
||||
}
|
||||
var pkField = Model.TableField.Where(c => c.ColumnKey == "True").FirstOrDefault();
|
||||
string pkFieldName = null;
|
||||
if(pkField != null && !string.IsNullOrEmpty(pkField.PropertyName))
|
||||
{
|
||||
pkFieldName = LowerFirstLetter(pkField.PropertyName);
|
||||
}
|
||||
Dictionary<string, int> definedObjects = new Dictionary<string, int>();
|
||||
bool haveLikeCdt = false;
|
||||
foreach (var column in Model.TableField){
|
||||
if (column.QueryWhether == "Y" && column.QueryType == "like"){
|
||||
haveLikeCdt = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
<template>
|
||||
<div class="@(@Model.LowerClassName)-container">
|
||||
<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
|
||||
@<el-form :model="queryParams" ref="queryForm" labelWidth="90">
|
||||
@<el-row>
|
||||
@if(Model.QueryWhetherList.Count > 0){
|
||||
@if(haveLikeCdt){
|
||||
@:<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
|
||||
@:<el-form-item label="关键字">
|
||||
@:<el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
|
||||
@:
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
}
|
||||
foreach (var column in Model.QueryWhetherList){
|
||||
@:<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
|
||||
if(@column.EffectType == "Input" || @column.EffectType == "InputTextArea"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-input v-model="queryParams.@(@column.LowerPropertyName)" clearable="" placeholder="请输入@(@column.ColumnComment)"/>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "InputTextArea"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-input-number v-model="queryParams.@(@column.LowerPropertyName)" clearable="" placeholder="请输入@(@column.ColumnComment)"/>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "InputNumber"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-input-number v-model="queryParams.@(@column.LowerPropertyName)" clearable="" placeholder="请输入@(@column.ColumnComment)"/>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "fk"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-select clearable="" filterable="" v-model="queryParams.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
@:<el-option v-for="(item,index) in @LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList" :key="index" :value="item.value" :label="item.label" />
|
||||
@:
|
||||
</el-select>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "Select"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-select clearable="" v-model="queryParams.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="item.code" :label="`[${item.code}] ${item.value}`" />
|
||||
@:
|
||||
</el-select>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "EnumSelector"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
@:<el-select clearable="" v-model="queryParams.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="item.value" :label="`${item.name} (${item.code}) [${item.value}] `" />
|
||||
@:
|
||||
</el-select>
|
||||
@:
|
||||
</el-form-item>
|
||||
}else if(@column.EffectType == "DatePicker"){
|
||||
@:<el-form-item label="@column.ColumnComment">
|
||||
if(@column.QueryType == "~"){
|
||||
@:<el-date-picker type="daterange" v-model="queryParams.@(@column.LowerPropertyName)Range" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
|
||||
}else
|
||||
{
|
||||
@:<el-date-picker placeholder="请选择@(@column.ColumnComment)" value-format="YYYY/MM/DD" v-model="queryParams.@(@column.LowerPropertyName)" />
|
||||
}
|
||||
@:
|
||||
</el-form-item>
|
||||
}
|
||||
@:</el-col>
|
||||
}
|
||||
}
|
||||
@<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
|
||||
@<el-form-item @(Model.QueryWhetherList.Count > 0?"":"label-width=\"0px\"")>
|
||||
@<el-button-group style="display: flex; align-items: center;">
|
||||
@<el-button type="primary" icon="ele-Search" @@click="handleQuery" v-auth="'@(@Model.LowerClassName):page'"> @(Model.QueryWhetherList.Count > 0?"查询":"刷新") </el-button>
|
||||
@if(Model.QueryWhetherList.Count > 0){
|
||||
@:<el-button icon="ele-Refresh" @@click="() => queryParams = {}"> 重置 </el-button>
|
||||
@if(haveLikeCdt){
|
||||
@:<el-button icon="ele-ZoomIn" @@click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
|
||||
@:<el-button icon="ele-ZoomOut" @@click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
|
||||
}
|
||||
<div class="@(@Model.LowerEntityName)-container" v-loading="options.loading">
|
||||
<el-card shadow="hover" :body-style="{ padding: '20px 20px 16px 0px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
|
||||
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" :label-width="'60px'" style="flex: 1 1 0%">
|
||||
<el-row :gutter="10">
|
||||
@if(Model.QueryWhetherList.Count > 0){
|
||||
foreach (var column in Model.QueryWhetherList) {
|
||||
if(@column.EffectType == "Input" || @column.EffectType == "InputTextArea") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
<el-input v-model="state.queryParams.@(@column.LowerPropertyName)" placeholder="@column.ColumnComment" clearable @@keyup.enter.native="handleQuery(true)" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
} else if(@column.EffectType == "InputNumber") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment">
|
||||
<el-input-number v-model="state.queryParams.@(@column.LowerPropertyName)" clearable placeholder="请输入@(@column.ColumnComment)" @@keyup.enter.native="handleQuery(true)" >
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
} else if(@column.EffectType == "fk") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment">
|
||||
<el-select clearable="" filterable="" v-model="state.queryParams.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
<el-option v-for="(item,index) in @LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList" :key="index" :value="item.value" :label="item.label" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
} else if(@column.EffectType == "Select") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
<el-select v-model="state.queryParams.@(@column.LowerPropertyName)" filterable clearable placeholder="请选择@(@column.ColumnComment)" @@keyup.enter.native="handleQuery(true)" >
|
||||
<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="item.code" :label="`${item.name} [${item.code}] ${item.value}`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
} else if(@column.EffectType == "EnumSelector") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
<el-select v-model="state.queryParams.@(@column.LowerPropertyName)" filterable clearable placeholder="请选择@(@column.ColumnComment)" @@keyup.enter.native="handleQuery(true)" >
|
||||
<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="item.value" :label="`${item.name} [${item.code}] ${item.value}`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
} else if(@column.EffectType == "DatePicker") {
|
||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
@if(@column.QueryType == "~"){
|
||||
@:<el-date-picker type="daterange" v-model="state.queryParams.@(@column.LowerPropertyName)Range" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
|
||||
} else {
|
||||
@:<el-date-picker placeholder="请选择@(@column.ColumnComment)" value-format="YYYY/MM/DD" v-model="state.queryParams.@(@column.LowerPropertyName)" />
|
||||
}
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
}
|
||||
}
|
||||
}
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />
|
||||
|
||||
<el-row>
|
||||
<el-col>
|
||||
<el-button-group>
|
||||
<el-button type="primary" icon="ele-Search" @@click="handleQuery(true)" v-auth="'@(@Model.LowerEntityName):page'" :loading="options.loading"> 查询 </el-button>
|
||||
<el-button icon="ele-Refresh" @@click="resetQuery" :loading="options.loading"> 重置 </el-button>
|
||||
</el-button-group>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
||||
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @@sort-change="sortChange">
|
||||
<template #toolbar_buttons>
|
||||
<el-button type="primary" icon="ele-Plus" @@click="handleAdd" v-auth="'@(@Model.LowerEntityName):add'"> 新增 </el-button>
|
||||
</template>
|
||||
<template #toolbar_tools> </template>
|
||||
<template #empty>
|
||||
<el-empty :image-size="200" />
|
||||
</template>
|
||||
@foreach (var column in Model.TableField) {
|
||||
if(@column.WhetherTable == "Y") {
|
||||
if(@column.EffectType == "Upload") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<el-image style="width: 60px; height: 60px" :src="fetchFileUrl(row)" alt="无法预览" lazy hide-on-click-modal :preview-src-list="[fetchFileUrl(row)]" :initial-index="0" fit="scale-down" preview-teleported></el-image>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "fk") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<span>{{ row.@LowerFirstLetter(@column.PropertyName)@(@column.FkColumnName) }}</span>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "ApiTreeSelect") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<span>{{ row.@LowerFirstLetter(@column.PropertyName)@(column.DisplayColumn) }}</span>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "Switch") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<el-tag v-if="row.@(@column.LowerPropertyName)"> 是 </el-tag>
|
||||
@:<el-tag type="danger" v-else> 否 </el-tag>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "ConstSelector") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<span>{{codeToName(row.@(@column.LowerPropertyName), '@(@column.DictTypeCode)')}}</span>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "Select") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<el-tag :type="di('@(@column.DictTypeCode)', row.@(@column.LowerPropertyName))?.tagType"> {{dv('@(@column.DictTypeCode)', row.@column.LowerPropertyName)?.name}}</el-tag>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "EnumSelector") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<el-tag :type="dv('@(@column.DictTypeCode)', row.@(@column.LowerPropertyName))?.tagType"> {{dv('@(@column.DictTypeCode)', row.@column.LowerPropertyName)?.name}}</el-tag>
|
||||
@:</template>
|
||||
} else if(@column.EffectType == "DatePicker") {
|
||||
@:<template #row_@(@column.LowerPropertyName)="{ row }">
|
||||
@:<span>{{ formatDate(new Date(row.@(@column.LowerPropertyName)), 'YYYY-mm-dd') }}</span>
|
||||
@:</template>
|
||||
}
|
||||
}
|
||||
@<el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @@click="openAdd@(@Model.ClassName)" v-auth="'@(@Model.LowerClassName):add'"> 新增 </el-button>
|
||||
@
|
||||
</el-button-group>
|
||||
</el-form-item>
|
||||
@
|
||||
@</el-col>
|
||||
</el-row>
|
||||
@* 操作区另起一行
|
||||
@:<el-row>
|
||||
@:<el-col>
|
||||
@:<el-button-group style="margin-left:20px;margin-bottom:5px;">
|
||||
@:<el-button type="primary" icon="ele-Plus" @@click="openAdd@(@Model.ClassName)" v-auth="'@(@Model.LowerClassName):add'"> 新增 </el-button>
|
||||
</el-button-group>
|
||||
@:</el-col>
|
||||
</el-row>
|
||||
*@
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 100%"
|
||||
v-loading="loading"
|
||||
tooltip-effect="light"
|
||||
@if(@pkFieldName != null)
|
||||
{
|
||||
@:row-key="@(@pkFieldName)"
|
||||
}
|
||||
@@sort-change="sortChange"
|
||||
border="">
|
||||
<el-table-column type="index" label="序号" width="55" align="center"/>
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.WhetherTable == "Y"){
|
||||
if(@column.EffectType == "Upload"||@column.EffectType == "fk"||@column.EffectType == "ApiTreeSelect"||@column.EffectType == "Switch"||@column.EffectType == "ConstSelector"){
|
||||
@:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="">
|
||||
@:<template #default="scope">
|
||||
if(@column.EffectType == "Upload"){
|
||||
@:<el-image
|
||||
@:v-if="scope.row.@column.LowerPropertyName"
|
||||
@:style="width: 60px; height: 60px"
|
||||
@::src="scope.row.@column.LowerPropertyName"
|
||||
@::lazy="true"
|
||||
@::hide-on-click-modal="true"
|
||||
@::preview-src-list="[scope.row.@column.LowerPropertyName]"
|
||||
@::initial-index="0"
|
||||
@:fit="scale-down"
|
||||
@:preview-teleported=""/>
|
||||
}else if(@column.EffectType == "fk"){
|
||||
@:<span>{{scope.row.@LowerFirstLetter(@column.PropertyName)@(@column.FkColumnName)}}</span>
|
||||
}else if(@column.EffectType == "ApiTreeSelect"){
|
||||
@:<span>{{scope.row.@LowerFirstLetter(@column.PropertyName)@(column.DisplayColumn)}}</span>
|
||||
}else if(@column.EffectType == "Switch"){
|
||||
@:<el-tag v-if="scope.row.@(@column.LowerPropertyName)"> 是 </el-tag>
|
||||
@:<el-tag type="danger" v-else> 否 </el-tag>
|
||||
}else if(@column.EffectType == "ConstSelector"){
|
||||
@:<span>{{codeToName(scope.row.@(@column.LowerPropertyName), '@(@column.DictTypeCode)')}}</span>
|
||||
}
|
||||
@:
|
||||
</template>
|
||||
@:
|
||||
</el-table-column>
|
||||
}
|
||||
else if(@column.EffectType == "Select"){
|
||||
@:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" >
|
||||
@:<template #default="scope">
|
||||
@:<el-tag :type="di('@(@column.DictTypeCode)', scope.row.@(@column.LowerPropertyName))?.tagType"> {{di("@(@column.DictTypeCode)", scope.row.@(@column.LowerPropertyName))?.value}} </el-tag>
|
||||
@:</template>
|
||||
@:</el-table-column>
|
||||
}
|
||||
else if(@column.EffectType == "EnumSelector"){
|
||||
@:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" >
|
||||
@:<template #default="scope">
|
||||
@:<el-tag :type="dv('@(@column.DictTypeCode)', scope.row.@(@column.LowerPropertyName))?.tagType"> {{dv('@(@column.DictTypeCode)', scope.row.@column.LowerPropertyName)?.name}}</el-tag>
|
||||
@:</template>
|
||||
@:</el-table-column>
|
||||
}
|
||||
else {
|
||||
@:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" />
|
||||
}
|
||||
}
|
||||
}
|
||||
@if(@Model.PrintType == "custom"){
|
||||
@:<el-table-column label="操作" width="200" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('@(@Model.LowerClassName):update') || auth('@(@Model.LowerClassName):delete')">
|
||||
@:<template #default="scope">
|
||||
@:<el-button icon="ele-Printer" size="small" text="" type="primary" @@click="openPrint@(@Model.ClassName)(scope.row)" v-auth="'@(@Model.LowerClassName):print'"> 打印 </el-button>
|
||||
}else{
|
||||
@:<el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('@(@Model.LowerClassName):update') || auth('@(@Model.LowerClassName):delete')">
|
||||
@:<template #default="scope">
|
||||
}
|
||||
<el-button icon="ele-Edit" size="small" text="" type="primary" @@click="openEdit@(@Model.ClassName)(scope.row)" v-auth="'@(@Model.LowerClassName):update'"> 编辑 </el-button>
|
||||
<el-button icon="ele-Delete" size="small" text="" type="primary" @@click="del@(@Model.ClassName)(scope.row)" v-auth="'@(@Model.LowerClassName):delete'"> 删除 </el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-model:currentPage="tableParams.page"
|
||||
v-model:page-size="tableParams.pageSize"
|
||||
:total="tableParams.total"
|
||||
:page-sizes="[10, 20, 50, 100, 200, 500]"
|
||||
size="small"
|
||||
background=""
|
||||
@@size-change="handleSizeChange"
|
||||
@@current-change="handleCurrentChange"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
/>
|
||||
<printDialog
|
||||
ref="printDialogRef"
|
||||
:title="print@(@Model.ClassName)Title"
|
||||
@@reloadTable="handleQuery" />
|
||||
<editDialog
|
||||
ref="editDialogRef"
|
||||
:title="edit@(@Model.ClassName)Title"
|
||||
@@reloadTable="handleQuery"
|
||||
/>
|
||||
</el-card>
|
||||
</div>
|
||||
<template #row_record="{ row }">
|
||||
<ModifyRecord :data="row" />
|
||||
</template>
|
||||
<template #row_buttons="{ row }">
|
||||
@if(@Model.PrintType == "custom") {
|
||||
<el-tooltip content="打印" placement="top">
|
||||
<el-button icon="ele-Printer" size="small" text type="primary" @@click="handlePrint(row)" v-auth="'@(@Model.LowerEntityName):print'" :disabled="row.status === 1" />
|
||||
</el-tooltip>
|
||||
}
|
||||
<el-tooltip content="编辑" placement="top">
|
||||
<el-button icon="ele-Edit" size="small" text type="primary" @@click="handleEdit(row)" v-auth="'@(@Model.LowerEntityName):update'" :disabled="row.status === 1" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button icon="ele-Delete" size="small" text type="danger" @@click="handleDelete(row)" v-auth="'@(@Model.LowerEntityName):delete'" :disabled="row.status === 1" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template #pager>
|
||||
<vxe-pager
|
||||
:loading="options.loading"
|
||||
v-model:current-page="state.tableParams.page"
|
||||
v-model:page-size="state.tableParams.pageSize"
|
||||
:total="state.tableParams.total"
|
||||
@@page-change="pageChange"
|
||||
/>
|
||||
</template>
|
||||
</vxe-grid>
|
||||
</el-card>
|
||||
|
||||
<PrintDialog ref="printDialogRef" :title="state.title" @@reloadTable="handleQuery" />
|
||||
<EditDialog ref="editDialogRef" :title="state.title" @@reloadTable="handleQuery" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup="" name="@(@Model.LowerClassName)">
|
||||
import { ref } from "vue";
|
||||
import { ElMessageBox, ElMessage } from "element-plus";
|
||||
import { auth } from '/@@/utils/authFunction';
|
||||
<script lang="ts" setup name="@(@Model.LowerEntityName)">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { ElMessageBox, ElMessage } from "element-plus";
|
||||
import { auth } from '/@@/utils/authFunction';
|
||||
import { VxeGridInstance, VxePagerEvents, VxePagerDefines } from 'vxe-table';
|
||||
import { useVxeTable } from '/@@/hooks/vxeTableOptionsHook';
|
||||
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "ConstSelector")){
|
||||
@:import { codeToName, getConstType } from "/@@/utils/constHelper";
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "Select") || @Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:import { getDictDataItem as di, getDictDataList as dl } from '/@@/utils/dict-utils';
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:import { getDictLabelByVal as dv } from '/@@/utils/dict-utils';
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "DatePicker")){
|
||||
@:import { formatDate } from '/@@/utils/formatTime';
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "ConstSelector")){
|
||||
@:import { codeToName, getConstType } from "/@@/utils/constHelper";
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "Select") || @Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:import { getDictDataItem as di, getDictDataList as dl } from '/@@/utils/dict-utils';
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:import { getDictLabelByVal as dv } from '/@@/utils/dict-utils';
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "DatePicker")){
|
||||
@:import { formatDate } from '/@@/utils/formatTime';
|
||||
}
|
||||
|
||||
@if(@Model.PrintType == "custom"){
|
||||
@:// 推荐设置操作 width 为 200
|
||||
@:import { hiprint } from 'vue-plugin-hiprint';
|
||||
@:import { SysPrintApi } from '/@@/api-services/api';
|
||||
@:import { SysPrint } from '/@@/api-services/models';
|
||||
}
|
||||
|
||||
import printDialog from '/@@/views/system/print/component/hiprint/preview.vue'
|
||||
import editDialog from '/@@/views/@(@Model.PagePath)/@(@Model.LowerClassName)/component/editDialog.vue'
|
||||
import { page@(@Model.ClassName), delete@(@Model.ClassName) } from '/@@/api/@(@Model.PagePath)/@(@Model.LowerClassName)';
|
||||
@foreach (var column in Model.QueryWhetherList){
|
||||
if(@column.EffectType == "fk"){
|
||||
@:import { get@(@column.FkEntityName)@(@column.PropertyName)Dropdown } from '/@@/api/@(@Model.PagePath)/@(@Model.LowerClassName)';
|
||||
}
|
||||
}
|
||||
@if(@Model.QueryWhetherList.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:import { getAPI } from '/@@/utils/axios-utils';
|
||||
@:import { SysEnumApi } from '/@@/api-services/api';
|
||||
@:import commonFunction from '/@@/utils/commonFunction';
|
||||
@foreach (var column in Model.TableField) {
|
||||
@if(@column.WhetherTable == "Y") {
|
||||
import { SysFile } from '/@@/api-services/models';
|
||||
}
|
||||
}
|
||||
|
||||
@if(haveLikeCdt){
|
||||
@:const showAdvanceQueryUI = ref(false);
|
||||
}else {
|
||||
@:const showAdvanceQueryUI = ref(true);
|
||||
}
|
||||
const printDialogRef = ref();
|
||||
const editDialogRef = ref();
|
||||
const loading = ref(false);
|
||||
const tableData = ref<any>([]);
|
||||
const queryParams = ref<any>({});
|
||||
const tableParams = ref({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
import { newValue } from '/@@/utils/desensitization';
|
||||
|
||||
const print@(@Model.ClassName)Title = ref("");
|
||||
const edit@(@Model.ClassName)Title = ref("");
|
||||
@if(@Model.PrintType != "off"){
|
||||
@:// 推荐设置操作 width 为 200
|
||||
@:import { hiprint } from 'vue-plugin-hiprint';
|
||||
@:import { SysPrintApi } from '/@@/api-services/api';
|
||||
@:import { SysPrint } from '/@@/api-services/models';
|
||||
}
|
||||
// 子窗口
|
||||
import PrintDialog from '/@@/views/system/print/component/hiprint/preview.vue';
|
||||
import EditDialog from '/@@/views/@(@Model.PagePath)/@(@Model.LowerEntityName)/component/editDialog.vue';
|
||||
import ModifyRecord from '/@@/components/table/modifyRecord.vue';
|
||||
|
||||
// 改变高级查询的控件显示状态
|
||||
const changeAdvanceQueryUI = () => {
|
||||
showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
|
||||
}
|
||||
// 接口函数
|
||||
import { getAPI } from '/@@/utils/axios-utils';
|
||||
|
||||
// 查询操作
|
||||
const handleQuery = async () => {
|
||||
loading.value = true;
|
||||
var res = await page@(@Model.ClassName)(Object.assign(queryParams.value, tableParams.value));
|
||||
tableData.value = res.data.result?.items ?? [];
|
||||
tableParams.value.total = res.data.result?.total;
|
||||
loading.value = false;
|
||||
};
|
||||
// 接口
|
||||
import { @(@Model.EntityName)Api } from '/@@/api-services/api';
|
||||
|
||||
// 列排序
|
||||
const sortChange = async (column: any) => {
|
||||
queryParams.value.field = column.prop;
|
||||
queryParams.value.order = column.order;
|
||||
// 模型
|
||||
import { @(@Model.EntityName), @(@Model.EntityName)Input, @(@Model.EntityName)Output } from '/@@/api-services/models';
|
||||
|
||||
// 子窗口对象
|
||||
const xGrid = ref<VxeGridInstance>();
|
||||
const printDialogRef = ref<InstanceType<typeof PrintDialog>>();
|
||||
const editDialogRef = ref<InstanceType<typeof EditDialog>>();
|
||||
|
||||
// 变量
|
||||
const state = reactive({
|
||||
queryParams: {
|
||||
@if(Model.QueryWhetherList.Count > 0) {
|
||||
@foreach (var column in Model.QueryWhetherList) {
|
||||
@:@(@column.LowerPropertyName): undefined,
|
||||
}
|
||||
}
|
||||
},
|
||||
tableParams: {
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
field: 'id', // 默认的排序字段
|
||||
order: 'aes', // 排序方向
|
||||
descStr: 'desc', // 降序排序的关键字符
|
||||
total: 0 as any,
|
||||
},
|
||||
visible: false,
|
||||
title: '',
|
||||
});
|
||||
|
||||
// 表格参数配置
|
||||
const options = useVxeTable<@(@Model.EntityName)>({
|
||||
id: '@(@Model.EntityName)',
|
||||
name: '@(@Model.BusName)',
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
|
||||
@foreach (var column in Model.TableField) {
|
||||
if(@column.WhetherTable == "Y") {
|
||||
if(@column.EffectType == "Upload" || @column.EffectType == "fk" || @column.EffectType == "ApiTreeSelect" || @column.EffectType == "Switch" || @column.EffectType == "ConstSelector") {
|
||||
if(@column.EffectType == "Upload") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "fk") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "ApiTreeSelect") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "Switch") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "ConstSelector") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
}
|
||||
} else if(@column.EffectType == "Select") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "EnumSelector") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else if(@column.EffectType == "DatePicker") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_@column.LowerPropertyName' } },
|
||||
} else {
|
||||
if(@column.LowerPropertyName != "remark") {
|
||||
@:{ field: '@column.LowerPropertyName', title: '@column.ColumnComment', minWidth: 100, showOverflow: 'tooltip' },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
|
||||
{ title: '操作', fixed: 'right', width: 180, showOverflow: true, slots: { default: 'row_buttons' } },
|
||||
],
|
||||
enableExport: auth('@(@Model.LowerEntityName):export'),
|
||||
searchCallback: () => handleQuery(),
|
||||
queryAllCallback: () => fetchData({ pageSize: 99999 }),
|
||||
});
|
||||
|
||||
// 页面初始化
|
||||
onMounted(async () => {
|
||||
await handleQuery();
|
||||
};
|
||||
});
|
||||
|
||||
// 打开新增页面
|
||||
const openAdd@(@Model.ClassName) = () => {
|
||||
edit@(@Model.ClassName)Title.value = '添加@(@Model.BusName)';
|
||||
editDialogRef.value.openDialog({});
|
||||
};
|
||||
// 查询操作
|
||||
const handleQuery = async (reset = false) => {
|
||||
options.loading = true;
|
||||
if (reset) state.tableParams.page = 1;
|
||||
var res = await fetchData(null);
|
||||
xGrid.value?.loadData(res.data.result?.items ?? []);
|
||||
state.tableParams.total = res.data.result?.total;
|
||||
options.loading = false;
|
||||
};
|
||||
|
||||
// 打开打印页面
|
||||
const openPrint@(@Model.ClassName) = async (row: any) => {
|
||||
print@(@Model.ClassName)Title.value = '打印@(@Model.BusName)';
|
||||
// 获取数据
|
||||
const fetchData = async (tableParams: any) => {
|
||||
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
|
||||
return getAPI(@(@Model.EntityName)Api).api@(@Model.EntityName)PagePost(params);
|
||||
};
|
||||
|
||||
// 重置操作
|
||||
const resetQuery = () => {
|
||||
@if(Model.QueryWhetherList.Count > 0) {
|
||||
@foreach (var column in Model.QueryWhetherList) {
|
||||
@:state.queryParams.@(@column.LowerPropertyName) = undefined,
|
||||
}
|
||||
}
|
||||
handleQuery(true);
|
||||
};
|
||||
|
||||
// 改变页码序号或页面容量
|
||||
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
|
||||
state.tableParams.page = currentPage;
|
||||
state.tableParams.pageSize = pageSize;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
// 列排序
|
||||
const sortChange = (options: any) => {
|
||||
state.tableParams.field = options.field;
|
||||
state.tableParams.order = options.order;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
// 打开新增页面
|
||||
const handleAdd = () => {
|
||||
state.title = '添加@(@Model.BusName)';
|
||||
editDialogRef.value?.openDialog({ type: 1 });
|
||||
};
|
||||
|
||||
// 打开编辑页面
|
||||
const handleEdit = (row: any) => {
|
||||
state.title = '编辑@(@Model.BusName)';
|
||||
editDialogRef.value?.openDialog(row);
|
||||
};
|
||||
|
||||
// 打开打印页面
|
||||
const handlePrint = async (row: any) => {
|
||||
state.title = '打印@(@Model.BusName)';
|
||||
@if(@Model.PrintType == "custom"){
|
||||
@:var res = await getAPI(SysPrintApi).apiSysPrintPrintNameGet('@Model.PrintName');
|
||||
@:var printTemplate = res.data.result as SysPrint;
|
||||
@:var printTemplate = res.data.result as SysPrint;
|
||||
@:var template = JSON.parse(printTemplate.template);
|
||||
@:row['printDate'] = formatDate(new Date(), 'YYYY-mm-dd HH:MM:SS')
|
||||
@:printDialogRef.value.showDialog(new hiprint.PrintTemplate({template: template}), row, template.panels[0].width);
|
||||
@:var width = template.panels[0].width;
|
||||
@:row['barCode'] = row.code;
|
||||
@:row['qrCode'] = row.code;
|
||||
@:row["printDate"] = formatDate(new Date(), 'YYYY-mm-dd HH:MM');
|
||||
@:printDialogRef.value.showDialog(new hiprint.PrintTemplate({template: template}), row, width);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开编辑页面
|
||||
const openEdit@(@Model.ClassName) = (row: any) => {
|
||||
edit@(@Model.ClassName)Title.value = '编辑@(@Model.BusName)';
|
||||
editDialogRef.value.openDialog(row);
|
||||
};
|
||||
@if(@Model.PrintType == "auto"){
|
||||
@:printDialogRef.value.showDialog(row);
|
||||
}
|
||||
};
|
||||
|
||||
// 删除
|
||||
const del@(@Model.ClassName) = (row: any) => {
|
||||
ElMessageBox.confirm(`确定要删除吗?`, "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
})
|
||||
.then(async () => {
|
||||
await delete@(@Model.ClassName)(row);
|
||||
handleQuery();
|
||||
ElMessage.success("删除成功");
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
// 删除
|
||||
const handleDelete = (row: any) => {
|
||||
ElMessageBox.confirm(`确定删除@(@Model.BusName):【${row.title}】?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(async () => {
|
||||
await getAPI(@(@Model.EntityName)Api).api@(@Model.EntityName)DeletePost({ id: row.id });
|
||||
handleQuery();
|
||||
ElMessage.success('删除成功');
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
// 改变页面容量
|
||||
const handleSizeChange = (val: number) => {
|
||||
tableParams.value.pageSize = val;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
// 改变页码序号
|
||||
const handleCurrentChange = (val: number) => {
|
||||
tableParams.value.page = val;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
@foreach (var column in Model.QueryWhetherList){
|
||||
if(@column.EffectType == "fk"){
|
||||
@:const @LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList = ref<any>([]);
|
||||
@:const get@(@column.FkEntityName)@(@column.PropertyName)DropdownList = async () => {
|
||||
@:let list = await get@(@column.FkEntityName)@(@column.PropertyName)Dropdown();
|
||||
@foreach (var column in Model.QueryWhetherList) {
|
||||
@if(@column.EffectType == "fk") {
|
||||
@:const @LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList = ref<any>([]);
|
||||
@:const get@(@column.FkEntityName)@(@column.PropertyName)DropdownList = async () => {
|
||||
//@:let list = await get@(@column.FkEntityName)@(@column.PropertyName)Dropdown();
|
||||
@:let list = await getAPI(@(@Model.EntityName)Api).api@(@Model.EntityName)@(@column.FkEntityName)@(@column.PropertyName)DropdownGet();
|
||||
@:@LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList.value = list.data.result ?? [];
|
||||
@:};
|
||||
@:get@(@column.FkEntityName)@(@column.PropertyName)DropdownList();
|
||||
@:
|
||||
}
|
||||
@:};
|
||||
@:get@(@column.FkEntityName)@(@column.PropertyName)DropdownList();
|
||||
}
|
||||
}
|
||||
|
||||
@foreach (var column in Model.TableField) {
|
||||
@if(@column.WhetherTable == "Y") {
|
||||
@if(@column.EffectType == "Upload") {
|
||||
@:// 获取文件地址
|
||||
@:const fetchFileUrl = (row: SysFile): string => {
|
||||
@:if (row.bucketName == 'Local') {
|
||||
@:return `/${row.filePath}/${row.id}${row.suffix}`;
|
||||
@:} else {
|
||||
@:return row.url!;
|
||||
@:}
|
||||
@:};
|
||||
}
|
||||
}
|
||||
}
|
||||
handleQuery();
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-input),
|
||||
:deep(.el-select),
|
||||
:deep(.el-input-number) {
|
||||
width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@{
|
||||
string LowerFirstLetter(string text)
|
||||
{
|
||||
return text.ToString()[..1].ToLower() + text[1..]; // 首字母小写
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user