/**
|
* 服务对象页面
|
* @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/VciSqlTool";
|
this.moduleKey = "VciSqlTool";
|
this.backPath = configData.compatibility?path:configData.adminServicePath;
|
this.id = "VciSqlTool";
|
this.url = {
|
controller:'vciDataBaseConnectController/',
|
executeSql:'executeSql',
|
executeQuerySql:'executeQuerySql'
|
};
|
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;overflow-x: hidden">',
|
that.getToolbarHtml(),
|
'<textarea id="sql_',that.id,'" style="width:100%;height:260px;"></textarea>',
|
'</div>',
|
'<div class="layui-south" style="height:400px;width:100%;overflow-y:auto;">' ,
|
'<table id="table_', that.id , '" lay-filter="table_',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">',
|
'<div layui-filter="toolbar_',that.id,'_select" class="layui-input-inline" style="position: relative;"></div>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_SQLQUERY"><i class="layui-icon layui-icon-search"></i>查询</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_SQLEXECUTE"><i class="layui-icon layui-icon-down"></i>执行</button>',
|
'<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_RESETSQL"><i class="layui-icon layui-icon-fonts-clear"></i>重置</button>',
|
'</div>'
|
].join("");
|
return html;
|
};
|
this.createSearchHtml = function () {
|
var that = this;
|
$webUtil.createSelectHtml(that.backPath+'vciDataBaseConnectController/comboxDatabase',$("[layui-filter='toolbar_" + that.id + "_select']"),'sql_select');
|
webUtil.bindDefultButtonLisenter(that, that.id);
|
};
|
this.init = function(){
|
var that = this;
|
webUtil.copyConfig(that,that.moduleKey);
|
layui.table.render({
|
elem: '#table_' + that.id,
|
id: 'table_' + that.id,
|
data:[],
|
emptyText:'',
|
limit:-1,
|
cols: [[]]
|
});
|
that.createSearchHtml();
|
};
|
this.SQLQUERY = function (){
|
var that = this;
|
var sql = $("#sql_" + that.id).val();
|
if($webUtil.isNull(sql)){
|
sql = $("#sql_" + that.id).text();
|
}
|
if($webUtil.isNotNull(sql)){
|
that.clearTable();
|
$webUtil.post(that.url.controller + that.url.executeQuerySql,{sql:sql,databaseId:$('#sql_select').val()},function (result){
|
if(result.success){
|
if(result.data.length > 0) {
|
var record = result.data[0];
|
var cols = [layui.table.getIndexColumn()];
|
for(var key in record){
|
cols.push({
|
field:key,
|
title:key
|
});
|
}
|
layui.table.reload('table_' + that.id,{
|
data: result.data,
|
cols: [cols]
|
});
|
}
|
}else{
|
$webUtil.showErrorMsg(result.msg);
|
}
|
},function (xhr,error){
|
$webUtil.showErrorMsg("执行SQL查询出错,可能是服务没有启动");
|
},that.backPath);
|
}
|
};
|
this.SQLEXECUTE = function () {
|
var that = this;
|
var sql = $("#sql_" + that.id).val();
|
if($webUtil.isNull(sql)){
|
sql = $("#sql_" + that.id).text();
|
}
|
if($webUtil.isNotNull(sql)) {
|
that.clearTable();
|
$webUtil.post(that.url.controller + that.url.executeSql, {sql: sql,databaseId:$('#sql_select').val()}, function (result) {
|
if (result.success) {
|
$webUtil.showMsgFromResult(result,"执行成功。受影响行数" + result.obj);
|
} else {
|
$webUtil.showErrorMsg(result.msg);
|
}
|
}, function (xhr, error) {
|
$webUtil.showErrorMsg("执行SQL查询出错,可能是服务没有启动");
|
}, that.backPath);
|
}
|
};
|
this.RESETSQL = function () {
|
var that = this;
|
$("#sql_" + that.id).text("");
|
$("#sql_" + that.id).val("");
|
};
|
this.clearTable = function (){
|
var that = this;
|
layui.table.reload("table_" + that.id, {cols:[[]]});
|
};
|
|
};
|
var cs = new Class();
|
exports(cs.MODELNAME,cs);
|
});
|