You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Views/Shared/Index.cshtml

124 lines
5.4 KiB

@using Infrastructure.Domain
@using System.Security.Claims
@{
var scope = ViewBag.ControllerScope as string;
var entityType = ViewData["EntityTypeExt"] as Type;
var isSoftDeleteEntity = typeof(ISoftDeleteEntity).IsAssignableFrom(entityType);
var modelType = ViewData["ModelTypeExt"] as Type;
HtmlTitle = modelType.GetDisplayName()+"列表";
var entityName = entityType.Name;
var hasPermissions = (User.Identity as ClaimsIdentity).Claims.Any(o => o.Value.EndsWith($"-{entityName}"));
var start = (Model.PageIndex - 1) * Model.PageSize;
var prefix = new ViewDataDictionary(this.ViewData);
prefix.TemplateInfo.HtmlFieldPrefix = "Query";
}
<form action="@Url.Action(null,null)" method="get" class="form-horizontal query">
<div class="card">
<div class="card-header">
<div class="row">
@(await Html.PartialAsync("Search",Model.Query as object,prefix))
</div>
@if (hasPermissions)
{
<div class="row">
<div class="col-12">
@if (User.IsInRole($"Read-{scope}-{entityName}"))
{
<button type="submit" class="action query btn btn-primary cancel" data-action="@Url.Action(null,null)">
查询
</button>
}
@if (User.IsInRole($"Add-{scope}-{entityName}"))
{
<a class="btn btn-success" href="@Url.Action("Add")">
新建
</a>
}
@if (isSoftDeleteEntity && User.IsInRole($"Edit-{scope}-{entityName}"))
{
<button type="submit" class="action confirm btn btn-primary" data-action="@Url.Action("Remove")">
移除
</button>
}
@if (isSoftDeleteEntity && User.IsInRole($"Edit-{scope}-{entityName}"))
{
<button type="submit" class="action confirm btn btn-primary" data-action="@Url.Action("Restore")">
还原
</button>
}
@if (User.IsInRole($"Delete-{scope}-{entityName}"))
{
<button type="submit" class="action confirm btn btn-danger" data-action="@Url.Action("Delete")">
删除
</button>
}
</div>
</div>
}
</div>
<div class="card-body" style="overflow-x:auto;">
<table class="table table-hover text-nowrap table-bordered dataTable dtr-inline projects">
<tr>
<th><input type="checkbox" class="select_all" /></th>
<th>行号</th>
@foreach (var item in modelType.GetProperties().Where(o => !typeof(BaseEntity).IsAssignableFrom(o.PropertyType) && o.Name != "Id" && !o.CustomAttributes.Any(t => t.AttributeType == typeof(ScaffoldColumnAttribute))))
{
if (item.PropertyType.IsGenericType && item.PropertyType.GetInterfaces().Contains(typeof(System.Collections.IEnumerable)))
{
continue;
}
if(scope=="Organ"&&item.Name=="OrganId")
{
continue;
}
<th>@item.GetDisplayName()</th>
}
@if (User.IsInRole($"Read-{scope}-{entityType.Name}"))
{
<th>查看</th>
}
@if (User.IsInRole($"Edit-{scope}-{entityType.Name}"))
{
<th>编辑</th>
}
</tr>
@foreach (var item in Model.List)
{
var id = modelType.GetProperty("Id").GetValue(item);
<tr>
<td title="@item.Id">
<input type="checkbox" name="list[]" value="@item.Id" />
</td>
<td>@(++start)</td>
@await Html.PartialAsync("_Index_Row", item as object)
@if (User.IsInRole($"Read-{scope}-{entityName}"))
{
<td>
<a class="btn btn-info btn-sm" href="@Url.Action("Details",new { id=id})">
查看
</a>
</td>
}
@if (User.IsInRole($"Edit-{scope}-{entityName}"))
{
<td>
<a class="btn btn-info btn-sm" href="@Url.Action("Edit",new { id=id})">
编辑
</a>
</td>
}
</tr>
}
</table>
</div>
@if (!HidePaged)
{
<div class="card-footer clearfix">
@(await Html.PartialAsync("_Paged"))
</div>
}
</div>
</form>
@section scripts{
@(await Html.PartialAsync("_Script"))
}