/**
|
* 帮助文档页面
|
* @author weidy
|
* @date 2021-11-25
|
*/
|
layui.define(['layer','element','form','table','dynamicCondition','upload' ],function(exports){
|
var webUtil = $webUtil;
|
var Class = function(){
|
this.MODELNAME = "platform/objectService/HelpDocument";
|
this.moduleKey = "HelpDocument";
|
this.backPath = configData.adminServicePath;
|
this.url = {
|
controller:'helpDocumentController/',
|
dataGrid:'gridHelpDocument',
|
addSave:'addSave',
|
editSave:'editSave',
|
deleteUrl:'deleteData',
|
getObjectByOid:'getObjectByOid',
|
importData:'importByFile',
|
downloadFile:'downloadFile'
|
};
|
this.getContent=function(){
|
var that = this;
|
var html = "";
|
html = [
|
'<div class="layui-layout" style="display:block;overflow-y: hidden">',
|
'<div class="layui-layout-border" style="display:block;margin-top:0px; " id="border_',that.id,'">',
|
'<div class="layui-center" style="overflow-y:auto;">',
|
that.getToolbarHtml(),
|
'<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',
|
'</div>',
|
'</div>',
|
'</div>'
|
].join("");
|
return html;
|
};
|
this.getToolbarHtml =function(){
|
var that = this;
|
var html = [
|
'<div layui-filter="toolbar_',that.id,'" class="layui-btn-container layui-buttons">',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_ADD"><i class="layui-icon layui-icon-add-1"></i>添加</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_EDIT"><i class="layui-icon layui-icon-edit"></i>修改基本信息</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_DEL"><i class="layui-icon layui-icon-delete"></i>删除</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_ADVQUERY"><i class="layui-icon layui-icon-search"></i>查询</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_refresh"><i class="layui-icon layui-icon-refresh"></i>刷新</button>',
|
'</div>'
|
].join("");
|
return html;
|
};
|
this.createSearchHtml = function () {
|
var that = this;
|
webUtil.bindDefultButtonLisenter(that, that.id);
|
webUtil.createSearchHtml({id:"文档编号",name:"文档名称"} ,$("[layui-filter='toolbar_" + that.id + "']"), "table_" + that.id);
|
};
|
this.init = function(){
|
var that = this;
|
webUtil.copyConfig(that,that.moduleKey);
|
that.initMainTable();
|
that.createSearchHtml();
|
};
|
this.initMainTable = function (parentFieldName) {
|
var that = this;
|
var table = layui.table;
|
that.checkColumns();
|
var tableWidth = $("#border_" + that.id).width()-225;
|
var options = {
|
elem: '#table_' + that.id,
|
id: 'table_' + that.id,
|
backPath:that.backPath,
|
url: that.url.controller + that.url.dataGrid,
|
page: {
|
limit: 20,
|
page: 1
|
},
|
width:tableWidth,
|
selectMode:table.selectMode.muti,
|
cols: [that.columns],
|
done:function(res,cur,total){
|
if(!that.fristMainLoad ){
|
table.on('tool(' + that.id + ')',function(obj){
|
var data = obj.data;//当前选择行的数据
|
var layEvent = obj.event;//点的是什么按钮
|
if(layEvent == 'EDITCONTENT') {
|
that.editContent(data.oid,data);
|
}else if(layEvent =='IMPORT'){
|
that.IMPORT(data.oid);
|
}else if(layEvent == 'DOWNLOAD'){
|
that.DOWNLOAD(data.oid);
|
}
|
});
|
}else{
|
if(total>0) {
|
table.selectRecord('table_' + that.id, {index:0});
|
}
|
}
|
that.fristMainLoad = true;
|
}
|
};
|
if(parentFieldName){
|
options.treeConfig = {
|
treepid:parentFieldName,
|
treeid:'id',
|
showField:'name'
|
};
|
}
|
table.render(options);
|
};
|
this.checkColumns = function(){
|
var that = this;
|
var table = layui.table;
|
if(that.columns==null || that.columns.length==0){
|
that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
|
title: '文档编号',
|
field: 'id',
|
sort:true,
|
width: 150
|
},
|
{
|
title: '文档名称',
|
field: 'name',
|
sort:true,
|
width: 200
|
},
|
{
|
title: '描述',
|
field: 'description',
|
sort:true,
|
width: 150
|
},
|
{
|
title: '文档用途',
|
field: 'docUsedTypeText',
|
sort:true,
|
width: 150
|
},
|
{
|
title: '后缀名',
|
field: 'fileExtension',
|
width:150
|
},
|
{
|
field:'options',
|
title:'操作',
|
width:200,
|
templet:function(d){
|
return '<a class="layui-btn layui-btn-intable" lay-event="EDITCONTENT">编辑内容</a>'+
|
'<a class="layui-btn layui-btn-intable" lay-event="IMPORT">导入文件</a>'+
|
'<a class="layui-btn layui-btn-intable" lay-event="DOWNLOAD">下载</a>';
|
}
|
}];
|
}
|
};
|
|
this.getFormItems = function(onlyShow) {
|
var that = this;
|
var table = layui.table;
|
return [ {
|
field: 'id',
|
title: '文档编号',
|
required: true,
|
type: 'text',
|
readOnly:onlyShow
|
}, {
|
field: 'name',
|
title: '文档名称',
|
required: true,
|
type: 'text',
|
readOnly:onlyShow
|
} ,
|
{
|
field: 'description',
|
title: '描述',
|
type: 'text',
|
readOnly:onlyShow
|
} , {
|
field: 'docUsedType',
|
title: '文档用途',
|
type: 'combox',
|
comboxKey:'helpdocusedtype',
|
showField:'docUsedTypeText',
|
data:[{key:"dev",value:"二次开发手册"},{key:"deploy",value: "实施部署文档"},{key:"manual",value:"用户手册"},
|
{key:"ui",value:"前端资料"},{key:"spring",value: "后台开发资料"},{key:"ide",value: "编译器资料"},
|
{key:"project",value: "项目管理工具资料"},{key:"design",value: "设计方案"},{key:"requirement",value: "需求方案"},
|
{key:"acceptance",value: "验收文档"},{key:"button",value: "按钮配置说明"},{key:"update",value: "更新说明"}],
|
readOnly:onlyShow
|
} ];
|
};
|
this.ADD = function () {
|
var that = this;
|
that.addOrEdit(true);
|
};
|
this.EDIT = function(){
|
var that = this;
|
var oid = webUtil.getOidFromGrid("table_" + that.id,true,true);
|
if(!oid){
|
return false;
|
}
|
that.addOrEdit(false,oid);
|
};
|
this.addOrEdit = function(add,oid) {
|
var that = this;
|
var form = layui.form;
|
var filter ="form_" + that.id;
|
var addSaveIndex =webUtil.dialog({
|
title:add?'添加帮助文档':'修改帮助文档',
|
btn:['保存','取消'],
|
skin:'layui-layer-lan',
|
content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
|
resizing:function(layero){
|
form.doResize(filter);
|
},
|
success:function(layero) {
|
form.addItems(filter,that.getFormItems(false),
|
function () {
|
if(!add){
|
form.load(filter,{
|
backPath:that.backPath,
|
url:that.url.controller + that.url.getObjectByOid,
|
method:'get',
|
params:{
|
oid:oid
|
}
|
});
|
}else{
|
var defaultValues = {};
|
//可以手动在此处添加默认值
|
form.setValues(defaultValues,filter);
|
}
|
}, {}, {defaultColumnOneRow: 2});
|
},
|
yes:function(layero){
|
if(form.validata(filter)){
|
var values = form.getValues(filter,true);
|
var url = that.url.controller + (add?that.url.addSave:that.url.editSave);
|
webUtil.ajax(add?'post':'put',url,values,function(result){
|
if(result.success){
|
webUtil.showMsgFromResult(result,(add ? "添加成功" : "修改成功"));
|
layer.close(addSaveIndex);
|
that.refresh();
|
}else{
|
webUtil.showErrorMsg(result.msg);
|
}
|
},function(xhr,err){
|
webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
|
},that.backPath);
|
}
|
},
|
btn2:function(layero){
|
layer.close(addSaveIndex);
|
}
|
});
|
};
|
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.controller + that.url.deleteUrl,{oid:oid,ts:ts},function(result){
|
if(result.success){
|
webUtil.showMsgFromResult(result,"删除成功");
|
that.refresh();
|
}else{
|
webUtil.showErrorMsg(result.msg);
|
}
|
},function(xhr,err){
|
webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
|
},that.backPath);
|
});
|
};
|
this.refresh = function () {
|
var that = this;
|
var that = this;
|
layui.table.reload("table_" + that.id);
|
};
|
this.IMPORT = function (oid){
|
var that = this;
|
var filter =that.id + "_upload";
|
var form = layui.form;
|
var uploadIndex = webUtil.dialog({
|
title:'导入附件',
|
content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" enctype="multipart/form-data"></form>',
|
area: ['300px', '300px'],
|
resize:false,
|
success:function(layero){
|
//如果导入有其他操作,在第二个参数中添加
|
form.addItems(filter,[],function(){
|
$("#form_" + filter).append('<button type="button" class="layui-btn" id="' + that.id + '_upload_form_file" style="margin-left:100px;margin-top:80px;"><i class="layui-icon"></i>选择文件后自动导入</button> ');
|
var upload = layui.upload;
|
//执行实例
|
var uploadInst = upload.render({
|
elem: '#' + that.id + '_upload_form_file' //绑定元素
|
,accept:'file'
|
,acceptMime:'file/*'
|
,data:{oid:oid}
|
,url: that.backPath + that.url.controller + that.url.importData
|
,done: function(result){
|
if(result.success){
|
layer.close(uploadIndex);
|
webUtil.showMsgFromResult(result,"导入成功");
|
that.refresh();
|
}else{
|
webUtil.showErrorMsg(result.msg);
|
}
|
}
|
,error: function(){
|
//请求异常回调
|
webUtil.showErrorMsg("上传异常");
|
}
|
});
|
},{},{
|
defaultColumnOneRow:1
|
});
|
}
|
});
|
};
|
this.DOWNLOAD = function (oid){
|
var that = this;
|
$webUtil.fileDownload(that.backPath + that.url.controller + that.url.downloadFile + "?oid=" + oid);
|
};
|
this.editContent = function (oid,data){
|
if($webUtil.isNull(data.fileExtension)|| data.fileExtension=='md'){
|
var menuObject = {
|
id: 'editmarkdown'+oid,
|
url: "USEJS:platform/objectService/markdown",
|
text: '['+data.id+']['+data.name+']编辑',
|
multiCompent:true,
|
initSourceData:data
|
};
|
portal.showTabByMenu(menuObject.id,menuObject);
|
}else{
|
$webUtil.showErrorMsg('不是markdown的文件,不能编辑');
|
return false;
|
}
|
|
};
|
this.ADVQUERY = function () {
|
var that = this;
|
if(!that.serinorQueryInstance) {
|
var dynamicCondition = layui.dynamicCondition;
|
$('[layui-filter="toolbar_' + that.id + '"]').append('<div id="toolbar' + that.id + '" class="layui-inline"></div>');
|
that.checkColumns();
|
var dataFields = [];
|
for(var i = 0 ; i < that.columns.length ; i ++){
|
dataFields[i] = that.columns[i];
|
}
|
that.serinorQueryInstance = dynamicCondition.create({
|
fields: dataFields//查询字段
|
, tableId: "table_" + that.id//需要查询的表格
|
, type: "complex" //type:"simple"/"complex" 查询的方法 暂时写死为 complex
|
, queryCallBack: function (requestData) {//查询之后的callback
|
|
}
|
});
|
}
|
that.serinorQueryInstance.open();
|
};
|
|
};
|
var cs = new Class();
|
exports(cs.MODELNAME,cs);
|
});
|