This commit is contained in:
yubaolee
2017-11-29 18:26:36 +08:00
parent 503f92d68e
commit e36664d5f6
27 changed files with 3565 additions and 3515 deletions

View File

@@ -1,138 +1,138 @@
<%--
Name: Database Table Properties
Author: yubaolee
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" %>
<script runat="template">
public String GetModelName()
{
if(NeedViewModel)
return ModuleName +"View";
else
return ModuleName;
}
</script>
<%if(NeedViewModel){ %>
using OpenAuth.App.ViewModel;
<%} %>
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenAuth.App
{
public class <%=ModuleName%>ManagerApp
{
private I<%=ModuleName%>Repository _repository;
private IOrgRepository _orgRepository;
public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository,
IOrgRepository orgRepository)
{
_repository = repository;
_orgRepository = orgRepository;
}
public int Get<%=GetModelName()%>CntInOrg(int orgId)
{
if (orgId == 0)
{
return _repository.Find(null).Count();
}
else
{
return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId));
}
}
public List<<%=GetModelName()%>> LoadAll()
{
return _repository.Find(null).ToList();
}
/// <summary>
/// 加载一个节点下面的一个或全部<%=GetModelName()%>s
/// </summary>
public dynamic Load(int orgId, int pageindex, int pagesize)
{
IEnumerable<<%=ModuleName%>> <%=ModuleName%>s;
int total = 0;
if (orgId == 0)
{
<%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize);
total = _repository.GetCount();
}
else
{
<%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
total = _repository.Get<%=ModuleName%>CntInOrgs(orgId);
}
<%if(NeedViewModel){ %>
var <%=ModuleName%>views = new List<<%=ModuleName%>View>();
foreach (var <%=ModuleName%> in <%=ModuleName%>s)
{
<%=ModuleName%>View uv = <%=ModuleName%>;
uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList());
<%=ModuleName%>views.Add(uv);
}
<%} %>
return new
{
total = total,
list = <%=GetModelName()%>s,
pageCurrent = pageindex
};
}
/// <summary>
/// 获取当前节点的所有下级节点
/// </summary>
private int[] GetSubOrgIds(int orgId)
{
var org = _orgRepository.FindSingle(u => u.Id == orgId);
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
return orgs;
}
public <%=GetModelName()%> Find(int id)
{
var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id);
if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>();
return <%=ModuleName.ToLower() %>;
}
public void Delete(int id)
{
_repository.Delete(id);
}
public void AddOrUpdate(<%=GetModelName()%> model)
{
<%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>();
model.CopyTo(<%=ModuleName.ToLower()%>);
if (<%=ModuleName.ToLower()%>.Id == 0)
{
_repository.Add(<%=ModuleName.ToLower()%>);
}
else
{
_repository.Update(<%=ModuleName.ToLower()%>);
}
}
}
<%--
Name: Database Table Properties
Author: yubaolee
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" %>
<script runat="template">
public String GetModelName()
{
if(NeedViewModel)
return ModuleName +"View";
else
return ModuleName;
}
</script>
<%if(NeedViewModel){ %>
using OpenAuth.App.ViewModel;
<%} %>
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenAuth.App
{
public class <%=ModuleName%>ManagerApp
{
private I<%=ModuleName%>Repository _repository;
private IOrgRepository _orgRepository;
public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository,
IOrgRepository orgRepository)
{
_repository = repository;
_orgRepository = orgRepository;
}
public int Get<%=GetModelName()%>CntInOrg(int orgId)
{
if (orgId == 0)
{
return _repository.Find(null).Count();
}
else
{
return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId));
}
}
public List<<%=GetModelName()%>> LoadAll()
{
return _repository.Find(null).ToList();
}
/// <summary>
/// 加载一个节点下面的一个或全部<%=GetModelName()%>s
/// </summary>
public dynamic Load(int orgId, int pageindex, int pagesize)
{
IEnumerable<<%=ModuleName%>> <%=ModuleName%>s;
int total = 0;
if (orgId == 0)
{
<%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize);
total = _repository.GetCount();
}
else
{
<%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
total = _repository.Get<%=ModuleName%>CntInOrgs(orgId);
}
<%if(NeedViewModel){ %>
var <%=ModuleName%>views = new List<<%=ModuleName%>View>();
foreach (var <%=ModuleName%> in <%=ModuleName%>s)
{
<%=ModuleName%>View uv = <%=ModuleName%>;
uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList());
<%=ModuleName%>views.Add(uv);
}
<%} %>
return new
{
total = total,
list = <%=GetModelName()%>s,
pageCurrent = pageindex
};
}
/// <summary>
/// 获取当前节点的所有下级节点
/// </summary>
private int[] GetSubOrgIds(int orgId)
{
var org = _orgRepository.FindSingle(u => u.Id == orgId);
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
return orgs;
}
public <%=GetModelName()%> Find(int id)
{
var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id);
if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>();
return <%=ModuleName.ToLower() %>;
}
public void Delete(int id)
{
_repository.Delete(id);
}
public void AddOrUpdate(<%=GetModelName()%> model)
{
<%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>();
model.CopyTo(<%=ModuleName.ToLower()%>);
if (<%=ModuleName.ToLower()%>.Id == 0)
{
_repository.Add(<%=ModuleName.ToLower()%>);
}
else
{
_repository.Update(<%=ModuleName.ToLower()%>);
}
}
}
}

