mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
后台内容管理
This commit is contained in:
parent
e9890b771a
commit
a9afd0d23d
@ -25,7 +25,8 @@ namespace FreeSql.Site.DAL
|
||||
/// <returns></returns>
|
||||
public bool Update(DocumentContent model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Update<DocumentContent>(model.ID).ExecuteUpdated().Count > 0;
|
||||
var runsql = DataBaseType.MySql.DB().Update<DocumentContent>().SetSource(model);
|
||||
return runsql.ExecuteAffrows() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -30,6 +30,7 @@ namespace FreeSql.Site.Entity
|
||||
/// <summary>
|
||||
/// 文档内容
|
||||
/// </summary>
|
||||
[Column(DbType = "text")]
|
||||
public string DocContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -29,7 +29,6 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
this.DocumentContentDAL = new DocumentContentDAL();
|
||||
}
|
||||
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
DocumentContent model = new DocumentContent();
|
||||
@ -87,7 +86,8 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
DocumentContent model = new DocumentContent();
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
model = DocumentContentDAL.GetByOne(w => w.ID == 1);
|
||||
int _id = Convert.ToInt32(id);
|
||||
model = DocumentContentDAL.GetByOne(w => w.ID == _id);
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
@ -108,6 +108,24 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers
|
||||
return Json(resdata);
|
||||
}
|
||||
|
||||
// POST: Documents/Create
|
||||
[HttpPost]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public ActionResult DocContentUpdate([FromBody]DocumentContent model)
|
||||
{
|
||||
var resdata = AutoException.Excute<bool>((result) =>
|
||||
{
|
||||
model.UpdateBy = "admin";
|
||||
model.UpdateDt = DateTime.Now;
|
||||
result.Data = DocumentContentDAL.Update(model);
|
||||
if (result.Data == false)
|
||||
{
|
||||
throw new Exception("数据新增异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
}
|
||||
}, false);
|
||||
return Json(resdata);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult DocContentDelete(int id, IFormCollection collection)
|
||||
|
@ -15,8 +15,8 @@
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>
|
||||
@*<button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>*@
|
||||
<div style="float:right;border:0px solid red;">
|
||||
<input type="text" name="search_txt" lay-verify="title" autocomplete="off" placeholder="标题" class="layui-input" style="height: 30px;width:160px;float:left;">
|
||||
<a href="#" style="line-height:30px;margin-left:8px;">高级查询</a>
|
||||
@ -65,24 +65,33 @@
|
||||
, { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
|
||||
]]
|
||||
, page: true
|
||||
, id : 'docContentTable'
|
||||
});
|
||||
|
||||
var reloadTable = function () {
|
||||
//执行重载
|
||||
table.reload('docContentTable', {
|
||||
page: {
|
||||
curr: 1 //重新从第 1 页开始
|
||||
}, where: { searchContent: $("input[type=search_txt]").val(), seniorQueryJson: "" }
|
||||
});
|
||||
};
|
||||
|
||||
//监听事件
|
||||
table.on('toolbar(test)', function (obj) {
|
||||
var checkStatus = table.checkStatus(obj.config.id);
|
||||
switch (obj.event) {
|
||||
case 'add':
|
||||
dialogWindow.open({
|
||||
type: 1,
|
||||
maxmin: true,
|
||||
var options = {
|
||||
url: "/Admin/Document/DocContentEditModule", paramters: { id: "" },
|
||||
title: "新增文档",
|
||||
area: ['1100px', '660px'],
|
||||
shadeClose: false, //点击遮罩关闭
|
||||
content: $("#docContentEdit").html(),
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentCreate",
|
||||
}
|
||||
}, form);
|
||||
},
|
||||
callback: reloadTable
|
||||
};
|
||||
dialogWindow.create(options);
|
||||
break;
|
||||
case 'delete':
|
||||
layer.msg('删除');
|
||||
@ -102,7 +111,7 @@
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Admin/Document/DocContentDelete",
|
||||
data: { id: docid },
|
||||
data: { id: data.ID },
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
obj.del();
|
||||
@ -115,26 +124,16 @@
|
||||
});
|
||||
});
|
||||
} else if (obj.event === 'edit') {
|
||||
$("#docContentEdit").load("/Admin/Document/DocContentEditModule", { id: data.ID }, function (responseText, textStatus, jqXHR) {
|
||||
switch (textStatus) {
|
||||
case "success":
|
||||
dialogWindow.open({
|
||||
type: 1,
|
||||
maxmin: true,
|
||||
title: "编辑文档",
|
||||
area: ['1100px', '660px'],
|
||||
shadeClose: false, //点击遮罩关闭
|
||||
content: responseText,
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentCreate",
|
||||
}
|
||||
}, form);
|
||||
break;
|
||||
case "error":
|
||||
freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 });
|
||||
break;
|
||||
}
|
||||
});
|
||||
var options = {
|
||||
url: "/Admin/Document/DocContentEditModule", paramters: { id: data.ID },
|
||||
title: "编辑文档",
|
||||
area: ['1100px', '660px'],
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentUpdate",
|
||||
},
|
||||
callback: reloadTable
|
||||
};
|
||||
dialogWindow.create(options);
|
||||
|
||||
//form.render();
|
||||
//layer.prompt({
|
||||
@ -151,6 +150,28 @@
|
||||
|
||||
//先简单封装下
|
||||
var dialogWindow = {
|
||||
create: function (options, formpage) {
|
||||
$("#docContentEdit").load(options.url, options.paramters, function (responseText, textStatus, jqXHR) {
|
||||
switch (textStatus) {
|
||||
case "success":
|
||||
dialogWindow.open($.extend({
|
||||
type: 1,
|
||||
maxmin: true,
|
||||
title: "编辑",
|
||||
area: ['1100px', '660px'],
|
||||
shadeClose: false, //点击遮罩关闭
|
||||
content: responseText,
|
||||
submit: {
|
||||
url: "/Admin/Document/DocContentCreate",
|
||||
}
|
||||
}, options), form);
|
||||
break;
|
||||
case "error":
|
||||
freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 });
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
open: function (options, form) {
|
||||
var base_options = {
|
||||
type: 1,
|
||||
@ -171,7 +192,6 @@
|
||||
});
|
||||
//监听提交
|
||||
form.on('submit(formDemo)', function (data) {
|
||||
debugger
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: options.submit.url,//"/Admin/Document/DocContentCreate",
|
||||
@ -179,7 +199,14 @@
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
success: function (e) {
|
||||
alert(JSON.stringify(e));
|
||||
if (e.Status == 1) {
|
||||
freejs.showMessage({ title: "提示", msg: e.Msg || "保存成功", type: 1 });
|
||||
if ($.isFunction(new_options.callback)) new_options.callback();
|
||||
layer.close(index);
|
||||
}
|
||||
else {
|
||||
freejs.showMessage({ title: "提示", msg: e.Msg, type: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
|
@ -2,18 +2,23 @@
|
||||
@model FreeSql.Site.Entity.DocumentContent
|
||||
|
||||
<form class="layui-form" action="" id="frm_DocContentEdit">
|
||||
@Html.HiddenFor(m => m.ID)
|
||||
@Html.HiddenFor(m => m.CreateBy)
|
||||
@Html.HiddenFor(m => m.CreateDt)
|
||||
@Html.HiddenFor(m => m.WatchCount)
|
||||
@Html.HiddenFor(m => m.StarCount)
|
||||
<div class="form-module-content">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章分类</label>
|
||||
<div class="layui-input-block">
|
||||
@*@Html.DropDownList("TypeID", ViewBag.DocumentTypeList as List<SelectListItem>, "", new Dictionary<string, object> { { "class", "plate_text" } })*@
|
||||
<select name="interest" lay-filter="aihao">
|
||||
<option value=""></option>
|
||||
@Html.DropDownList("TypeID", ViewBag.DocumentTypeList as List<SelectListItem>, "", new Dictionary<string, object> { { "class", "plate_text" } })
|
||||
@*<select name="TypeID" lay-filter="aihao">
|
||||
<option value="0" selected="selected">--请选择--</option>
|
||||
@foreach (var item in (List<SelectListItem>)ViewBag.DocumentTypeList)
|
||||
{
|
||||
<option value="@item.Value">@item.Text</option>
|
||||
}
|
||||
</select>
|
||||
{
|
||||
<option value="@item.Value">@item.Text</option>
|
||||
}
|
||||
</select>*@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -49,13 +54,13 @@
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">文本域</label>
|
||||
<div class="layui-input-block" id="md_DocContent">
|
||||
<textarea style="display:none;" placeholder="请输入内容" name="DocContent"></textarea>
|
||||
@Html.TextAreaFor(m => m.DocContent, new Dictionary<string, object> { { "autocomplete", "off" }, { "placeholder", "请输入内容" } })
|
||||
@*<textarea style="display:none;" placeholder="请输入内容" name="DocContent"></textarea>*@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-module-footer">
|
||||
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user