diff --git a/CodeSmith/CSharp/Web/Application.cst b/CodeSmith/CSharp/Web/Application.cst index 1963fec1..632c16d1 100644 --- a/CodeSmith/CSharp/Web/Application.cst +++ b/CodeSmith/CSharp/Web/Application.cst @@ -5,7 +5,6 @@ Description: Create a list of properties from a database table --%> <%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %> <%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> <%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> @@ -73,10 +72,9 @@ namespace OpenAuth.App public void Update(<%=ModuleName%> obj) { - UnitWork.Update(u => u.Id == obj.Id, u => new User + UnitWork.Update<<%=ModuleName%>>(u => u.Id == obj.Id, u => new <%=ModuleName%> { - Name = role.Name, - Status = role.Status + //todo:要修改的 }); } diff --git a/CodeSmith/CSharp/Web/Controller.cst b/CodeSmith/CSharp/Web/Controller.cst index 9a86ec5e..3858e30d 100644 --- a/CodeSmith/CSharp/Web/Controller.cst +++ b/CodeSmith/CSharp/Web/Controller.cst @@ -20,19 +20,18 @@ using OpenAuth.Mvc.Models; namespace OpenAuth.Mvc.Controllers { - public class <%=ModuleName%>ManagerController : BaseController + public class <%=ModuleName%>sController : BaseController { public <%=ModuleName%>App App { get; set; } // - // GET: /UserManager/ [Authenticate] public ActionResult Index() { return View(); } - //添加或修改组织 + //添加或修改 [System.Web.Mvc.HttpPost] public string Add(<%=ModuleName%> obj) { @@ -49,7 +48,7 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(Result); } - //添加或修改组织 + //添加或修改 [System.Web.Mvc.HttpPost] public string Update(<%=ModuleName%> obj) { @@ -67,7 +66,7 @@ namespace OpenAuth.Mvc.Controllers } /// - /// 加载组织下面的所有用户 + /// 加载列表 /// public string Load([FromUri]Query<%=ModuleName%>ListReq request) { diff --git a/CodeSmith/CSharp/Web/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.cst index be5a8d95..e9740de3 100644 --- a/CodeSmith/CSharp/Web/Index.cshtml.cst +++ b/CodeSmith/CSharp/Web/Index.cshtml.cst @@ -19,17 +19,7 @@ Description="连接的数据库" %> }
@@ -96,10 +86,17 @@ Description="连接的数据库" %>
<%} %> + +
+
+ + +
+
- + diff --git a/CodeSmith/CSharp/Web/index.js.cst b/CodeSmith/CSharp/Web/index.js.cst index 376bb6e7..391bf002 100644 --- a/CodeSmith/CSharp/Web/index.js.cst +++ b/CodeSmith/CSharp/Web/index.js.cst @@ -29,7 +29,7 @@ layui.config({ $.extend(config, options); } table.reload('mainList', { - url: '/<%=ModuleName%>Manager/Load', + url: '/<%=ModuleName%>s/Load', where: config }); } @@ -91,9 +91,9 @@ layui.config({ }, end: mainList }); - var url = "/<%=ModuleName%>Manager/Add"; + var url = "/<%=ModuleName%>s/Add"; if (update) { - url = "/<%=ModuleName%>Manager/Update"; + url = "/<%=ModuleName%>s/Update"; } //提交数据 form.on('submit(formSubmit)', @@ -135,7 +135,7 @@ layui.config({ btnDel: function () { //批量删除 var checkStatus = table.checkStatus('mainList') , data = checkStatus.data; - openauth.del("/<%=ModuleName%>Manager/Delete", + openauth.del("/<%=ModuleName%>s/Delete", data.map(function (e) { return e.Id; }), mainList); } diff --git a/CodeSmith/CSharp/WebGenerate.cst b/CodeSmith/CSharp/WebGenerate.cst index a4166920..51fbbc18 100644 --- a/CodeSmith/CSharp/WebGenerate.cst +++ b/CodeSmith/CSharp/WebGenerate.cst @@ -45,6 +45,9 @@ OnChanged="OnSourceDatabaseChanged"%> <%@ Register Name="JSGenerateClass" Template="Web\index.js.cst" MergeProperties="False" %> +<%@ Register Name="ControllerGenerateClass" + Template="Web\Controller.cst" + MergeProperties="False" %> Generating Entities ... <% Generate(); %> @@ -57,6 +60,9 @@ Generating Entities ... if (!Directory.Exists(directory)) //根目录 Directory.CreateDirectory(directory); + if (!Directory.Exists(directory +"/controllers")) //controller目录 + Directory.CreateDirectory(directory +"/controllers"); + if (!Directory.Exists(directory +"/views")) //视图根文件夹 Directory.CreateDirectory(directory +"/views"); @@ -66,6 +72,7 @@ Generating Entities ... if (!Directory.Exists(directory +"/views/"+ModuleName +"Manager")) //视图文件夹 Directory.CreateDirectory(directory +"/views/"+ModuleName +"Manager"); + CreateControllerClass(); CreateApplicationClass(); CreateHtmlClass(); CreateJSClass(); @@ -80,6 +87,23 @@ Generating Entities ... Response.WriteLine("Generate Time: " + watch.ElapsedMilliseconds + " ms"); } + //创建控制器,如UserManagerController.cs + public void CreateControllerClass() + { + ControllerGenerateClass generatedClass = this.Create(); + this.CopyPropertiesTo(generatedClass); + + string rootDirectory = Path.GetFullPath(directory); + + string generatedFile ="controllers" + ModuleName + "sController.cs"; + generatedFile = Path.Combine(rootDirectory, generatedFile); + + generatedClass.ModuleName = ModuleName; + + Response.WriteLine(generatedFile); + generatedClass.RenderToFile(generatedFile, generatedFile, true); + } + //创建APP层,如UserManagerApp.cs public void CreateApplicationClass() { @@ -88,11 +112,10 @@ Generating Entities ... string rootDirectory = Path.GetFullPath(directory); - string generatedFile = ModuleName + "ManagerApp.cs"; + string generatedFile = ModuleName + "App.cs"; generatedFile = Path.Combine(rootDirectory, generatedFile); generatedClass.ModuleName = ModuleName; - generatedClass.NeedViewModel = NeedViewModel; Response.WriteLine(generatedFile); generatedClass.RenderToFile(generatedFile, generatedFile, true); @@ -104,7 +127,7 @@ Generating Entities ... HtmlGenerateClass generatedClass = this.Create(); this.CopyPropertiesTo(generatedClass); - string generatedFile = Path.GetFullPath(directory) + "/views/"+ModuleName+"Manager/" + "index.cshtml"; + string generatedFile = Path.GetFullPath(directory) + "/views/"+ModuleName+"s/index.cshtml"; generatedClass.ModuleName = ModuleName; generatedClass.SourceTable = SourceTable; @@ -119,7 +142,7 @@ Generating Entities ... JSGenerateClass generatedClass = this.Create(); this.CopyPropertiesTo(generatedClass); - string generatedFile = Path.GetFullPath(directory) + "/js/"+ModuleName+"Manager.js"; + string generatedFile = Path.GetFullPath(directory) + "/js/"+ModuleName+"s.js"; generatedClass.ModuleName = ModuleName; @@ -131,7 +154,7 @@ Generating Entities ... //更换数据源时,改变ModuleName private void OnSourceDatabaseChanged(object sender, EventArgs e) { - if (SourceTable == null) + if (SourceTable == null || ModuleName != null) return; ModuleName = SourceTable.Name; } diff --git a/OpenAuth.App/FormApp.cs b/OpenAuth.App/FormApp.cs new file mode 100644 index 00000000..2c56bb77 --- /dev/null +++ b/OpenAuth.App/FormApp.cs @@ -0,0 +1,47 @@ +using System.Linq; +using OpenAuth.App.Request; +using OpenAuth.App.Response; +using OpenAuth.Repository.Domain; + + +namespace OpenAuth.App +{ + public class FormApp : BaseApp + { + public RevelanceManagerApp ReleManagerApp { get; set; } + + /// + /// 加载列表 + /// + public TableData Load(QueryFormListReq request) + { + var forms = UnitWork.Find(null) + .OrderBy(u => u.FrmCode) + .Skip((request.page - 1) * request.limit) + .Take(request.limit); + + + return new TableData + { + count = Repository.GetCount(null), + data = forms, + }; + } + + public void Add(WFFrmMain obj) + { + Repository.Add(obj); + } + + public void Update(WFFrmMain obj) + { + UnitWork.Update(u => u.Id == obj.Id, u => new WFFrmMain + { + FrmCode = obj.FrmCode, + FrmContent = obj.FrmContent + }); + + } + + } +} \ No newline at end of file diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index cf753824..7a3c2c94 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -111,10 +111,12 @@ + + diff --git a/OpenAuth.App/Request/QueryFormListReq.cs b/OpenAuth.App/Request/QueryFormListReq.cs new file mode 100644 index 00000000..0a9d7732 --- /dev/null +++ b/OpenAuth.App/Request/QueryFormListReq.cs @@ -0,0 +1,7 @@ +namespace OpenAuth.App.Request +{ + public class QueryFormListReq : PageReq + { + public string orgId { get; set; } + } +} diff --git a/OpenAuth.Mvc/Controllers/FormsController.cs b/OpenAuth.Mvc/Controllers/FormsController.cs new file mode 100644 index 00000000..dae2a08e --- /dev/null +++ b/OpenAuth.Mvc/Controllers/FormsController.cs @@ -0,0 +1,81 @@ +using System; +using System.Web.Http; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +using OpenAuth.App.Request; +using OpenAuth.Mvc.Models; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.Mvc.Controllers +{ + public class FormsController : BaseController + { + public FormApp App { get; set; } + + // + [Authenticate] + public ActionResult Index() + { + return View(); + } + + //添加或修改 + [System.Web.Mvc.HttpPost] + public string Add(WFFrmMain obj) + { + try + { + App.Add(obj); + + } + catch (Exception ex) + { + Result.Code = 500; + Result.Message = ex.Message; + } + return JsonHelper.Instance.Serialize(Result); + } + + //添加或修改 + [System.Web.Mvc.HttpPost] + public string Update(WFFrmMain obj) + { + try + { + App.Update(obj); + + } + catch (Exception ex) + { + Result.Code = 500; + Result.Message = ex.Message; + } + return JsonHelper.Instance.Serialize(Result); + } + + /// + /// 加载列表 + /// + public string Load([FromUri]QueryFormListReq request) + { + return JsonHelper.Instance.Serialize(App.Load(request)); + } + + [System.Web.Mvc.HttpPost] + public string Delete(string[] ids) + { + try + { + App.Delete(ids); + } + catch (Exception e) + { + Result.Code = 500; + Result.Message = e.Message; + } + + return JsonHelper.Instance.Serialize(Result); + } + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 57a4c126..6e7ec760 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -150,6 +150,7 @@ + @@ -168,6 +169,7 @@ + @@ -354,6 +356,7 @@ + diff --git a/OpenAuth.Mvc/Views/Forms/index.cshtml b/OpenAuth.Mvc/Views/Forms/index.cshtml new file mode 100644 index 00000000..ff9b8ce7 --- /dev/null +++ b/OpenAuth.Mvc/Views/Forms/index.cshtml @@ -0,0 +1,186 @@ +@section header +{ + +} + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
表单模板Id表单编号表单名称表单分类数据表关联表的主键是否需要建表0不建表,1建表表单内容排序码删除标记数据库Id有效备注创建时间创建用户主键创建用户修改时间修改用户主键修改用户
+
+ + + + + + + + + diff --git a/OpenAuth.Mvc/js/assign.js b/OpenAuth.Mvc/js/assign.js index 14bc5ea4..ace75dd3 100644 --- a/OpenAuth.Mvc/js/assign.js +++ b/OpenAuth.Mvc/js/assign.js @@ -1,11 +1,9 @@ layui.config({ base: "/js/" -}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth','queryString'], function () { +}).use(['form','vue', 'ztree', 'layer', 'jquery','queryString'], function () { var //layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer, layer = layui.layer, $ = layui.jquery; - var table = layui.table; - var openauth = layui.openauth; var id = $.getUrlParam("id"); //待分配的id var type = $.getUrlParam("type"); //待分配的类型 var menuType = $.getUrlParam("menuType"); //待分配菜单的类型 @@ -146,8 +144,8 @@ layui.config({ zTreeObj.checkNode(node, true, false); }); }); - - menutree.load({ moduleId: json[0].Id }); + $("#menutree").html("点击左边的模块开始分配菜单"); + // menutree.load({ moduleId: json[0].Id }); zTreeObj.expandAll(true); }); }; diff --git a/OpenAuth.Mvc/js/forms.js b/OpenAuth.Mvc/js/forms.js new file mode 100644 index 00000000..0a99a078 --- /dev/null +++ b/OpenAuth.Mvc/js/forms.js @@ -0,0 +1,119 @@ +layui.config({ + base: "/js/" +}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth'], function () { + var form = layui.form, + //layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer, + layer = layui.layer, + $ = layui.jquery; + var table = layui.table; + var openauth = layui.openauth; + layui.droptree("/UserSession/GetOrgs", "#Organizations", "#OrganizationIds"); + + //主列表加载,可反复调用进行刷新 + var config= {}; //table的参数,如搜索key,点击tree的id + var mainList = function (options) { + if (options != undefined) { + $.extend(config, options); + } + table.reload('mainList', { + url: '/Forms/Load', + where: config + }); + } + + mainList(); + + //添加(编辑)对话框 + var editDlg = function() { + var vm = new Vue({ + el: "#formEdit" + }); + var update = false; //是否为更新 + var show = function (data) { + var title = update ? "编辑信息" : "添加"; + layer.open({ + title: title, + area: ["500px", "400px"], + type: 1, + content: $('#divEdit'), + success: function() { + vm.$set('$data', data); + }, + end: mainList + }); + var url = "/Forms/Add"; + if (update) { + url = "/Forms/Update"; + } + //提交数据 + form.on('submit(formSubmit)', + function(data) { + $.post(url, + data.field, + function(data) { + layer.msg(data.Message); + }, + "json"); + return false; + }); + } + return { + add: function() { //弹出添加 + update = false; + show({ + Id: '' + }); + }, + update: function(data) { //弹出编辑框 + update = true; + show(data); + } + }; + }(); + + //监听表格内部按钮 + table.on('tool(list)', function (obj) { + var data = obj.data; + if (obj.event === 'detail') { //查看 + layer.msg('ID:' + data.Id + ' 的查看操作'); + } + }); + + + //监听页面主按钮操作 + var active = { + btnDel: function () { //批量删除 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + openauth.del("/Forms/Delete", + data.map(function (e) { return e.Id; }), + mainList); + } + , btnAdd: function () { //添加 + editDlg.add(); + } + , btnEdit: function () { //编辑 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + if (data.length != 1) { + layer.msg("请选择编辑的行,且同时只能编辑一行"); + return; + } + editDlg.update(data[0]); + } + + , search: function () { //搜索 + mainList({ key: $('#key').val() }); + } + , btnRefresh: function() { + mainList(); + } + }; + + $('.toolList .layui-btn').on('click', function () { + var type = $(this).data('type'); + active[type] ? active[type].call(this) : ''; + }); + + //监听页面主按钮操作 end +}) \ No newline at end of file