/** * 服务对象页面 * @author weidy * @date 2020-12-10 */ layui.define(['layer','element','form','table','dynamicCondition','upload' ],function(exports){ var webUtil = $webUtil; var Class = function(){ this.MODELNAME = "platform/monitor/VciService"; this.moduleKey = "VciService"; this.backPath = configData.adminServicePath; this.id = "VciService"; this.url = { controller:'vciServiceController/', dataGrid:'gridVciService', addSave:'addSave', editSave:'editSave', deleteUrl:'deleteData', getObjectByOid:'getObjectByOid' }; this.getContent=function(){ var that = this; var html = ""; html = [ '
', '
', '
', that.getToolbarHtml(), '
', '', '
', '
', '
' ].join(""); return html; }; this.getToolbarHtml =function(){ var that = this; var html = [ '
', '', '', '', '', '', '
' ].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 == 'stop'){ that.stop(data.id); }else if(layEvent == "start"){ that.start(data.id); }else if(layEvent == "restart"){ that.restart(data.id); }else if(layEvent == "update"){ that.update(data.id); } }); }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', width: 150 }, { title: '名称', field: 'name', width: 150, templet:function (d){ if(d.uiFlag == 'true'){ return d.name + "(UI)"; }else{ return d.name; } } }, { title: '当前状态', field: 'currentStatus', width: 80, templet:function(d){ if(d.currentStatus == "未知") { return '
'+d.currentStatus+'
' ; } else if(d.currentStatus == "运行中") { return '

'+d.currentStatus+'

' ; }else{ return '

'+d.currentStatus+'

' ; } } }, { title: '执行步骤', field: 'processStatus', width: 80 }, { title: '部署文件夹', field: 'folder', width: 150 }, { title: '初始化的bat', field: 'initBat', width: 150 }, { title: '启动的bat', field: 'startBat', width: 150 }, { title: '请求的地址', field: 'requestPath', width: 150 },{ field: 'options', title:'操作', width: 260, fixed:'right', templet: function (d) { var btns = []; if(d.uiFlag == 'true'){ btns.push('更新'); }else { btns.push('停服'); btns.push('启动'); btns.push('重启'); btns.push('更新jar'); } return btns.join(""); } }]; } }; 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: 'folder', title: '所在文件夹', required: true, type: 'text', readOnly:onlyShow } , { field: 'initBat', title: '初始化的bat', required: true, type: 'text', readOnly:onlyShow }, { field: 'startBat', title: '启动的bat', required: true, type: 'text', readOnly:onlyShow } , { field: 'requestPath', title: '请求的地址', required: true, type: 'text', readOnly:onlyShow } , { field: 'privateKey', title: '私钥(用于停服)', type: 'text', required: true, readOnly:onlyShow }, { field: 'pidPath', title: '进程文件的路径', required: true, type: 'text', defaultValue:'app.pid', readOnly:onlyShow }, { field: 'logsFolder', title: '日志的文件夹', type: 'text', defaultValue: 'logs', readOnly:onlyShow }, { field: 'logsAllName', title: '全部信息的日志名称', type: 'text', readOnly:onlyShow } , { field: 'description', title: '描述', type: 'text', readOnly:onlyShow } // , { // field: 'sameDb', // title: '是否相同的数据库', // type: 'truefalse', // readOnly:onlyShow // } , { field: 'uiFlag', title: '是否UI项目', type: 'truefalse', 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:'
', fullScreen:true, 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; layui.table.reload("table_" + that.id); }; this.ADVQUERY = function () { var that = this; if(!that.serinorQueryInstance) { var dynamicCondition = layui.dynamicCondition; $('[layui-filter="toolbar_' + that.id + '"]').append('
'); var dataFields = that.columns; that.serinorQueryInstance = dynamicCondition.create({ fields: dataFields//查询字段 , tableId: "table_" + that.id//需要查询的表格 , type: "complex" //type:"simple"/"complex" 查询的方法 暂时写死为 complex //,conditionTextId:"#toolbar"+that.id//高级查询 按钮所在的div //,popupShowQueryBtn: true//显示高级查询按钮 , queryCallBack: function (requestData) {//查询之后的callback //console.log(JSON.stringify(requestData)) } }); } that.serinorQueryInstance.open(); }; this.stop = function (id){ var that = this; if(!id){ return false; } $webUtil.showConfirmMsg("是否要停止服务",function (r){ if(r) { $webUtil.post(that.url.controller + "stopService", {id: id}, function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"发送停服的命令成功,请自行刷新状态"); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error){},that.backPath); } }); }; this.start = function (id){ var that = this; if(!id){ return false; } $webUtil.showConfirmMsg("是否要启动服务",function (r){ if(r) { $webUtil.showConfirmMsg("是否要初始化数据库表?",function (r){ $webUtil.post(that.url.controller + "startService", {id: id,checkFlag:true}, function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"发送启动的命令成功,请自行刷新状态"); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error){},that.backPath); },function (){ $webUtil.post(that.url.controller + "startService", {id: id,checkFlag:false}, function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"发送启动的命令成功,请自行刷新状态"); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error){},that.backPath); }); } }); }; this.restart = function (id){ var that = this; if(!id){ return false; } $webUtil.showConfirmMsg("是否要重启服务",function (r){ if(r) { $webUtil.post(that.url.controller + "restartService", {id: id}, function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"发送重启的命令成功,请自行刷新状态"); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error){},that.backPath); } }); }; this.update = function (id){ var that = this; if(!id){ return false; } var form = layui.form; var filter ="form_" + id; $webUtil.showConfirmMsg("是否要更新服务的文件,这个过程可能会很长",function (r){ if(r){ var addSaveIndex = webUtil.dialog({ title: '上传更新包,并且更新服务,如果遇到错误,请关闭后重试', content: '
', resizing: function (layero) { form.doResize(filter); }, area: ['500px', '300px'], success: function (layero) { form.addItems(filter, [{ field: 'checkFlag', title: '是否初始化数据库表', labelWidth:200, type: 'truefalse', defaultValue: 'false' }], function () { if ($("#upload_table_template_" + filter)) { $("#upload_table_template_" + filter).remove(); } $("#form_" + filter).append(''); var upload = layui.upload; //执行实例 var uploadInst = upload.render({ elem: '#upload_table_template_' + filter //绑定元素 ,accept:'file' ,acceptMime:'file/*' ,exts:'jar|zip|rar' ,url: (that.backPath+ that.url.controller + 'updateJar')//上传接口 ,auto:true ,before:function(obj){ if(form.validata(filter)){ var formData = form.getValues(filter); formData['id'] = id; obj.setData(formData); $webUtil.showProgress('文件上传中'); return true; }else{ $webUtil.showErrorMsg("请先输入内容后再选择文件"); return false; } } ,done: function(result){ $webUtil.closeProgress(); if(result.success){ $webUtil.showMsgFromResult(result,"更新指令发送成功!"); layui.layer.close(addSaveIndex); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } } ,error: function(){ //请求异常回调 $webUtil.showErrorMsg("上传异常"); } }); }, {}, {defaultColumnOneRow: 1}); } }); } }); }; }; var cs = new Class(); exports(cs.MODELNAME,cs); });