mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
文档类型管理完善
This commit is contained in:
parent
96c2a66131
commit
054f85de36
@ -27,7 +27,8 @@ namespace FreeSql.Site.DAL
|
||||
/// <returns></returns>
|
||||
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>
|
||||
|
@ -118,7 +118,7 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public ActionResult DocContentDelete(int id, IFormCollection collection)
|
||||
{
|
||||
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();
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
if (ischildren)
|
||||
{
|
||||
int _id = Convert.ToInt32(id);
|
||||
model = DocumentTypeDAL.GetByOne(w => w.ID == _id);
|
||||
if (!string.IsNullOrEmpty(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);
|
||||
}
|
||||
@ -189,11 +201,13 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
// POST: Documents/Create
|
||||
[HttpPost]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public ActionResult DocTypeCreate([FromBody]DocumentContent model)
|
||||
public ActionResult DocTypeCreate([FromBody]DocumentType model)
|
||||
{
|
||||
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)
|
||||
{
|
||||
throw new Exception("数据新增异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
@ -205,13 +219,13 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
// POST: Documents/Create
|
||||
[HttpPost]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public ActionResult DocTypeUpdate([FromBody]DocumentContent model)
|
||||
public ActionResult DocTypeUpdate([FromBody]DocumentType model)
|
||||
{
|
||||
var resdata = AutoException.Excute<bool>((result) =>
|
||||
{
|
||||
model.UpdateBy = "admin";
|
||||
model.UpdateDt = DateTime.Now;
|
||||
result.Data = DocumentContentDAL.Update(model);
|
||||
result.Data = DocumentTypeDAL.Update(model);
|
||||
if (result.Data == false)
|
||||
{
|
||||
throw new Exception("数据新增异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
@ -221,12 +235,12 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public ActionResult DocTypeDelete(int id, IFormCollection collection)
|
||||
{
|
||||
var resdata = AutoException.Excute<long>((result) =>
|
||||
{
|
||||
if (!DocumentContentDAL.Delete(id))
|
||||
if (!DocumentTypeDAL.Delete(id))
|
||||
{
|
||||
throw new Exception("数据删除异常,ID:" + id);
|
||||
}
|
||||
|
@ -6,7 +6,11 @@
|
||||
<script>
|
||||
var dialog_Paramters = { height: 660, width: 1100 };
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.layui-table, .layui-table-view {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<table class="layui-table" id="test" lay-filter="test"></table>
|
||||
|
||||
<script type="text/html" id="docContentEdit">
|
||||
@ -99,9 +103,10 @@
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentCreate",
|
||||
},
|
||||
elmid: "docContentEdit",
|
||||
callback: reloadTable
|
||||
};
|
||||
freejs.dialogWindow.create(options);
|
||||
freejs.dialogWindow.create(options, form);
|
||||
break;
|
||||
case 'delete':
|
||||
var data = checkStatus.data;
|
||||
@ -143,9 +148,10 @@
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentUpdate",
|
||||
},
|
||||
elmid: "docContentEdit",
|
||||
callback: reloadTable
|
||||
};
|
||||
freejs.dialogWindow.create(options);
|
||||
freejs.dialogWindow.create(options, form);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -4,92 +4,150 @@
|
||||
//Layout = "~/Areas/Admin/Shared/_Layout.cshtml";
|
||||
}
|
||||
<style>
|
||||
body {
|
||||
padding: 10px 30px;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none
|
||||
}
|
||||
</style>
|
||||
<button class="layui-btn layui-btn-primary down-up-all">全部收起/展开</button>
|
||||
<button class="layui-btn layui-btn-primary get-checked">获取选中</button>
|
||||
<script>
|
||||
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>
|
||||
|
||||
<script type="text/html" id="docTypeEdit">
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
layui.use(['treetable', 'form'], function () {
|
||||
var data = @Html.Raw(Html.ToJson(ViewBag.TypeList as List<DocumentTypeTreeNode>));
|
||||
|
||||
var o = layui.$, treetable = layui.treetable;
|
||||
var form = layui.form, layer = layui.layer;
|
||||
treetable.render({
|
||||
elem: '#doctype-tree-table',
|
||||
data: data,
|
||||
field: 'title',
|
||||
is_checkbox: true,
|
||||
checked: [1, 2, 3, 4],
|
||||
/*icon_val: {
|
||||
open: "",
|
||||
close: ""
|
||||
},
|
||||
space: 4,*/
|
||||
cols: [
|
||||
{
|
||||
field: 'title',
|
||||
title: '标题',
|
||||
width: '40%',
|
||||
template: function (item) {
|
||||
if (item.level == 1) {
|
||||
return '<span style="color:red;">' + item.title + '</span>';
|
||||
var loadTreeTable = function () {
|
||||
treetable.render({
|
||||
elem: '#doctype-tree-table',
|
||||
data: data,
|
||||
field: 'title',
|
||||
is_checkbox: true,
|
||||
checked: [1, 2, 3, 4],
|
||||
/*icon_val: {
|
||||
open: "",
|
||||
close: ""
|
||||
},
|
||||
space: 4,*/
|
||||
cols: [
|
||||
{
|
||||
field: 'title',
|
||||
title: '标题',
|
||||
width: '40%',
|
||||
template: function (item) {
|
||||
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) {
|
||||
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);
|
||||
})
|
||||
|
||||
treetable.on('treetable(edit)', function (data) {
|
||||
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 () {
|
||||
@ -99,7 +157,7 @@
|
||||
})
|
||||
|
||||
o('.get-checked').click(function () {
|
||||
console.log(treetable.all('checked'));
|
||||
layer.alert(JSON.stringify(treetable.all('checked')));
|
||||
})
|
||||
|
||||
form.on('switch(status)', function (data) {
|
||||
|
@ -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>
|
@ -31,30 +31,10 @@
|
||||
var path_json = $(this).attr("datajson");
|
||||
|
||||
var index = freejs.showLoading({ msg: "数据加载中......" });
|
||||
$("#page_content").load(path_item, $.parseJSON(path_json), function (responseText, textStatus, jqXHR) {
|
||||
freejs.closeLoading(index);
|
||||
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;
|
||||
}
|
||||
});
|
||||
var options = {
|
||||
url: path_item, paramters: $.parseJSON(path_json), loadIndex: index
|
||||
};
|
||||
freejs.loadHtml(options);
|
||||
|
||||
//如果出现长时间未关闭,定时关闭loading
|
||||
setTimeout(function () {
|
||||
|
@ -4,7 +4,7 @@
|
||||
}
|
||||
|
||||
.layui-form-label {
|
||||
width: 110px;
|
||||
width: 80px;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
.form-module-footer {
|
||||
border: 0px solid red;
|
||||
height: 60px;
|
||||
height: 55px;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
border-top: 5px solid #e8e8e8;
|
||||
@ -33,6 +33,11 @@
|
||||
bottom: 0px;
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
z-index:100;
|
||||
padding:6px;
|
||||
z-index: 100;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.form-module-footer button {
|
||||
margin-right: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
@ -136,7 +136,8 @@
|
||||
callback: reloadTable //执行完成回调函数
|
||||
*/
|
||||
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) {
|
||||
case "success":
|
||||
freejs.dialogWindow.open($.extend({
|
||||
@ -149,7 +150,7 @@
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentCreate",
|
||||
}
|
||||
}, options), form);
|
||||
}, options), formpage);
|
||||
break;
|
||||
case "error":
|
||||
freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 });
|
||||
@ -214,6 +215,39 @@
|
||||
},
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user