forked from mengqingquan/treetable-lay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test5.html
117 lines (110 loc) · 3.97 KB
/
test5.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tree-table</title>
<link rel="stylesheet" href="assets/layui/css/layui.css">
<link rel="stylesheet" href="assets/common.css"/>
<style>
input {
height: 33px;
line-height: 33px;
padding: 0 7px;
border: 1px solid #ccc;
border-radius: 2px;
margin-bottom: -2px;
outline: none;
}
input:focus {
border-color: #009E94;
}
</style>
</head>
<body>
<div class="layui-container">
<br><br>
<a class="layui-btn layui-btn-normal" href="index.html"><<返回</a>
<div class="layui-btn-group">
<button class="layui-btn" id="btn-expand">全部展开</button>
<button class="layui-btn" id="btn-fold">全部折叠</button>
</div>
<input id="edt-search" type="text" placeholder="输入关键字" style="width: 120px;"/>
<button class="layui-btn" id="btn-search"> 搜索 </button>
<table id="auth-table" class="layui-table" lay-filter="auth-table"></table>
</div>
<script src="assets/layui/layui.js"></script>
<script>
layui.config({
base: 'module/'
}).extend({
treetable: 'treetable-lay/treetable'
}).use(['table', 'treetable'], function () {
var $ = layui.jquery;
var table = layui.table;
var treetable = layui.treetable;
// 渲染表格
layer.load(2);
treetable.render({
treeColIndex: 1,
treeSpid: -1,
treeIdName: 'authorityId',
treePidName: 'parentId',
elem: '#auth-table',
url: 'json/menus.json',
page: false,
cols: [[
{type: 'numbers'},
{field: 'authorityName', minWidth: 200, title: '权限名称'},
{field: 'authority', title: '权限标识'},
{field: 'menuUrl', title: '菜单url'},
{
field: 'isMenu', width: 80, align: 'center', templet: function (d) {
if (d.isMenu == 1) {
return '<span class="layui-badge layui-bg-gray">按钮</span>';
}
if (d.parentId == -1) {
return '<span class="layui-badge layui-bg-blue">目录</span>';
} else {
return '<span class="layui-badge-rim">菜单</span>';
}
}, title: '类型'
}
]],
done: function () {
layer.closeAll('loading');
}
});
$('#btn-expand').click(function () {
treetable.expandAll('#auth-table');
});
$('#btn-fold').click(function () {
treetable.foldAll('#auth-table');
});
$('#btn-search').click(function () {
var keyword = $('#edt-search').val();
var searchCount = 0;
$('#auth-table').next('.treeTable').find('.layui-table-body tbody tr td').each(function () {
$(this).css('background-color', 'transparent');
var text = $(this).text();
if (keyword != '' && text.indexOf(keyword) >= 0) {
$(this).css('background-color', 'rgba(250,230,160,0.5)');
if (searchCount == 0) {
treetable.expandAll('#auth-table');
$('html,body').stop(true);
$('html,body').animate({scrollTop: $(this).offset().top - 150}, 500);
}
searchCount++;
}
});
if (keyword == '') {
layer.msg("请输入搜索内容", {icon: 5});
} else if (searchCount == 0) {
layer.msg("没有匹配结果", {icon: 5});
}
});
});
</script>
</body>
</html>