/**
|
* 数据库相关的操作
|
* @author weidy@2020-2-19
|
*/
|
layui.define(['layer','element','form','table','util'],function(exports){
|
var Class = function(){
|
this.MODELNAME = "platform/objectService/OsDLL";
|
this.moduleKey = "OsDLL";
|
this.id='OsDLL';
|
this.sourceData={};
|
this.columns = [];
|
this.backPath = configData.compatibility?path:configData.frameworkPath;
|
this.url={
|
dataGrid:'smButtonController/dataGrid',//列表数据和查询
|
add:'smButtonController/addSave',
|
edit:'smButtonController/editSave',
|
deleteUrl:'smButtonController/delete'
|
};
|
this.buttonIconMap = {
|
SEARCH:'layui-icon-refresh-2',
|
SENIORSEARCH:'layui-icon-query',
|
ADD:'layui-icon-add-1',
|
EDIT:'layui-icon-edit',
|
DELETE:'layui-icon-delete'
|
};
|
this.getContent=function(){//返回这个组件的基础html
|
var that = this;
|
var html = "";
|
html = [
|
'<div class="layui-layout-border">',
|
'<div class="layui-center">',
|
that.getToolbarHtml(),
|
'<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',//主列表
|
'</div>',
|
'</div>'
|
].join("");
|
return html;
|
};
|
this.getToolbarHtml =function(){
|
var that = this;
|
var html = [
|
'<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
|
'</div>'
|
].join("");
|
return html;
|
};
|
this.getDetailToolbarHtml = function(){
|
var me = this;
|
return '<div layui-filter="detail_toolbar_' + me.id + '" class="layui-btn-container"></div>';
|
};
|
this.init=function(){//基础的html被添加后,再执行初始化
|
var that = this;
|
$webUtil.copyConfig(that,that.moduleKey);
|
$webUtil.createButtonHtmlEx(that.sourceData,that.buttonIconMap,$('[layui-filter="toolbar_' + that.id + '"]'),that.id,
|
[{uniqueFlag:'ADD',alias:'添加'},{uniqueFlag:'EDIT',alias:'修改'},{uniqueFlag:'DEL',alias:'删除'},{uniqueFlag:'LISTUSED',alias:'查看应用范围'},{uniqueFlag:'CASCADEDEL',alias:'关联删除'},{uniqueFlag:'refresh',alias:'刷新'}],
|
[],function(buttons,hasViewRight,hasQueryRight) {
|
hasViewRight = true;
|
hasQueryRight = true;
|
if (hasViewRight) {
|
$webUtil.bindDefultButtonLisenter(that, that.id);
|
var table = layui.table;
|
that.checkColumns();//主列表中列。
|
table.render({
|
elem: '#table_' + that.id,
|
id: 'table_' + that.id,
|
url: that.backPath + that.url.dataGrid,
|
page: {
|
limit: 30,
|
page: 1
|
},
|
cols: [that.columns],
|
done: function (res, cur, count) {
|
if(res && res.data && res.data.length>0){
|
table.selectRecord('table_' + that.id,res.data[0]);
|
}
|
},
|
rowClick: function (thisTableFilter, record) {
|
if(that.hasDetailRight) {
|
table.reload("person_" + that.id, {
|
where: {
|
oid: record.oid
|
}
|
});
|
}
|
}
|
});
|
if(hasQueryRight) {
|
$webUtil.createSearchHtml({
|
id: '按钮标识',
|
name: '按钮名称'
|
}, $('[layui-filter="toolbar_' + that.id + '"]'), 'table_' + that.id);
|
}
|
}else{
|
$webUtil.showErrorMsg("您没有权限浏览本页面");
|
}
|
});
|
};
|
this.ADD = function(){//保存
|
var that = this;
|
layui.use('form',function(){
|
var form = layui.form;
|
var filter ="form_" + that.id;
|
var addSaveIndex = layer.open({
|
type:1,
|
title:'添加按钮',
|
btn:['保存','取消'],
|
skin:'layui-layer-lan',
|
content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
|
area:['800px','270px'],
|
closeBtn:2,
|
shade:true,
|
shadeClose:true,
|
resize:true,
|
resizing:function(layero){
|
form.doResize(filter);
|
},
|
success:function(layero) {
|
form.addItems(filter,that.getFormItems(false),
|
function () {}, {}, {defaultColumnOneRow: 2});
|
},
|
yes:function(layero){
|
if(form.validata(filter)){
|
var values = form.getValues(filter);
|
$webUtil.post(that.url.add,values,function(result){
|
if(result.success){
|
$webUtil.showMsg("添加按钮成功");
|
layer.close(addSaveIndex);
|
that.refresh();
|
}else{
|
$webUtil.showErrorMsg(result.msg);
|
}
|
},function (xhr,error) {
|
|
},that.backPath);
|
}
|
},
|
btn2:function(layero){
|
layer.close(addSaveIndex);
|
that.refresh();
|
}
|
});
|
});
|
};
|
this.getFormItems = function(isEdit){
|
return [{
|
type: 'text',
|
name: 'id',
|
text: '按钮标识',
|
required: true
|
}, {
|
type: 'text',
|
name: 'name',
|
text: '按钮名称',
|
required: true
|
}, {
|
name: 'iconCss',
|
text: '显示图标'
|
}, {
|
type: 'text',
|
name: 'description',
|
text: '描述'
|
}];
|
};
|
this.EDIT = function(){
|
var that = this;
|
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
|
if(!oid){
|
return false;
|
}
|
var selectRowData = layui.table.checkStatus("table_" + that.id);
|
layui.use('form',function(){
|
var form = layui.form;
|
var filter ="form_" + that.id;
|
var addSaveIndex = layer.open({
|
type: 1,
|
title: '修改按钮',
|
btn: ['保存', '取消'],
|
url: that.backPath + that.url.edit,
|
skin: 'layui-layer-lan',
|
content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
|
area: ['800px', '270px'],
|
closeBtn: 2,
|
shade: true,
|
shadeClose: true,
|
resize: true,
|
resizing: function (layero) {
|
form.doResize(filter);
|
},
|
success: function (layero) {
|
form.addItems(filter,that.getFormItems(true),
|
function () {
|
form.setValues(selectRowData.data[0],filter);
|
}
|
, {}
|
, {
|
defaultColumnOneRow: 2
|
});
|
},
|
yes:function(layero){
|
if(form.validata(filter)){
|
var formValues = form.getValues(filter,true);
|
formValues['oid'] = selectRowData.data[0].oid;
|
formValues['ts'] = selectRowData.data[0].ts;
|
$webUtil.put(that.url.edit,formValues,function (result) {
|
if(result.success){
|
$webUtil.showMsg("修改按钮成功");
|
that.refresh();
|
layer.close(addSaveIndex);
|
}else{
|
$webUtil.showErrorMsg(result.msg);
|
}
|
},function (error) {
|
|
},that.backPath);
|
}
|
},
|
btn2:function(layero){
|
that.refresh();
|
layer.close()
|
}
|
});
|
});
|
};
|
|
this.DEL= function(){
|
var that = this;
|
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
|
if(!oid){
|
return false;
|
}
|
var ts = $webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
|
$webUtil.showConfirmMsg("是否删除这个按钮,对应的功能菜单中的按钮不会自动删除",function () {
|
$webUtil.deleteRequest(that.url.deleteUrl,{oid:oid,ts:ts},function(result){
|
if(result.success){
|
$webUtil.showMsg("删除按钮成功");
|
that.refresh();
|
}else{
|
$webUtil.showErrorMsg(result.msg);
|
}
|
},function (xhr,error) {
|
|
},that.backPath);
|
});
|
};
|
this.checkColumns = function(){
|
var that = this;
|
var table = layui.table;
|
if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
|
that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
|
field:'id',
|
title:'按钮标识',
|
width:150
|
},{
|
field:'name',
|
title:'按钮名称',
|
width:200
|
},{
|
field:'iconCss',
|
title:'显示图标',
|
width:100
|
},{
|
field:'description',
|
title:'描述',
|
width:150
|
}];
|
}
|
};
|
this.refresh = function(){
|
var that = this;
|
layui.table.reload("table_" + that.id);
|
|
};
|
};
|
var cs = new Class();
|
exports(cs.MODELNAME,cs);
|
});
|