View File

@@ -1,110 +1,110 @@
<%--
Name: Database Table Properties
Author: yubaolee
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" %>
<script runat="template">
public String GetModelName()
{
if(NeedViewModel)
return ModuleName +"View";
else
return ModuleName;
}
</script>
using System;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
<%if(NeedViewModel){ %>
using OpenAuth.App.ViewModel;
<%} %>
using OpenAuth.Domain;
namespace OpenAuth.Mvc.Controllers
{
public class <%=ModuleName%>ManagerController : BaseController
{
private <%=ModuleName%>ManagerApp _app;
public <%=ModuleName%>ManagerController()
{
_app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>();
}
//
// GET: /UserManager/
public ActionResult Index()
{
return View();
}
public ActionResult Add(int id = 0)
{
return View(_app.Find(id));
}
//添加或修改<%=ModuleName %>
[HttpPost]
public string Add(<%=GetModelName()%> model)
{
try
{
_app.AddOrUpdate(model);
}
catch (Exception ex)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
/// <summary>
/// 加载节点下面的所有<%=ModuleName %>s
/// </summary>
public string Load(int parentId, int pageCurrent = 1, int pageSize = 30)
{
return JsonHelper.Instance.Serialize(_app.Load(parentId, pageCurrent, pageSize));
}
public string LoadForTree()
{
var models = _app.LoadAll();
//添加根节点
models.Add(new <%=ModuleName %>
{
Id = 0,
ParentId = -1,
Name = "根结点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(models);
}
public string Delete(int Id)
{
try
{
_app.Delete(Id);
}
catch (Exception e)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = e.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
}
<%--
Name: Database Table Properties
Author: yubaolee
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" %>
<script runat="template">
public String GetModelName()
{
if(NeedViewModel)
return ModuleName +"View";
else
return ModuleName;
}
</script>
using System;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
<%if(NeedViewModel){ %>
using OpenAuth.App.ViewModel;
<%} %>
using OpenAuth.Domain;
namespace OpenAuth.Mvc.Controllers
{
public class <%=ModuleName%>ManagerController : BaseController
{
private <%=ModuleName%>ManagerApp _app;
public <%=ModuleName%>ManagerController()
{
_app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>();
}
//
// GET: /UserManager/
public ActionResult Index()
{
return View();
}
public ActionResult Add(int id = 0)
{
return View(_app.Find(id));
}
//添加或修改<%=ModuleName %>
[HttpPost]
public string Add(<%=GetModelName()%> model)
{
try
{
_app.AddOrUpdate(model);
}
catch (Exception ex)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
/// <summary>
/// 加载节点下面的所有<%=ModuleName %>s
/// </summary>
public string Load(int parentId, int pageCurrent = 1, int pageSize = 30)
{
return JsonHelper.Instance.Serialize(_app.Load(parentId, pageCurrent, pageSize));
}
public string LoadForTree()
{
var models = _app.LoadAll();
//添加根节点
models.Add(new <%=ModuleName %>
{
Id = 0,
ParentId = -1,
Name = "根结点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(models);
}
public string Delete(int Id)
{
try
{
_app.Delete(Id);
}
catch (Exception e)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = e.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
}
}

View File

@@ -1,105 +1,105 @@
<%--
Name: 列表页面
Author: yubaolee
Description: 列表页面
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
Description="连接的数据库" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Assembly Src="Util.cs" %>
<%@ Import Namespace="Util" %>
@section header
{
<link rel="stylesheet" href="/css/treetable.css" />
}
<blockquote class="layui-elem-quote news_search toolList">
<div class="layui-inline">
<div class="layui-input-inline">
<input class="layui-input" placeholder="请输入关键字"
name="key" id="key" autocomplete="off">
</div>
<button class="layui-btn" data-type="search">搜索</button>
</div>
@Html.Action("MenuHeader", "Home")
@*<button class="layui-btn " data-type="refresh">刷新</button>
<button class="layui-btn " data-type="addData">添加</button>
<button class="layui-btn layui-btn-danger" data-type="del">批量删除</button>*@
</blockquote>
<div style="display: flex;">
<ul id="tree" class="ztree" style="display: inline-block; width: 180px; padding: 10px; border: 1px solid #ddd; overflow: auto;"></ul>
<table class="layui-table"
lay-data="{height: 'full-80', page:true, id:'mainList'}"
lay-filter="list">
<thead>
<tr>
<th lay-data="{checkbox:true, fixed: true}"></th>
<% foreach (ColumnSchema column in this.SourceTable.Columns) {%>
<th lay-data="{field:'<%=column.Name%>', width:150}"><%=Tools.GetDescription(column)%></th>
<% }%>
<th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barList'}"></th>
</tr>
</thead>
</table>
</div>
<script type="text/html" id="barList">
<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
</script>
<!--用户添加/编辑窗口-->
<div id="divEdit" style="display: none">
<form class="layui-form" action="" id="formEdit">
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
if(column.IsPrimaryKeyMember){%>
<input type="hidden" name="<%=column.Name%>" v-model="<%=column.Name%>" />
<%}else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="checkbox" name="<%=column.Name%>" v-model="<%=column.Name%>" lay-skin="switch" value="1">
</div>
</div>
<%}else if(CSharpAlias[column.SystemType.FullName] == "int" ) {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="radio" name="<%=column.Name%>" value="1" title="value1" checked>
<input type="radio" name="<%=column.Name%>" value="0" title="value2">
</div>
</div>
<%} else {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="text" name="<%=column.Name%>" v-model="<%=column.Name%>" required lay-verify="required"
placeholder="<%=Tools.GetDescription(column)%>" autocomplete="off" class="layui-input">
</div>
</div>
<%} %>
<%} %>
<%if(Tools.NeedCascade(SourceTable)){ %>
<div class="layui-form-item">
<label class="layui-form-label">所属部门</label>
<div class="layui-input-block">
<input id="Organizations" name="Organizations" v-model="Organizations" required lay-verify="required" class="layui-input" />
<input id="OrganizationIds" name="OrganizationIds" v-model="OrganizationIds" required lay-verify="required" type="hidden" />
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
<%} %>
</form>
</div>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/<%=ModuleName%>Manager.js"></script>
<%--
Name: 列表页面
Author: yubaolee
Description: 列表页面
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
Description="连接的数据库" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Assembly Src="Util.cs" %>
<%@ Import Namespace="Util" %>
@section header
{
<link rel="stylesheet" href="/css/treetable.css" />
}
<blockquote class="layui-elem-quote news_search toolList">
<div class="layui-inline">
<div class="layui-input-inline">
<input class="layui-input" placeholder="请输入关键字"
name="key" id="key" autocomplete="off">
</div>
<button class="layui-btn" data-type="search">搜索</button>
</div>
@Html.Action("MenuHeader", "Home")
@*<button class="layui-btn " data-type="refresh">刷新</button>
<button class="layui-btn " data-type="addData">添加</button>
<button class="layui-btn layui-btn-danger" data-type="del">批量删除</button>*@
</blockquote>
<div style="display: flex;">
<ul id="tree" class="ztree" style="display: inline-block; width: 180px; padding: 10px; border: 1px solid #ddd; overflow: auto;"></ul>
<table class="layui-table"
lay-data="{height: 'full-80', page:true, id:'mainList'}"
lay-filter="list">
<thead>
<tr>
<th lay-data="{checkbox:true, fixed: true}"></th>
<% foreach (ColumnSchema column in this.SourceTable.Columns) {%>
<th lay-data="{field:'<%=column.Name%>', width:150}"><%=Tools.GetDescription(column)%></th>
<% }%>
<th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barList'}"></th>
</tr>
</thead>
</table>
</div>
<script type="text/html" id="barList">
<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
</script>
<!--用户添加/编辑窗口-->
<div id="divEdit" style="display: none">
<form class="layui-form" action="" id="formEdit">
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
if(column.IsPrimaryKeyMember){%>
<input type="hidden" name="<%=column.Name%>" v-model="<%=column.Name%>" />
<%}else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="checkbox" name="<%=column.Name%>" v-model="<%=column.Name%>" lay-skin="switch" value="1">
</div>
</div>
<%}else if(CSharpAlias[column.SystemType.FullName] == "int" ) {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="radio" name="<%=column.Name%>" value="1" title="value1" checked>
<input type="radio" name="<%=column.Name%>" value="0" title="value2">
</div>
</div>
<%} else {%>
<div class="layui-form-item">
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
<div class="layui-input-block">
<input type="text" name="<%=column.Name%>" v-model="<%=column.Name%>" required lay-verify="required"
placeholder="<%=Tools.GetDescription(column)%>" autocomplete="off" class="layui-input">
</div>
</div>
<%} %>
<%} %>
<%if(Tools.NeedCascade(SourceTable)){ %>
<div class="layui-form-item">
<label class="layui-form-label">所属部门</label>
<div class="layui-input-block">
<input id="Organizations" name="Organizations" v-model="Organizations" required lay-verify="required" class="layui-input" />
<input id="OrganizationIds" name="OrganizationIds" v-model="OrganizationIds" required lay-verify="required" type="hidden" />
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
<%} %>
</form>
</div>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/<%=ModuleName%>Manager.js"></script>

View File

@@ -1,24 +1,24 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using CodeSmith.Engine;
using SchemaExplorer;
namespace Util{
public class Tools{
public static String GetDescription(ColumnSchema column) { //得到字段的描述
if(string.IsNullOrEmpty(column.Description))
return column.Name;
else
return column.Description;
}
public static bool NeedCascade(TableSchema SourceTable){ //判断表中是否需要下拉选择树
return SourceTable.Columns.Contains("ParentId")
|| SourceTable.Columns.Contains("CascadeId") ;
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using CodeSmith.Engine;
using SchemaExplorer;
namespace Util{
public class Tools{
public static String GetDescription(ColumnSchema column) { //得到字段的描述
if(string.IsNullOrEmpty(column.Description))
return column.Name;
else
return column.Description;
}
public static bool NeedCascade(TableSchema SourceTable){ //判断表中是否需要下拉选择树
return SourceTable.Columns.Contains("ParentId")
|| SourceTable.Columns.Contains("CascadeId") ;
}
}
}

View File

@@ -1,166 +1,166 @@
<%--
Name: 主JS界面
Author: yubaolee
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Assembly Src="Util.cs" %>
<%@ Import Namespace="Util" %>
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: '/<%=ModuleName%>Manager/Load',
where: config
});
}
//左边树状机构列表
var ztree = function () {
var url = '/UserSession/GetOrgs';
var zTreeObj;
var setting = {
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: {
onClick: function (event, treeId, treeNode) {
mainList({ orgId: treeNode.Id });
}
}
};
var load = function () {
$.getJSON(url, function (json) {
zTreeObj = $.fn.zTree.init($("#tree"), setting, json);
mainList({ orgId: json[0].Id });
zTreeObj.expandAll(true);
});
};
load();
return {
reload: load
}
}();
//添加(编辑)对话框
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 = "/<%=ModuleName%>Manager/Add";
if (update) {
url = "/<%=ModuleName%>Manager/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("/<%=ModuleName%>Manager/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
<%--
Name: 主JS界面
Author: yubaolee
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Assembly Src="Util.cs" %>
<%@ Import Namespace="Util" %>
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: '/<%=ModuleName%>Manager/Load',
where: config
});
}
//左边树状机构列表
var ztree = function () {
var url = '/UserSession/GetOrgs';
var zTreeObj;
var setting = {
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: {
onClick: function (event, treeId, treeNode) {
mainList({ orgId: treeNode.Id });
}
}
};
var load = function () {
$.getJSON(url, function (json) {
zTreeObj = $.fn.zTree.init($("#tree"), setting, json);
mainList({ orgId: json[0].Id });
zTreeObj.expandAll(true);
});
};
load();
return {
reload: load
}
}();
//添加(编辑)对话框
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 = "/<%=ModuleName%>Manager/Add";
if (update) {
url = "/<%=ModuleName%>Manager/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("/<%=ModuleName%>Manager/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
})