Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
 * 服务对象页面
 * @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);
});