Skip to content

Commit

Permalink
[feat]新增生成工具栏批处理模板视图
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 29, 2024
1 parent 3d2e4c0 commit 0431dba
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
32 changes: 27 additions & 5 deletions NewLife.Cube/Common/ViewHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,14 +718,36 @@ internal static Boolean MakeSearchView(Type entityType, String vpath, List<DataF
@*@await Html.PartialAsync("_DateRange")*@
""";

//var sb = new StringBuilder();
//var fact = EntityFactory.CreateFactory(entityType);

tmp = tmp.Replace("{EntityType}", entityType.Name);
tmp = tmp.Replace("{Namespace}", entityType.Namespace);

//sb.Append(tmp.Substring(p));
//tmp = sb.ToString();
File.WriteAllText(vpath.GetFullPath().EnsureDirectory(true), tmp, Encoding.UTF8);

return true;
}

internal static Boolean MakeBatchView(Type entityType, String vpath, List<DataField> fields)
{
var tmp = """
@using NewLife.Common;
@using NewLife.Cube
@using XCode
@{
var user = ViewBag.User as IUser ?? User.Identity as IUser;
var fact = ViewBag.Factory as IEntityFactory;
var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;
}
@if (set.EnableSelect)
{
@*<button type="button" class="btn btn-purple btn-sm" data-action="action" data-url="@Url.Action("DeleteSelect")" data-method="post" data-fields="keys,keys2" data-confirm="该操作将删除选中数据并不可恢复!确认删除?" disabled>
<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
批量删除
</button>*@
}
""";

tmp = tmp.Replace("{EntityType}", entityType.Name);
tmp = tmp.Replace("{Namespace}", entityType.Namespace);

File.WriteAllText(vpath.GetFullPath().EnsureDirectory(true), tmp, Encoding.UTF8);

Expand Down
23 changes: 23 additions & 0 deletions NewLife.CubeNC/Common/ReadOnlyEntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ public virtual async Task<ActionResult> Develop(String act)
"MakeList" => MakeList(),
"MakeForm" => MakeForm(),
"MakeSearch" => MakeSearch(),
"MakeBatch" => MakeBatch(),
_ => throw new NotSupportedException($"未支持[{act}]"),
};
}
Expand Down Expand Up @@ -857,6 +858,28 @@ public ActionResult MakeSearch()
return RedirectToAction("Index");
}

/// <summary>生成批处理</summary>
/// <returns></returns>
[NonAction]
public ActionResult MakeBatch()
{
if (!SysConfig.Current.Develop) throw new InvalidOperationException("仅支持开发模式下使用!");

// 找到项目根目录
var root = GetProjectRoot();

// 视图路径,Areas/区域/Views/控制器/_List_Toolbar_Batch.cshtml
var cs = GetControllerAction();
var vpath = $"Areas/{cs[0]}/Views/{cs[1]}/_List_Toolbar_Batch.cshtml";
if (!root.IsNullOrEmpty()) vpath = root.EnsureEnd("/") + vpath;

_ = ViewHelper.MakeBatchView(typeof(TEntity), vpath, OnGetFields(ViewKinds.List, null));

WriteLog("生成批处理", true, vpath);

return RedirectToAction("Index");
}

private String GetProjectRoot()
{
var asm = GetType().Assembly;
Expand Down
3 changes: 3 additions & 0 deletions NewLife.CubeNC/Views/Shared/_List_Toolbar_Adv.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<li>
<a href="@Url.Action("Develop",new{act="MakeSearch"})">生成搜索</a>
</li>
<li>
<a href="@Url.Action("Develop",new{act="MakeBatch"})">生成批处理</a>
</li>
}
</ul>
</div><!-- /.btn-group -->

0 comments on commit 0431dba

Please sign in to comment.