From a5bb6d650fb1c0846db7fa164edf70d496fdfe2c Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sat, 8 Jul 2023 13:06:42 +0800 Subject: [PATCH] update --- .../Entities/SystemManagement/User.cs | 3 ++- .../WTA.Shared/Attributes/SelectAttribute.cs | 22 ++++++++++++++++ .../Extensions/JsonSchemaExtensions.cs | 26 ++++++++++++++----- docs/demo/src/WTA.Shared/SignalR/PageHub.cs | 4 +-- .../WTA/wwwroot/components/form/form-input.js | 9 ++++--- .../src/WTA/wwwroot/components/list/index.js | 7 +++-- 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 docs/demo/src/WTA.Shared/Attributes/SelectAttribute.cs diff --git a/docs/demo/src/WTA.Application/Identity/Entities/SystemManagement/User.cs b/docs/demo/src/WTA.Application/Identity/Entities/SystemManagement/User.cs index f06a9930..1aab848f 100644 --- a/docs/demo/src/WTA.Application/Identity/Entities/SystemManagement/User.cs +++ b/docs/demo/src/WTA.Application/Identity/Entities/SystemManagement/User.cs @@ -27,7 +27,8 @@ public class User : BaseEntity [Navigation] public Guid? DepartmentId { get; set; } - [Navigation] + [Select] + [ManyToOne("Id")] public Guid? PostId { get; set; } public Department? Department { get; set; } diff --git a/docs/demo/src/WTA.Shared/Attributes/SelectAttribute.cs b/docs/demo/src/WTA.Shared/Attributes/SelectAttribute.cs new file mode 100644 index 00000000..7890e563 --- /dev/null +++ b/docs/demo/src/WTA.Shared/Attributes/SelectAttribute.cs @@ -0,0 +1,22 @@ +namespace WTA.Shared.Attributes; + +[AttributeUsage(AttributeTargets.Property)] +public class SelectAttribute : Attribute +{ + public SelectAttribute(bool mutiple = false, string? label = null, string? value = null, string? controller = null, string? action = null, string? parentId = null) + { + this.Mutiple = mutiple; + this.Label = label; + this.Value = value; + this.Controller = controller; + this.Action = action; + this.ParentId = parentId; + } + + public bool Mutiple { get; } + public string? Label { get; } + public string? Value { get; } + public string? Controller { get; } + public string? Action { get; } + public string? ParentId { get; } +} diff --git a/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs b/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs index 2e26f7e0..242e06de 100644 --- a/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs +++ b/docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs @@ -145,17 +145,31 @@ public static class JsonSchemaExtensions var propertyName = defaultModelMetadata.Name; if (propertyName != null) { + if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType() == typeof(SelectAttribute)) is SelectAttribute selectAttribute) + { + schema.Add("input", "select"); + schema.Add("mutiple", selectAttribute.Mutiple); + schema.Add("url", $"{selectAttribute.Controller ?? propertyName.TrimEnd("Id").ToSlugify()}/{selectAttribute.Action ?? "index"}"); + schema.Add("parentId", selectAttribute.ParentId ?? "parentId"); + schema.AddNotNull("value", selectAttribute.Value ?? "id"); + schema.AddNotNull("label", selectAttribute.Label ?? "name"); + } if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType() == typeof(DefaultValueAttribute)) is DefaultValueAttribute defaultValue) { schema.AddNotNull("default", defaultValue.Value); } - if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType() == typeof(NavigationAttribute)) is NavigationAttribute navigationAttribute) + //if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType() == typeof(NavigationAttribute)) is NavigationAttribute navigationAttribute) + //{ + // var path = navigationAttribute.Property ?? $"{propertyName[..^2]}.Name"; + // path = string.Join('.', path.Split('.').Select(o => o.ToCamelCase())); + // schema.Add("navigation", path); + // schema.Add("input", "select"); + // schema.Add("url", defaultModelMetadata.ContainerType?.GetProperty(propertyName[..^2])?.PropertyType.Name.ToSlugify()!); + //} + if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType().IsGenericType && o.GetType().GetGenericTypeDefinition() == typeof(ManyToOneAttribute<>)) is ITypeAttribute manyToOneAttribute) { - var path = navigationAttribute.Property ?? $"{propertyName[..^2]}.Name"; - path = string.Join('.', path.Split('.').Select(o => o.ToCamelCase())); - schema.Add("navigation", path); - schema.Add("input", "select"); - schema.Add("url", defaultModelMetadata.ContainerType?.GetProperty(propertyName[..^2])?.PropertyType.Name.ToSlugify()!); + schema.Add("manyToOne", $"{manyToOneAttribute.Type.Name}.{manyToOneAttribute.GetType().GetProperty("Property")?.GetValue(manyToOneAttribute) ?? defaultModelMetadata.PropertyName}"); + //schema.Add("url", manyToOneAttribute.Type.Name.ToSlugify()); } if (defaultModelMetadata.Attributes.Attributes.FirstOrDefault(o => o.GetType().IsGenericType && o.GetType().GetGenericTypeDefinition() == typeof(OneToManyAttribute<>)) is ITypeAttribute oneToManyAttribute) { diff --git a/docs/demo/src/WTA.Shared/SignalR/PageHub.cs b/docs/demo/src/WTA.Shared/SignalR/PageHub.cs index e509ab90..9e322d97 100644 --- a/docs/demo/src/WTA.Shared/SignalR/PageHub.cs +++ b/docs/demo/src/WTA.Shared/SignalR/PageHub.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using WTA.Shared.EventBus; @@ -25,7 +23,7 @@ public class PageHub : Hub var userName = httpContext?.User.Identity?.Name; if (!string.IsNullOrEmpty(userName)) { - this._logger.LogInformation($"{this.Context.ConnectionId} 已连接 {userName}"); + this._logger.LogInformation(message: $"{this.Context.ConnectionId} 已连接 {userName}"); this.Groups.AddToGroupAsync(this.Context.ConnectionId, this.Context.ConnectionId); if (!string.IsNullOrEmpty(userName)) { 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 88b9af6c..a99cc6c0 100644 --- a/docs/demo/src/WTA/wwwroot/components/form/form-input.js +++ b/docs/demo/src/WTA/wwwroot/components/form/form-input.js @@ -93,9 +93,12 @@ export default { options.value = props.schema.options; } else if (props.schema.url) { try { - const url = `${props.schema.url}/index`; - const result = await post(url, { queryAll: true, query: { isReadonly: null } }); - options.value = result.data?.items; + const url = `${props.schema.url}`; + const result = await post(url, { queryAll: true, query: { isReadonly: null, isDisabled: null, order: null } }); + options.value = result.data?.items.map((o) => ({ + value: o[props.schema.value], + label: o[props.schema.label], + })); } catch (error) { console.log(error); } diff --git a/docs/demo/src/WTA/wwwroot/components/list/index.js b/docs/demo/src/WTA/wwwroot/components/list/index.js index 9da96e1a..36ff23cd 100644 --- a/docs/demo/src/WTA/wwwroot/components/list/index.js +++ b/docs/demo/src/WTA/wwwroot/components/list/index.js @@ -56,6 +56,7 @@ export default { -
{{$t('拖放文件或')}} {{$t('点击上传')}}
@@ -327,6 +327,7 @@ export default { const treeProps = reactive({ children: "children", }); + const tableKey = ref(false); const tableRef = ref(null); const uploadRef = ref(null); const columns = ref([]); @@ -422,6 +423,7 @@ export default { } tableData.value = listData.items; data.value = listData; + tableKey.value = !tableKey.value; } catch (error) { console.log(error); } finally { @@ -489,7 +491,7 @@ export default { if (valid) { editFormloading.value = true; const url = `${baseUrl}/${editFormMode.value}`; - const result = await post(url, editFormModel); + const result = await post(url, editFormModel.value); if (result.errors) { model.errors = result.errors; //?? } else { @@ -595,6 +597,7 @@ export default { }); return { treeProps, + tableKey, tableRef, uploadRef, tableLoading,