PageSourceSearch

https://qhbio.ac.cn/static/javascripts/tree-define.js

js qhbio.ac.cn collected 2026-10-07 22:52:51 UTC 5,261 bytes, 108 lines download raw bytes

1/**
2   * [tree 树形组件]
3   * @param  {[type]}  layid   [过滤器ID]
4   * @param  {[type]}  data    [数据]
5   * @param  {[type]}  showCheckbox [复选框]
6   * @param  {[type]}  showLine [连接线]
7   * @param  {[type]}  accordion [手风琴模式]
8   * @param  {[type]}  onlyIconControl [图标控制展开]
9   * @param  {[type]}  isJump [新窗口跳转]
10   */
11layui.use('tree', function () {
12    var $ = layui.$;
13    datatree = function (layid, data, showCheckbox, showLine, accordion, onlyIconControl, isJump) {
14        if (layid) {
15            var _data = data || [];
16            var _showCheckbox = showCheckbox || false; //是否显示复选框
17            var _showLine = showLine || true; //是否开启连接线。默认 true,若设为 false,则节点左侧出现三角图标。
18            var _accordion = accordion || false; //是否开启手风琴模式,默认 false
19            var _onlyIconControl = onlyIconControl || false; //是否仅允许节点左侧图标控制展开收缩。默认 false
20            var _isJump = isJump || false; //是否允许点击节点时弹出新窗口跳转。默认 false
21            var result = {
22                onclick: function () { },
23                oncheck: function () { },
24                onspread: function () { },
25                getChecked: function () { },
26                setChecked: function () { },
27                reload: function () { },
28                getData: function () { // zhangying 新增 getData 方法
29                    return _data;
30                },
31                expandNode: function (nodeId) { //zhangying 新增 expandNode 方法
32                    const tree = layui.tree;
33                    const elem = $('#' + layid).find(`[data-id="${nodeId}"]`);
34                    if (elem.length > 0) {
35                        elem.addClass('layui-tree-spread');
36                        elem.children('.layui-tree-pack').show();
37                        // 调用 spread 事件
38                        result.onspread.call({ state: 'open', data: elem.data() });
39                    }
40                }
41            }
42        
43                var tree = layui.tree;
44                var inst1 = tree.render({
45                    elem: '#' + layid,
46                    id: layid, //定义索引
47                    showCheckbox: _showCheckbox,
48                    showLine: _showLine,
49                    accordion: _accordion,
50                    onlyIconControl: _onlyIconControl,
51                    isJump: _isJump,
52                    data: _data,
53                    text: {
54                        defaultNodeName: '无数据',
55                        none: '加载数据失败!'
56                    },
57                    click: function (obj) {
58                        
59                        result.onclick.call(obj);
60                        if (!_showCheckbox) {
61                            $('#' + layid).find('.layui-tree-click').removeClass('layui-tree-click');
62                            obj.elem.find('span.layui-tree-txt:first').addClass('layui-tree-click');
63                        }
64                         //console.log(obj.data); //得到当前点击的节点数据
65                        // console.log(obj.state); //得到当前节点的展开状态:open、close、normal
66                         //console.log(obj.elem); //得到当前节点元素
67                        // console.log(obj.data.children); //当前节点下是否有子节点
68                    },
69                    oncheck: function (obj) {
70                        result.oncheck.call(obj);
71                        //console.log(obj.data); //得到当前点击的节点数据
72                        // console.log(obj.checked); //得到当前节点的展开状态:open、close、normal
73                        // console.log(obj.elem); //得到当前节点元素
74                    },
75                    spread: function (obj) {
76                        if (obj.state == 'open') {
77                            obj.lazytree = function (data) {
78                                tree.lazytree(inst1.config.id, obj.elem, data);
79                            }
80                            result.onspread.call(obj);
81                        }
82                    }
83                });
84                result.getChecked = function () {
85                    if (_showCheckbox) {
86                        var checkData = tree.getChecked(layid);
87                        return checkData;
88                    }
89                    else {
90                        var check = $('#' + layid).find('.layui-tree-click');
91                        if (check.length > 0) {
92                            return { id: check.parent().parent().parent().attr('data-id') }
93                        }
94                    }
95                }
96                result.setChecked = function (data) {
97                    if (_showCheckbox) {
98                        tree.setChecked(layid, data);
99                    }
100                }
101                result.reload = function () {
102                    tree.reload(layid, {});
103                }
104        
105            return result;
106        }
107    }
108});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.