Browse Source

update

pull/1/head^2
wanggang 1 year ago
parent
commit
a5bb6d650f
  1. 3
      docs/demo/src/WTA.Application/Identity/Entities/SystemManagement/User.cs
  2. 22
      docs/demo/src/WTA.Shared/Attributes/SelectAttribute.cs
  3. 26
      docs/demo/src/WTA.Shared/Extensions/JsonSchemaExtensions.cs
  4. 4
      docs/demo/src/WTA.Shared/SignalR/PageHub.cs
  5. 9
      docs/demo/src/WTA/wwwroot/components/form/form-input.js
  6. 7
      docs/demo/src/WTA/wwwroot/components/list/index.js

3
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<Post>("Id")]
public Guid? PostId { get; set; }
public Department? Department { get; set; }

22
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; }
}

26
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)
{

4
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))
{

9
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);
}

7
docs/demo/src/WTA/wwwroot/components/list/index.js

@ -56,6 +56,7 @@ export default {
<el-col>
<el-scrollbar>
<el-table
:key="tableKey"
ref="tableRef"
:tree-props="treeProps"
:data="tableData"
@ -245,7 +246,6 @@ export default {
:on-change="handleChange"
>
<el-icon class="el-icon--upload"><ep-upload-filled /></el-icon>
<div class="el-upload__text">{{$t('拖放文件或')}} <em>{{$t('点击上传')}}</em></div>
</el-upload>
</el-form-item>
</el-form>
@ -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,

Loading…
Cancel
Save