diff --git a/docs/demo/src/WTA.Application/Identity/Data/IdentityDbSeed.cs b/docs/demo/src/WTA.Application/Identity/Data/IdentityDbSeed.cs index 7c81389c..1de5c05a 100644 --- a/docs/demo/src/WTA.Application/Identity/Data/IdentityDbSeed.cs +++ b/docs/demo/src/WTA.Application/Identity/Data/IdentityDbSeed.cs @@ -119,18 +119,18 @@ public class IdentityDbSeed : IDbSeed context.Set().Add(superUser); } - private void InitTestDate(IdentityDbContext context) + private static void InitTestDate(IdentityDbContext context) { context.Set().Add(new HBPO_SA { Version = "测试数据", BillNum = "123", DNBillNum = "测试数据", State = "测试数据", RecordCount = "测试数据" }); context.Set().Add(new HBPO_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据" }); context.Set().Add(new BBAC_SA { Version = "测试数据", BillNum = "123", DNBillNum = "测试数据", State = "测试数据", RecordCount = "测试数据" }); context.Set().Add(new BBAC_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据", Category = "测试数据", IsReturn = "测试数据" }); context.Set().Add(new JIT_SA { Version = "测试数据", BillNum = "123", DNBillNum = "测试数据", State = "测试数据", RecordCount = "测试数据" }); - context.Set().Add(new JIT_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据" }); + context.Set().Add(new JIT_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据" }); context.Set().Add(new BJ_SA { Version = "测试数据", BillNum = "123", DNBillNum = "测试数据", State = "测试数据", RecordCount = "测试数据" }); context.Set().Add(new BJ_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据" }); context.Set().Add(new IN_SA { Version = "测试数据", BillNum = "123", DNBillNum = "测试数据", State = "测试数据" }); - context.Set().Add(new IN_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PU = "测试数据", Site = "测试数据",SettleDate = new DateTime(), GroupNum = "测试数据" }); + context.Set().Add(new IN_SA_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PU = "测试数据", Site = "测试数据", SettleDate = new DateTime(), GroupNum = "测试数据" }); context.Set().Add(new HBPO_DN { Version = "测试数据", DNBillNum = "123", StockCount = "测试数据" }); context.Set().Add(new HBPO_DN_DETAIL { KeyCode = "测试数据", Version = "测试数据", BillNum = "123", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), State = "测试数据", INVGroupNum = "测试数据", GroupNum = "测试数据", DNBillNum = "测试数据" }); context.Set().Add(new BBAC_DN { Version = "测试数据", DNBillNum = "123", StockCount = "测试数据" }); @@ -140,13 +140,43 @@ public class IdentityDbSeed : IDbSeed context.Set().Add(new BJ_DN { Version = "测试数据", DNBillNum = "123", StockCount = "测试数据" }); context.Set().Add(new BJ_DN_DETAIL { KeyCode = "测试数据", Version = "测试数据", LU = "测试数据", PN = "测试数据", Site = "测试数据", SettleDate = new DateTime(), State = "测试数据", INVGroupNum = "测试数据", GroupNum = "测试数据", DNBillNum = "测试数据" }); context.Set().Add(new IN_DN { Version = "测试数据", DNBillNum = "123", StockCount = "测试数据" }); - context.Set().Add(new IN_DN_DETAIL { KeyCode = "测试数据", Version = "测试数据", LU = "测试数据", PU = "测试数据", Site = "测试数据", SettleDate = new DateTime(), State = "测试数据", INVGroupNum = "测试数据", GroupNum = "测试数据", DNBillNum = "测试数据" }); - context.Set().Add(new INVOICE { RealnvBillNum = "测试数据", InvbillNum = "123", INVGroupNum = "测试数据", FileName ="测试数据",BusinessType="测试数据"}); - context.Set().Add(new INVOICE_DETAIL { LU = "测试数据", InvbillNum = "123"}); + context.Set().Add(new IN_DN_DETAIL { KeyCode = "测试数据", Version = "测试数据", LU = "测试数据", PU = "测试数据", Site = "测试数据", SettleDate = new DateTime(), State = "测试数据", INVGroupNum = "测试数据", GroupNum = "测试数据", DNBillNum = "测试数据" }); + context.Set().Add(new INVOICE { RealnvBillNum = "测试数据", InvbillNum = "123", INVGroupNum = "测试数据", FileName = "测试数据", BusinessType = "测试数据" }); + context.Set().Add(new INVOICE_DETAIL { LU = "测试数据", InvbillNum = "123" }); } - private void InitDictionaries(DbContext context) + private static void InitDictionaries(DbContext context) { + context.Set().Add(new DictionaryItem + { + Name = "测试1", + Number = "test1", + Children = new List { + new DictionaryItem{ + Name="测试1.1", + Number="test1.1", + }, + new DictionaryItem{ + Name="测试1.2", + Number="test1.2", + } + } + }.UpdateId()); + context.Set().Add(new DictionaryItem + { + Name = "测试2", + Number = "test2", + Children = new List { + new DictionaryItem{ + Name="测试2.1", + Number="test2.1", + }, + new DictionaryItem{ + Name="测试2.2", + Number="test2.2", + } + } + }.UpdateId()); } private void InitPermissions(DbContext context) diff --git a/docs/demo/src/WTA.Shared/Attributes/ManyToManyAttribute.cs b/docs/demo/src/WTA.Shared/Attributes/ManyToManyAttribute.cs new file mode 100644 index 00000000..a9b3114c --- /dev/null +++ b/docs/demo/src/WTA.Shared/Attributes/ManyToManyAttribute.cs @@ -0,0 +1,14 @@ +namespace WTA.Shared.Attributes; + +[AttributeUsage(AttributeTargets.Property)] +public class ManyToManyAttribute : Attribute, ITypeAttribute +{ + public Type Type { get; set; } = null!; + public string? Property { get; } + + public ManyToManyAttribute(string? property = null) + { + this.Type = typeof(TEntity); + this.Property = property; + } +} diff --git a/docs/demo/src/WTA.Shared/Attributes/ManyToOneAttribute.cs b/docs/demo/src/WTA.Shared/Attributes/ManyToOneAttribute.cs new file mode 100644 index 00000000..15c0a185 --- /dev/null +++ b/docs/demo/src/WTA.Shared/Attributes/ManyToOneAttribute.cs @@ -0,0 +1,14 @@ +namespace WTA.Shared.Attributes; + +[AttributeUsage(AttributeTargets.Property)] +public class ManyToOneAttribute : Attribute, ITypeAttribute +{ + public Type Type { get; set; } = null!; + public string? Property { get; } + + public ManyToOneAttribute(string? property = null) + { + this.Type = typeof(TEntity); + this.Property = property; + } +} diff --git a/docs/demo/src/WTA.Shared/Controllers/GenericController.cs b/docs/demo/src/WTA.Shared/Controllers/GenericController.cs index 02482cba..12960a6a 100644 --- a/docs/demo/src/WTA.Shared/Controllers/GenericController.cs +++ b/docs/demo/src/WTA.Shared/Controllers/GenericController.cs @@ -38,13 +38,14 @@ public class GenericController model) { - var query = BuildQuery(model); + var isTree = typeof(TEntity).IsAssignableTo(typeof(BaseTreeEntity)); + var query = BuildQuery(model, isTree); model.TotalCount = query.Count(); if (!string.IsNullOrEmpty(model.OrderBy)) { query = query.OrderBy(model.OrderBy); } - if (model.QueryAll) + if (model.QueryAll || isTree) { model.PageSize = model.TotalCount; } @@ -59,9 +60,8 @@ public class GenericController BuildQuery(PaginationModel model) + protected virtual IQueryable BuildQuery(PaginationModel model, bool isTree) { - var isTree = typeof(TEntity).IsAssignableTo(typeof(BaseTreeEntity)); var query = this.Repository.AsNoTracking(); query = query.Include(); if (model.Query != null) @@ -181,8 +181,9 @@ public class GenericController)); + var query = this.BuildQuery(model, isTree); + if (!includeAll && !isTree) { query = query.Skip(model.PageSize * (model.PageIndex - 1)).Take(model.PageSize); } diff --git a/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs b/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs index 9acf0dc3..fe319b65 100644 --- a/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs +++ b/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs @@ -75,6 +75,10 @@ public static class JsonSchemaExtensions if (!modelType.IsValueType && modelType != typeof(string)) { schema.Add("type", "object"); + if (modelType.GetBaseClasses().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(BaseTreeEntity<>))) + { + schema.Add("isTree", true); + } var properties = new Dictionary(); foreach (var propertyMetadata in meta.Properties) { @@ -151,11 +155,11 @@ public static class JsonSchemaExtensions path = string.Join('.', path.Split('.').Select(o => o.ToLowerCamelCase())); schema.Add("navigation", path); schema.Add("input", "select"); - schema.Add("url", propertyName[..^2].ToSlugify()); + schema.Add("url", defaultModelMetadata.ContainerType?.GetProperty(propertyName[..^2])?.PropertyType.Name.ToSlugify()!); } if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType().IsGenericType && o.GetType().GetGenericTypeDefinition() == typeof(OneToManyAttribute<>)) is ITypeAttribute oneToManyAttribute) { - schema.Add("oneToMany",$"{oneToManyAttribute.Type.Name}.{oneToManyAttribute.GetType().GetProperty("Property")?.GetValue(oneToManyAttribute)??defaultModelMetadata.PropertyName}"); + schema.Add("oneToMany", $"{oneToManyAttribute.Type.Name}.{oneToManyAttribute.GetType().GetProperty("Property")?.GetValue(oneToManyAttribute) ?? defaultModelMetadata.PropertyName}"); } if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType() == typeof(ScaffoldColumnAttribute)) is ScaffoldColumnAttribute scaffoldColumnAttribute && !scaffoldColumnAttribute.Scaffold) diff --git a/docs/demo/src/WTA/wwwroot/components/form/form-input.js b/docs/demo/src/WTA/wwwroot/components/form/form-input.js index f2329ac6..677140f2 100644 --- a/docs/demo/src/WTA/wwwroot/components/form/form-input.js +++ b/docs/demo/src/WTA/wwwroot/components/form/form-input.js @@ -42,7 +42,7 @@ export default { /> `, props: ["modelValue", "mode", "parentSchema", "schema", "prop", "errors"], diff --git a/docs/demo/src/WTA/wwwroot/components/form/index.js b/docs/demo/src/WTA/wwwroot/components/form/index.js index 9bc79905..2a9ed526 100644 --- a/docs/demo/src/WTA/wwwroot/components/form/index.js +++ b/docs/demo/src/WTA/wwwroot/components/form/index.js @@ -1,9 +1,8 @@ import html from "html"; -import { ref, reactive, watch } from "vue"; -import AppFormItem from "./form-item.js"; +import { defineAsyncComponent, ref, reactive, watch } from "vue"; export default { - components: { AppFormItem }, + components: { AppFormItem: defineAsyncComponent(() => import("./form-item.js")) }, name: "AppForm", template: html`