数据字典完成一半管理功能
This commit is contained in:
@@ -20,6 +20,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
[MyAuthorize("viewlist", "datadictionary")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
Admin.WriteLogActions($"查看数据字典页面;");
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
@@ -53,5 +54,147 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取数据字典
|
||||
[HttpPost]
|
||||
[MyAuthorize("edit", "datadictionary", "JSON")]
|
||||
public IActionResult GetDataDictionary(int id)
|
||||
{
|
||||
var entity = DataDictionary.Find(DataDictionary._.Id == id);
|
||||
if(entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本记录!";
|
||||
return Json(tip);
|
||||
}
|
||||
var detail = new
|
||||
{
|
||||
id = entity.Id,
|
||||
rank = entity.Rank,
|
||||
description = entity.Description,
|
||||
key = entity.Key
|
||||
};
|
||||
tip.Detail = detail;
|
||||
tip.Message = "获取成功!";
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
Admin.WriteLogActions($"查看数据字典({entity.Id});");
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 保存(添加或者修改)数据字典
|
||||
[HttpPost]
|
||||
[MyAuthorize("add", "datadictionary", "JSON")]
|
||||
public IActionResult DoSaveDataDictionary(DataDictionary model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Key))
|
||||
{
|
||||
tip.Message = "请输入字典Key";
|
||||
return Json(tip);
|
||||
}
|
||||
if(model.Id==0 && DataDictionary.FindCount(DataDictionary._.Key== model.Key, null, null, 0, 0) > 0)
|
||||
{
|
||||
tip.Message = "此字典Key已经存在,请填写其他的!";
|
||||
return Json(tip);
|
||||
}
|
||||
if(model.Id> 0 && DataDictionary.FindCount(DataDictionary._.Key == model.Key & DataDictionary._.Id !=model.Id, null, null, 0, 0) > 0)
|
||||
{
|
||||
tip.Message = "此字典Key已经存在,请填写其他的!";
|
||||
return Json(tip);
|
||||
}
|
||||
DataDictionary entity = null;
|
||||
string tipMessage = "";
|
||||
if (model.Id > 0)
|
||||
{
|
||||
entity = DataDictionary.Find(DataDictionary._.Id == model.Id);
|
||||
if(entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本记录!";
|
||||
return Json(tip);
|
||||
}
|
||||
tipMessage = "修改";
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = new DataDictionary();
|
||||
entity.AddTime = DateTime.Now;
|
||||
tipMessage = "添加";
|
||||
}
|
||||
entity.Key = model.Key;
|
||||
entity.Description = model.Description;
|
||||
entity.Rank = model.Rank;
|
||||
entity.Save();
|
||||
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.Message = $"{tipMessage}数据字典成功!";
|
||||
Admin.WriteLogActions($"{tipMessage}数据字典成功({entity.Id});");
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除数据字典
|
||||
[HttpPost]
|
||||
[MyAuthorize("del", "datadictionary", "JSON")]
|
||||
public IActionResult DelDataDictionary(int id)
|
||||
{
|
||||
var entity = DataDictionary.Find(DataDictionary._.Id == id);
|
||||
if (entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本记录!";
|
||||
return Json(tip);
|
||||
}
|
||||
//获取数据字典详情
|
||||
IList<DataDictionaryDetail> list = DataDictionaryDetail.FindAll(DataDictionaryDetail._.DataDictionaryId == entity.Id, null, null, 0, 0);
|
||||
if (list.Count > 0)
|
||||
{
|
||||
list.Delete();
|
||||
}
|
||||
Admin.WriteLogActions($"删除数据字典({entity.Id});");
|
||||
entity.Delete();
|
||||
|
||||
|
||||
tip.Message = "删除数据字典成功!";
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取字典值列表
|
||||
[HttpPost]
|
||||
[MyAuthorize("edit", "datadictionary", "JSON")]
|
||||
public IActionResult GetDataDictionaryDetail(int id)
|
||||
{
|
||||
var entity = DataDictionary.Find(DataDictionary._.Id == id);
|
||||
if (entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本记录!";
|
||||
return Json(tip);
|
||||
}
|
||||
//获取数据字典详情
|
||||
IList<DataDictionaryDetail> list = DataDictionaryDetail.FindAll(DataDictionaryDetail._.DataDictionaryId == entity.Id, DataDictionaryDetail._.Rank.Asc().And(DataDictionaryDetail._.Id.Desc()), null, 0, 0);
|
||||
|
||||
List<object> detail = new List<object>();
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
detail.Add(new
|
||||
{
|
||||
dataDictionaryId = item.DataDictionaryId,
|
||||
id = item.Id,
|
||||
val = item.Val,
|
||||
title = item.Title,
|
||||
description = item.Description,
|
||||
rank = item.Rank,
|
||||
isDefault = item.IsDefault,
|
||||
addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm")
|
||||
});
|
||||
}
|
||||
tip.Detail = detail;
|
||||
tip.Message = "获取成功!";
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
Admin.WriteLogActions($"查看数据字典值列表({entity.Id});");
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
</button>
|
||||
</div>
|
||||
<table id="tb_departments"></table>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
|
||||
@@ -88,8 +87,6 @@
|
||||
cardView: false, //是否显示详细视图
|
||||
detailView: false, //是否显示父子表
|
||||
columns: [{
|
||||
checkbox: true
|
||||
}, {
|
||||
field: 'id',
|
||||
title: 'ID'
|
||||
}, {
|
||||
@@ -130,34 +127,12 @@
|
||||
|
||||
function actionFormatter(value, row, index) {
|
||||
return [
|
||||
'<a href="javascript:;" class="btn btn-xs btn-primary" title="编辑" onclick="top.showDialog(\'eidtarticle\', \'编辑文章详情\', \'/AdminCP/DataDictionary/EditArticle/' + value + '\', 0, 0)"><i class="fa fa-edit"></i> 编辑</a>',
|
||||
'<a href="javascript:;" class="btn btn-xs btn-primary" title="编辑" onclick="app.getDataDictionary(' + value + ')"><i class="fa fa-edit"></i> 编辑</a>',
|
||||
'<a href="javascript:;" class="btn btn-xs btn-success" title="编辑" onclick="app.getDataDictionaryDetail(' + value + ')"><i class="fa fa-edit"></i> 管理字典值</a>',
|
||||
'<a href="javascript:;" class="btn btn-xs btn-danger m-l-xs" title="删除" onclick="doDel(\'/AdminCP/DataDictionary/DelDataDictionary\',' + value + ');"><i class="fa fa-close"></i> 删除</a>',
|
||||
].join('');
|
||||
}
|
||||
|
||||
function newFormatter(value, row, index) {
|
||||
if (value == 1) {
|
||||
return '<i class="fa fa-circle-o"></i>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function recommendFormatter(value, row, index) {
|
||||
if (value == 1) {
|
||||
return '<i class="fa fa-star"></i>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
function hideFormatter(value, row, index) {
|
||||
if (value == 1) {
|
||||
return '<i class="fa fa-eye-slash"></i>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
var ButtonInit = function () {
|
||||
var oInit = new Object();
|
||||
var postdata = {};
|
||||
@@ -176,9 +151,9 @@
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="row form-horizontal">
|
||||
<div class="col-sm-12">
|
||||
<h3 class="m-t-none m-b">{{optTitle}}</h3>
|
||||
<h3 class="m-t-none m-b">{{model.id==0?'添加新数据字典':'编辑数据字典'}}</h3>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">字典Key:</label>
|
||||
@@ -216,19 +191,90 @@
|
||||
<div class="col-sm-6">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5>数据字典详情</h5>
|
||||
<h5>字典值详情</h5>
|
||||
<div class="ibox-tools">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div id="toolbar" class="btn-group">
|
||||
<button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="top.showDialog('addarticle','添加文章','/AdminCP/Article/AddArticle',0,0)">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
</div>
|
||||
<table id="tb_departments"></table>
|
||||
<div v-show="showDetail">
|
||||
<div id="toolbar" class="btn-group">
|
||||
<button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="top.showDialog('addarticle','添加文章','/AdminCP/Article/AddArticle',0,0)">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
</div>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>值</th>
|
||||
<th>标签</th>
|
||||
<th>排序</th>
|
||||
<th>是否默认</th>
|
||||
<th>说明</th>
|
||||
<th>添加时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item,index) in detailList" v-bind:key="id">
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>{{item.id}}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary btn-xm" v-on:click="doEditDetail(item)"><i class="fa fa-edit"></i> 编辑</button>
|
||||
<button class="btn btn-danger btn-sm" v-on:click="doDelDetail(item.id)"><i class="fa fa-close"></i> 删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="detailList.length>0">
|
||||
<td colspan="8">暂无记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="detailModal" class="modal fade" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<div class="row form-horizontal">
|
||||
<div class="col-sm-12">
|
||||
<h3 class="m-t-none m-b">{{detailModel.id==0?'添加新数据字典值':'编辑数据字典值'}}</h3>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">字典值Key:</label>
|
||||
<div class="col-sm-8">
|
||||
<input v-model="model.key" type="text" class="form-control" maxlength="250" placeholder="字典Key,请填写英文" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">字典说明:</label>
|
||||
<div class="col-sm-8">
|
||||
<input v-model="model.description" type="text" class="form-control" maxlength="250" placeholder="字典说明" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">字典排序:</label>
|
||||
<div class="col-sm-8">
|
||||
<input v-model="model.rank" type="number" class="form-control" maxlength="250" placeholder="字典排序,越小越前,仅后台" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-5 col-sm-offset-3">
|
||||
<input type="hidden" v-model="model.id" />
|
||||
<button class="btn btn-primary" type="button" v-on:click="doSaveDataDictionary"><i class="fa fa-save"></i> 确定 </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -240,12 +286,43 @@
|
||||
el: '#app',
|
||||
data: {
|
||||
model: { key: '', id: 0, rank: 0, description:''},
|
||||
optTitle:'添加字典'
|
||||
|
||||
optTitle: '添加字典',
|
||||
showDetail: false,
|
||||
detailList: [],
|
||||
detailModel: {}
|
||||
},
|
||||
methods: {
|
||||
getDataDictionary: function (id) {
|
||||
console.log('获取详情:', id);
|
||||
//console.log('获取详情:', id);
|
||||
let that = this;
|
||||
if (id == 0) {
|
||||
this.model = { key: '', id: 0, rank: 0, description: '' };
|
||||
$("#myModal").modal('show');
|
||||
return;
|
||||
}
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/AdminCP/DataDictionary/GetDataDictionary",
|
||||
data: {id:id},
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
that.model = data.detail;
|
||||
$("#myModal").modal('show');
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
},
|
||||
doSaveDataDictionary: function () {
|
||||
var that = this;
|
||||
@@ -256,6 +333,62 @@
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/AdminCP/DataDictionary/DoSaveDataDictionary",
|
||||
data: that.model,
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
layer.msg(data.message, {
|
||||
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
$('#myModal').modal('hide')
|
||||
$("#tb_departments").bootstrapTable('refresh');
|
||||
});
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
},
|
||||
getDataDictionaryDetail: function (id) {
|
||||
let that = this;
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/AdminCP/DataDictionary/GetDataDictionaryDetail",
|
||||
data: { id: id },
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
that.showDetail = true;
|
||||
that.detailList = data.detail;
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
},
|
||||
doEditDetail: function (item) {
|
||||
|
||||
},
|
||||
doDelDetail: function (id) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3,9 +3,9 @@ function showDialog(id, title, url, width, height) {
|
||||
top.showDialog(id, title, url, width, height)
|
||||
}
|
||||
//删除数据
|
||||
function doDel(url, id) {
|
||||
top.doDel(url, id);
|
||||
}
|
||||
//function doDel(url, id) {
|
||||
// top.doDel(url, id);
|
||||
//}
|
||||
//刷新网页
|
||||
function refresh() {
|
||||
|
||||
|
||||
@@ -114,12 +114,13 @@ function DoPost(formId, rules, messages) {
|
||||
}
|
||||
//后台异步删除
|
||||
function doDel(url, id) {
|
||||
layer.confirm('确认要删除当前记录?此操作不可恢复!', {
|
||||
//console.log('找到记录:' + $("#tb_departments").length, window.location.href);
|
||||
top.layer.confirm('确认要删除当前记录?此操作不可恢复!', {
|
||||
icon: 3,
|
||||
title: '系统提示',
|
||||
btn: ['确定', '取消 '] //按钮
|
||||
}, function () {
|
||||
var loading = layer.load(0, {
|
||||
var loading = top.layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
@@ -129,36 +130,36 @@ function doDel(url, id) {
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
layer.msg(data.message, {
|
||||
top.layer.close(loading);
|
||||
top.layer.msg(data.message, {
|
||||
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
if ($("#row_" + id).length > 0) {
|
||||
$("#row_" + id).fadeOut(300).remove();
|
||||
if ($("#tb_departments").length > 0) {
|
||||
$("#tb_departments").bootstrapTable('refresh');
|
||||
} else {
|
||||
//window.location.href = window.location.href;
|
||||
var dindex = parent.layer.getFrameIndex(window.name);
|
||||
if (dindex) {
|
||||
layer.close(dindex);
|
||||
return;
|
||||
}
|
||||
if (top.toplayerindex) {
|
||||
//window.location.href = window.location.href;
|
||||
} else {
|
||||
top.refreshCurrentTab();//刷新本tab
|
||||
}
|
||||
window.location.href = window.location.href;
|
||||
//var dindex = parent.layer.getFrameIndex(window.name);
|
||||
//if (dindex) {
|
||||
// layer.close(dindex);
|
||||
// return;
|
||||
//}
|
||||
//if (top.toplayerindex) {
|
||||
// //window.location.href = window.location.href;
|
||||
//} else {
|
||||
// top.refreshCurrentTab();//刷新本tab
|
||||
//}
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
top.layer.close(loading);
|
||||
top.layer.alert(data.message, { icon: 2 });
|
||||
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
top.layer.close(loading);
|
||||
top.layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
|
||||
Reference in New Issue
Block a user