#
luxiaotao1123
2022-03-01 5e4bef66a37f1bbdf48d845dda518fd8cc54ef37
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
var currentSensorId = null;
var currentSensorUuid = null;
var init = false;
 
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"  // 配置模块所在的目录
}).use(['table','laydate', 'form', 'tree', 'xmSelect'], function() {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var tree = layui.tree;
    var xmSelect = layui.xmSelect;
    var selObj, treeData;  // 左树选中数据
 
    var organizationTree;
    window.loadTree = function(condition){
        var loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl+"/sensor/tree/auth?sensorType="+sensorType,
            headers: {'token': localStorage.getItem('token')},
            data: {
                'condition': condition
            },
            method: 'POST',
            success: function (res) {
                if (res.code === 200){
                    layer.close(loadIndex);
                    // 树形图
                    organizationTree = tree.render({
                        elem: '#organizationTree',
                        id: 'organizationTree',
                        onlyIconControl: true,
                        data: res.data,
                        click: function (obj) {
                            currentSensorId = obj.data.id;
                            currentSensorUuid = obj.data.title;
                            selObj = obj;
                            $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                            $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                            if (obj.data.field === 'sensor') {
                                if (window.location.href.indexOf('standard') !== -1) {
                                    renderList(currentSensorId);
                                } else {
                                    insTb2.reload({
                                        where: {sensor_id: obj.data.id},
                                        page: {curr: 1}
                                    });
                                }
                            } else if (obj.data.field === 'host') {
                                currentSensorId = null;
                                currentSensorUuid = null;
                                if (window.location.href.indexOf('standard') !== -1) {
                                    renderList(currentSensorId, obj.data.id);
                                } else {
                                    insTb2.reload({
                                        where: {sensor_id: "", host_id: obj.data.id},
                                        page: {curr: 1}
                                    });
                                }
                            }
                        }
                    });
                    treeData = res.data;
                    if (isEmpty(condition) && init) {
                        currentSensorId = null;
                        currentSensorUuid = null;
                        if (window.location.href.indexOf('standard') !== -1) {
                            renderList(currentSensorId);
                        } else {
                            insTb2.reload({
                                where: {sensor_id: "", host_id: null},
                                page: {curr: 1}
                            });
                        }
                    }
                    if (!init) {
                        init = true;
                    }
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }
    loadTree();
 
    /* 树形图重置 */
    $('#treeReset').click(function () {
        $("#condition").val("");
        loadTree("");
    })
 
})
 
function closeDialog() {
    layer.closeAll();
}
 
/* 树形图搜索 */
function findData(el) {
    var condition = $(el).val();
    loadTree(condition)
}