文档类型管理完善

This commit is contained in:
hogan 2019-01-26 01:10:53 +08:00
parent 96c2a66131
commit 054f85de36
8 changed files with 249 additions and 112 deletions

View File

@ -27,7 +27,8 @@ namespace FreeSql.Site.DAL
/// <returns></returns> /// <returns></returns>
public virtual bool Update(T model) public virtual bool Update(T model)
{ {
return DataBaseType.MySql.DB().Update<T>(model.ID).ExecuteUpdated().Count > 0; var runsql = DataBaseType.MySql.DB().Update<T>().SetSource(model);
return runsql.ExecuteAffrows() > 0;
} }
/// <summary> /// <summary>

View File

@ -118,7 +118,7 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
} }
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public ActionResult DocContentDelete(int id, IFormCollection collection) public ActionResult DocContentDelete(int id, IFormCollection collection)
{ {
var resdata = AutoException.Excute<long>((result) => var resdata = AutoException.Excute<long>((result) =>
@ -175,13 +175,25 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
}); });
} }
public ActionResult DocTypeEditModule(string id) public ActionResult DocTypeEditModule(string id, bool ischildren)
{ {
ViewBag.DocumentTypeList = DocumentTypeDAL.Query(w => w.Status == 1).list.Select(s => new SelectListItem { Text = s.TypeName, Value = s.ID.ToString() }).ToList();
DocumentType model = new DocumentType(); DocumentType model = new DocumentType();
if (!string.IsNullOrEmpty(id)) if (ischildren)
{ {
int _id = Convert.ToInt32(id); if (!string.IsNullOrEmpty(id))
model = DocumentTypeDAL.GetByOne(w => w.ID == _id); {
model.UpID = Convert.ToInt32(id);
}
}
else
{
if (!string.IsNullOrEmpty(id))
{
int _id = Convert.ToInt32(id);
model = DocumentTypeDAL.GetByOne(w => w.ID == _id);
}
} }
return View(model); return View(model);
} }
@ -189,11 +201,13 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
// POST: Documents/Create // POST: Documents/Create
[HttpPost] [HttpPost]
//[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public ActionResult DocTypeCreate([FromBody]DocumentContent model) public ActionResult DocTypeCreate([FromBody]DocumentType model)
{ {
var resdata = AutoException.Excute<long>((result) => var resdata = AutoException.Excute<long>((result) =>
{ {
result.Data = DocumentContentDAL.Insert(model); model.CreateBy = "admin";
model.CreateDt = DateTime.Now;
result.Data = DocumentTypeDAL.Insert(model);
if (result.Data == 0) if (result.Data == 0)
{ {
throw new Exception("数据新增异常JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model)); throw new Exception("数据新增异常JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
@ -205,13 +219,13 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
// POST: Documents/Create // POST: Documents/Create
[HttpPost] [HttpPost]
//[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public ActionResult DocTypeUpdate([FromBody]DocumentContent model) public ActionResult DocTypeUpdate([FromBody]DocumentType model)
{ {
var resdata = AutoException.Excute<bool>((result) => var resdata = AutoException.Excute<bool>((result) =>
{ {
model.UpdateBy = "admin"; model.UpdateBy = "admin";
model.UpdateDt = DateTime.Now; model.UpdateDt = DateTime.Now;
result.Data = DocumentContentDAL.Update(model); result.Data = DocumentTypeDAL.Update(model);
if (result.Data == false) if (result.Data == false)
{ {
throw new Exception("数据新增异常JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model)); throw new Exception("数据新增异常JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
@ -220,13 +234,13 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
return Json(resdata); return Json(resdata);
} }
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public ActionResult DocTypeDelete(int id, IFormCollection collection) public ActionResult DocTypeDelete(int id, IFormCollection collection)
{ {
var resdata = AutoException.Excute<long>((result) => var resdata = AutoException.Excute<long>((result) =>
{ {
if (!DocumentContentDAL.Delete(id)) if (!DocumentTypeDAL.Delete(id))
{ {
throw new Exception("数据删除异常ID:" + id); throw new Exception("数据删除异常ID:" + id);
} }

View File

@ -6,7 +6,11 @@
<script> <script>
var dialog_Paramters = { height: 660, width: 1100 }; var dialog_Paramters = { height: 660, width: 1100 };
</script> </script>
<style>
.layui-table, .layui-table-view {
margin: 0;
}
</style>
<table class="layui-table" id="test" lay-filter="test"></table> <table class="layui-table" id="test" lay-filter="test"></table>
<script type="text/html" id="docContentEdit"> <script type="text/html" id="docContentEdit">
@ -99,9 +103,10 @@
submit: { submit: {
url: "/Admin/Document/DocContentCreate", url: "/Admin/Document/DocContentCreate",
}, },
elmid: "docContentEdit",
callback: reloadTable callback: reloadTable
}; };
freejs.dialogWindow.create(options); freejs.dialogWindow.create(options, form);
break; break;
case 'delete': case 'delete':
var data = checkStatus.data; var data = checkStatus.data;
@ -143,9 +148,10 @@
submit: { submit: {
url: "/Admin/Document/DocContentUpdate", url: "/Admin/Document/DocContentUpdate",
}, },
elmid: "docContentEdit",
callback: reloadTable callback: reloadTable
}; };
freejs.dialogWindow.create(options); freejs.dialogWindow.create(options, form);
} }
}); });

View File

@ -4,92 +4,150 @@
//Layout = "~/Areas/Admin/Shared/_Layout.cshtml"; //Layout = "~/Areas/Admin/Shared/_Layout.cshtml";
} }
<style> <style>
body {
padding: 10px 30px;
}
.hide { .hide {
display: none display: none
} }
</style> </style>
<button class="layui-btn layui-btn-primary down-up-all">全部收起/展开</button> <script>
<button class="layui-btn layui-btn-primary get-checked">获取选中</button> var dialog_Paramters = { height: 460, width: 600 };
</script>
<button class="layui-btn layui-btn-primary layui-btn-xs down-up-all">全部收起/展开</button>
<button class="layui-btn layui-btn-primary layui-btn-xs get-checked">获取选中</button>
<table class="layui-table layui-form" id="doctype-tree-table"></table> <table class="layui-table layui-form" id="doctype-tree-table"></table>
<script type="text/html" id="docTypeEdit">
</script>
<script type="text/javascript"> <script type="text/javascript">
layui.use(['treetable', 'form'], function () { layui.use(['treetable', 'form'], function () {
var data = @Html.Raw(Html.ToJson(ViewBag.TypeList as List<DocumentTypeTreeNode>)); var data = @Html.Raw(Html.ToJson(ViewBag.TypeList as List<DocumentTypeTreeNode>));
var o = layui.$, treetable = layui.treetable; var o = layui.$, treetable = layui.treetable;
var form = layui.form, layer = layui.layer; var form = layui.form, layer = layui.layer;
treetable.render({ var loadTreeTable = function () {
elem: '#doctype-tree-table', treetable.render({
data: data, elem: '#doctype-tree-table',
field: 'title', data: data,
is_checkbox: true, field: 'title',
checked: [1, 2, 3, 4], is_checkbox: true,
/*icon_val: { checked: [1, 2, 3, 4],
open: "&#xe619;", /*icon_val: {
close: "&#xe61a;" open: "&#xe619;",
}, close: "&#xe61a;"
space: 4,*/ },
cols: [ space: 4,*/
{ cols: [
field: 'title', {
title: '标题', field: 'title',
width: '40%', title: '标题',
template: function (item) { width: '40%',
if (item.level == 1) { template: function (item) {
return '<span style="color:red;">' + item.title + '</span>'; if (item.level == 1) {
return '<span style="color:red;">' + item.title + '</span>';
}
if (item.level == 2) {
return '<span style="color:green;">' + item.title + '</span>';
}
return item.title;
} }
if (item.level == 2) {
return '<span style="color:green;">' + item.title + '</span>';
}
return item.title;
}
},
{
field: 'id',
title: '编号',
width: '10%'
},
{
title: '标签',
width: '10%',
template: function (item) {
return item.tag||"";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
}
},
{
title: '创建时间',
width: '20%',
template: function (item) {
return item.createdt.replace('T',' ') || "";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
}
},
{
field: 'actions',
title: '操作',
width: '20%',
template: function (item) {
var tem = [];
tem.push('<button class="layui-btn layui-btn-xs layui-btn-normal">添加子级</button>');
tem.push('<button class="layui-btn layui-btn-xs">编辑</button>');
return tem.join(' ')
}, },
}, {
] field: 'id',
}); title: '编号',
width: '10%'
},
{
title: '标签',
width: '10%',
template: function (item) {
return item.tag || "";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
}
},
{
title: '创建时间',
width: '20%',
template: function (item) {
return (item.createdt || "").replace('T', ' ') || "";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
}
},
{
field: 'actions',
title: '操作',
width: '20%',
template: function (item) {
var tem = [];
tem.push('<button class="layui-btn layui-btn-xs layui-btn-normal" lay-filter="add">添加子级</button>');
tem.push('<button class="layui-btn layui-btn-xs" lay-filter="edit">编辑</button>');
tem.push('<button class="layui-btn layui-btn-xs" lay-filter="delete">删除</button>');
return tem.join(' ')
},
},
]
});
};
loadTreeTable();
var reloadTable = function () {
//执行重载
//loadTreeTable();
//layer.msg('树的刷新功能暂未实现');
var options = {
url: "/Admin/Document/DocType", paramters: {}
};
freejs.loadHtml(options);
};
treetable.on('treetable(add)', function (data) { treetable.on('treetable(add)', function (data) {
layer.msg('添加操作'); var options = {
url: "/Admin/Document/DocTypeEditModule", paramters: { id: data.item.id, ischildren: true },
title: "新增分类",
area: ['600px', '460px'],
submit: {
url: "/Admin/Document/DocTypeCreate",
},
elmid:"docTypeEdit",
callback: reloadTable
};
freejs.dialogWindow.create(options, form);
console.log(data); console.log(data);
}) })
treetable.on('treetable(edit)', function (data) { treetable.on('treetable(edit)', function (data) {
layer.msg('编辑操作'); layer.msg('编辑操作');
console.log(data); var options = {
url: "/Admin/Document/DocTypeEditModule", paramters: { id: data.item.id, ischildren: false },
title: "编辑分类",
area: ['600px', '460px'],
submit: {
url: "/Admin/Document/DocTypeUpdate",
},
elmid: "docTypeEdit",
callback: reloadTable
};
freejs.dialogWindow.create(options, form);
});
treetable.on('treetable(delete)', function (data) {
layer.confirm('确定要删除吗?', function (index) {
//调用删除
$.ajax({
type: "POST",
url: "/Admin/Document/DocTypeDelete",
data: { id: data.item.id },
dataType: "html",
success: function (data) {
layer.close(index);
},
error: function () {
layer.close(index);
layer.alert("删除失败!");
}
});
});
}) })
o('.down-up-all').click(function () { o('.down-up-all').click(function () {
@ -99,7 +157,7 @@
}) })
o('.get-checked').click(function () { o('.get-checked').click(function () {
console.log(treetable.all('checked')); layer.alert(JSON.stringify(treetable.all('checked')));
}) })
form.on('switch(status)', function (data) { form.on('switch(status)', function (data) {

View File

@ -0,0 +1,39 @@
@using FreeSql.Site.Entity;
@model FreeSql.Site.Entity.DocumentType
<form class="layui-form" action="" id="frm_DocTypeEdit">
@Html.HiddenFor(m => m.ID)
@Html.HiddenFor(m => m.CreateBy)
@Html.HiddenFor(m => m.CreateDt)
<div class="form-module-content">
<div class="layui-form-item">
<label class="layui-form-label">上级分类</label>
<div class="layui-input-block">
@Html.DropDownList("UpID", ViewBag.DocumentTypeList as List<SelectListItem>, "", new Dictionary<string, object> { { "class", "plate_text" } })
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分类名称</label>
<div class="layui-input-block">
@Html.TextBoxFor(m => m.TypeName, "", new Dictionary<string, object> { { "autocomplete", "off" }, { "class", "layui-input " }, { "lay-verify", "title" }, { "placeholder", "请输入标题" } })
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">标签</label>
<div class="layui-input-block">
@Html.TextBoxFor(m => m.Tag, "", new Dictionary<string, object> { { "autocomplete", "off" }, { "class", "layui-input " }, { "lay-verify", "title" }, { "placeholder", "请输入摘要" } })
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="1" title="启用" checked="">
<input type="radio" name="status" value="0" title="关闭">
</div>
</div>
</div>
<div class="form-module-footer">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
</div>
</form>

View File

@ -31,30 +31,10 @@
var path_json = $(this).attr("datajson"); var path_json = $(this).attr("datajson");
var index = freejs.showLoading({ msg: "数据加载中......" }); var index = freejs.showLoading({ msg: "数据加载中......" });
$("#page_content").load(path_item, $.parseJSON(path_json), function (responseText, textStatus, jqXHR) { var options = {
freejs.closeLoading(index); url: path_item, paramters: $.parseJSON(path_json), loadIndex: index
switch (textStatus) { };
case "success": freejs.loadHtml(options);
//初始化绑定页面的时间,例如时间控件
index = -1;
layui.use('form', function () {
var form = layui.form;
});
break;
//case "notmodified":
//case "error":
//case "timeout":
//case "parsererror":
//spf.loadHtml(mcid, "/Service/Error/", function (jElement, responseText) {
// loadResultShow(jElement, responseText, spTitle, spHead);
//});
//break;
case "error":
$("#page_content").html(responseText);
break;
}
});
//如果出现长时间未关闭定时关闭loading //如果出现长时间未关闭定时关闭loading
setTimeout(function () { setTimeout(function () {

View File

@ -4,7 +4,7 @@
} }
.layui-form-label { .layui-form-label {
width: 110px; width: 80px;
font-weight:bold; font-weight:bold;
} }
@ -24,7 +24,7 @@
.form-module-footer { .form-module-footer {
border: 0px solid red; border: 0px solid red;
height: 60px; height: 55px;
width: 100%; width: 100%;
position: absolute; position: absolute;
border-top: 5px solid #e8e8e8; border-top: 5px solid #e8e8e8;
@ -33,6 +33,11 @@
bottom: 0px; bottom: 0px;
width: 100%; width: 100%;
text-align: right; text-align: right;
z-index:100; z-index: 100;
padding:6px; padding: 0px;
} }
.form-module-footer button {
margin-right: 10px;
margin-top: 10px;
}

View File

@ -136,7 +136,8 @@
callback: reloadTable //执行完成回调函数 callback: reloadTable //执行完成回调函数
*/ */
create: function (options, formpage) { create: function (options, formpage) {
$("#docContentEdit").load(options.url, options.paramters, function (responseText, textStatus, jqXHR) { //docContentEdit
$("#" + options.elmid).load(options.url, options.paramters, function (responseText, textStatus, jqXHR) {
switch (textStatus) { switch (textStatus) {
case "success": case "success":
freejs.dialogWindow.open($.extend({ freejs.dialogWindow.open($.extend({
@ -149,7 +150,7 @@
submit: { submit: {
url: "/Admin/Document/DocContentCreate", url: "/Admin/Document/DocContentCreate",
} }
}, options), form); }, options), formpage);
break; break;
case "error": case "error":
freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 }); freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 });
@ -214,6 +215,39 @@
}, },
close: function () { close: function () {
} }
},
loadHtml: function (options) {
//options = {
// url: "/Admin/Document/DocType", paramters: {},loadIndex:1
//};
$("#page_content").load(options.url, options.paramters, function (responseText, textStatus, jqXHR) {
freejs.closeLoading(options.loadIndex);
switch (textStatus) {
case "success":
//初始化绑定页面的时间,例如时间控件
index = -1;
layui.use('form', function () {
var form = layui.form;
});
break;
//case "notmodified":
//case "error":
//case "timeout":
//case "parsererror":
//spf.loadHtml(mcid, "/Service/Error/", function (jElement, responseText) {
// loadResultShow(jElement, responseText, spTitle, spHead);
//});
//break;
case "error":
$("#page_content").html(responseText);
break;
}
});
//如果出现长时间未关闭定时关闭loading
setTimeout(function () {
if (options.loadIndex >= 0) freejs.closeLoading(options.loadIndex);
}, 5000);
} }
}; };
window.freejs = new base(); window.freejs = new base();