mirror of https://gitee.com/stylefeng/guns
【Dict】完善新的字典功能
parent
504245a5e9
commit
d4c2ced31f
|
@ -0,0 +1,220 @@
|
|||
layui.use(['layer', 'form', 'table', 'util', 'admin', 'func', 'HttpRequest'], function () {
|
||||
var $ = layui.jquery;
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
var admin = layui.admin;
|
||||
var HttpRequest = layui.HttpRequest;
|
||||
var func = layui.func;
|
||||
var selObj; // 左表选中数据
|
||||
|
||||
var Dict = {
|
||||
tableId: "dictTable",
|
||||
};
|
||||
|
||||
var DictType = {
|
||||
tableId: "dictTypeTable"
|
||||
};
|
||||
|
||||
|
||||
/* 字典类型-点击新增对话框 */
|
||||
DictType.openAddDlg = function () {
|
||||
func.open({
|
||||
height: 700,
|
||||
title: '添加字典类型',
|
||||
content: Feng.ctxPath + '/view/dictType/addView',
|
||||
tableId: DictType.tableId
|
||||
});
|
||||
};
|
||||
|
||||
/* 字典类型-点击编辑对话框 */
|
||||
DictType.openEditDlg = function (data) {
|
||||
func.open({
|
||||
height: 700,
|
||||
title: '修改字典类型',
|
||||
content: Feng.ctxPath + '/view/dictType/editView?dictTypeId=' + data.dictTypeId,
|
||||
tableId: DictType.tableId
|
||||
});
|
||||
};
|
||||
|
||||
/* 字典类型-点击删除 */
|
||||
DictType.onDeleteItem = function (data) {
|
||||
if (data.dictTypeClass === 2) {
|
||||
Feng.error("系统类型无法删除");
|
||||
return;
|
||||
}
|
||||
var operation = function () {
|
||||
var httpRequest = new HttpRequest(Feng.ctxPath + "/dictType/deleteDictType", 'post', function (data) {
|
||||
Feng.success("删除成功!");
|
||||
table.reload(DictType.tableId);
|
||||
}, function (data) {
|
||||
Feng.error("删除失败!" + data.message + "!");
|
||||
});
|
||||
httpRequest.set(data);
|
||||
httpRequest.start(true);
|
||||
};
|
||||
Feng.confirm("是否删除?", operation);
|
||||
};
|
||||
|
||||
/* 字典类型-点击搜索 */
|
||||
form.on('submit(dictTypeTbSearch)', function (data) {
|
||||
dictTypeTable.reload({where: data.field});
|
||||
return false;
|
||||
});
|
||||
|
||||
/* 字典类型-点击表格头工具栏 */
|
||||
table.on('toolbar(dictTypeTable)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'add') { // 添加
|
||||
DictType.openAddDlg();
|
||||
} else if (obj.event === 'edit') { // 修改
|
||||
DictType.openEditDlg(data);
|
||||
} else if (obj.event === 'del') { // 删除
|
||||
DictType.onDeleteItem(data);
|
||||
}
|
||||
});
|
||||
|
||||
/* 字典类型-渲染表格 */
|
||||
var dictTypeTable = table.render({
|
||||
elem: '#dictTypeTable',
|
||||
url: Feng.ctxPath + '/dictType/getDictTypePageList',
|
||||
height: 'full-100',
|
||||
toolbar: '#dictTypeHtbBar',
|
||||
defaultToolbar: [], //默认表格头部右侧工具栏
|
||||
cols: [[
|
||||
{type: 'numbers'},
|
||||
{field: 'dictTypeName', title: '类型'},
|
||||
{field: 'dictTypeCode', title: '编码'},
|
||||
]],
|
||||
done: function (res, curr, count) {
|
||||
//加载后自动选中第一行并出发click事件
|
||||
$('#dictTypeTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
|
||||
},
|
||||
parseData: Feng.parseData //解析成 table 组件所规定的数据格式
|
||||
});
|
||||
|
||||
/* 字典类型-监听行单击事件 */
|
||||
table.on('row(dictTypeTable)', function (obj) {
|
||||
selObj = obj;
|
||||
obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
|
||||
dictTable.reload({where: {dictTypeCode: obj.data.dictTypeCode}, page: {curr: 1}, url: Feng.ctxPath + '/dict/page'});
|
||||
});
|
||||
|
||||
/* 删除 */
|
||||
function doDel(obj) {
|
||||
layer.confirm('确定要删除此字典吗?', {
|
||||
skin: 'layui-layer-admin',
|
||||
shade: .1
|
||||
}, function (i) {
|
||||
layer.close(i);
|
||||
var loadIndex = layer.load(2);
|
||||
$.get('../../json/ok.json', {
|
||||
id: obj.data.dictId,
|
||||
}, function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (200 === res.code) {
|
||||
layer.msg(res.msg, {icon: 1});
|
||||
obj.del();
|
||||
$('#dictTypeTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2});
|
||||
}
|
||||
}, 'json');
|
||||
});
|
||||
}
|
||||
|
||||
/* 字典-点击新增对话框 */
|
||||
Dict.openAddDlg = function (data) {
|
||||
func.open({
|
||||
height: 680,
|
||||
title: '添加字典',
|
||||
content: Feng.ctxPath + '/view/dict/addView?dictTypeId=' + data.dictTypeId,
|
||||
tableId: Dict.tableId
|
||||
});
|
||||
};
|
||||
|
||||
/* 字典-点击编辑对话框 */
|
||||
Dict.openEditDlg = function (data) {
|
||||
func.open({
|
||||
height: 680,
|
||||
title: '修改字典',
|
||||
content: Feng.ctxPath + '/view/dict/editView?dictId=' + data.dictId,
|
||||
tableId: Dict.tableId
|
||||
});
|
||||
};
|
||||
|
||||
/* 字典-点击删除 */
|
||||
Dict.onDeleteItem = function (data) {
|
||||
var operation = function () {
|
||||
var httpRequest = new HttpRequest(Feng.ctxPath + "/dict/deleteDict", 'post', function (data) {
|
||||
Feng.success("删除成功!");
|
||||
table.reload(Dict.tableId);
|
||||
}, function (data) {
|
||||
Feng.error("删除失败!" + data.message + "!");
|
||||
});
|
||||
httpRequest.set(data);
|
||||
httpRequest.start(true);
|
||||
};
|
||||
Feng.confirm("是否删除?", operation);
|
||||
};
|
||||
|
||||
/* 字典-点击搜索 */
|
||||
form.on('submit(dictTbSearch)', function (data) {
|
||||
//赋值左表dictTypeCode
|
||||
data.field.dictTypeCode = selObj.data.dictTypeCode;
|
||||
dictTable.reload({where: data.field});
|
||||
return false;
|
||||
});
|
||||
|
||||
/* 字典-点击操作工具栏 */
|
||||
table.on('tool(dictTable)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') { // 修改
|
||||
Dict.openEditDlg(data);
|
||||
} else if (obj.event === 'del') { // 删除
|
||||
Dict.onDeleteItem(data);
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮点击事件
|
||||
$('#btnAdd').click(function () {
|
||||
Dict.openAddDlg(selObj.data);
|
||||
return false;
|
||||
});
|
||||
|
||||
/* 字典-点击表格头工具栏 */
|
||||
// table.on('toolbar(dictTable)', function (obj) {
|
||||
// if (obj.event === 'add') { // 添加
|
||||
// Dict.openAddDlg(selObj.data);
|
||||
// } else if (obj.event === 'del') { // 删除
|
||||
// var checkRows = table.checkStatus('dictTable');
|
||||
// if (checkRows.data.length === 0) {
|
||||
// layer.msg('请选择要删除的数据', {icon: 2});
|
||||
// return;
|
||||
// }
|
||||
// var ids = checkRows.data.map(function (d) {
|
||||
// return d.dictDataId;
|
||||
// });
|
||||
// doDel2({ids: ids});
|
||||
// }
|
||||
// });
|
||||
|
||||
/* 字典-渲染表格 */
|
||||
var dictTable = table.render({
|
||||
elem: '#dictTable',
|
||||
data: [],
|
||||
height: 'full-100',
|
||||
page: true,
|
||||
//toolbar: '#dictHtbBar',
|
||||
cellMinWidth: 100,
|
||||
cols: [[
|
||||
{type: 'checkbox'},
|
||||
{type: 'numbers'},
|
||||
{field: 'dictName', align: "center", sort: true, title: '字典名称'},
|
||||
{field: 'dictCode', align: "center", sort: true, title: '字典编码'},
|
||||
{field: 'dictSort', align: "center", sort: true, title: '排序号'},
|
||||
{align: 'center', toolbar: '#dictTbBar', title: '操作'}
|
||||
]],
|
||||
parseData: Feng.parseData
|
||||
});
|
||||
});
|
|
@ -0,0 +1,108 @@
|
|||
@layout("/layout/_container.html",{js:["/assets/modular/system/dict/dictionary.js"]}){
|
||||
<style>
|
||||
#dictTypeTable + .layui-table-view .layui-table-tool-temp {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
#dictTypeTable + .layui-table-view .layui-table-body tbody > tr td {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#dictTypeTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click {
|
||||
background-color: #fff3e0;
|
||||
}
|
||||
|
||||
#dictTypeTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click td:last-child > div:before {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
content: "\e602";
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
font-family: layui-icon !important;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
</style>
|
||||
<div class="layui-fluid" style="padding-bottom: 0;">
|
||||
<div class="layui-row layui-col-space15">
|
||||
<div class="layui-col-md3">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body" style="padding: 10px;">
|
||||
<!-- 表格工具栏1 -->
|
||||
<form class="layui-form toolbar">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline" style="max-width: 140px;">
|
||||
<input name="dictTypeName" class="layui-input" type="text" placeholder="类型" autocomplete="off"/>
|
||||
</div>
|
||||
<div class="layui-inline" style="max-width: 140px;">
|
||||
<input name="dictTypeCode" class="layui-input" type="text" placeholder="编码" autocomplete="off"/>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button class="layui-btn icon-btn" lay-filter="dictTypeTbSearch" lay-submit>
|
||||
<i class="layui-icon"></i>搜索
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- 数据表格1 -->
|
||||
<table id="dictTypeTable" lay-filter="dictTypeTable"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-md9">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body" style="padding: 10px;">
|
||||
<!-- 表格工具栏2 -->
|
||||
<form class="layui-form toolbar">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">字典名称:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="dictName" class="layui-input" placeholder="输入字典名称"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">字典编码:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="dictCode" class="layui-input" placeholder="输入字典键值"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline"> 
|
||||
<button class="layui-btn icon-btn" lay-filter="dictTbSearch" lay-submit><i class="layui-icon"></i>搜索</button>
|
||||
<button id="btnAdd" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- 数据表格2 -->
|
||||
<table id="dictTable" lay-filter="dictTable"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格头部操作列 -->
|
||||
<script type="text/html" id="dictTypeHtbBar">
|
||||
<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
<button lay-event="edit" class="layui-btn layui-btn-sm layui-btn-warm icon-btn"><i class="layui-icon"></i>修改</button>
|
||||
<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon"></i>删除</button>
|
||||
</script>
|
||||
<!-- 表格头部操作列结束 -->
|
||||
|
||||
<!-- 表格头部操作列 -->
|
||||
<script type="text/html" id="dictHtbBar">
|
||||
<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon"></i>删除</button>
|
||||
</script>
|
||||
<!-- 表格头部操作列结束 -->
|
||||
|
||||
<!-- 表格操作列 -->
|
||||
<script type="text/html" id="dictTbBar">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
<!-- 表格操作列结束 -->
|
||||
|
||||
|
||||
|
||||
@}
|
Loading…
Reference in New Issue