-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.js
70 lines (64 loc) · 1.97 KB
/
table.js
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
window.$ = (function (window, $) {
const initTable = function(columns, page, target) {
// 1. 拼接查询数据
let offset = page.offset || 0;
let limit = page.limit || 0;
// 2. 查询
// TODO
let data = {
total: 1,
rows: [
{
title: '这是title',
content: '这是content'
},
{
title: '这是title',
content: '这是content'
},
{
title: '这是title',
content: '这是content'
},
{
title: '这是title',
content: '这是content'
},
{
title: '这是title',
content: '这是content'
},
]
};
// 3. 组装结果数据
let thead = columns.map(col => `<th width=${col.width || ''}>${col.name}</th>`).join('')
let tbody = data.rows.map((item, idx) => {
return '<tr>' + columns.map(col => `<td>${
col.render ? col.render(item[col.code], idx, item) : (item[col.code] || '-')
}</td>`).join('') + '</tr>'
}).join('\n')
let tableTmplate = `<div class="std-table-header">
<div class="left"></div>
<div class="right"><button class="add btn-black btn-fade">+新增</button></div>
</div>
<table class='std-table'>
<thead>
<tr>
${thead}
</tr>
</thead>
<tbody>
${tbody}
</tbody>
</table>`
target.innerHTML = tableTmplate
}
const func = {
initTable: initTable
}
for (const _func in func) {
$[_func] = func[_func]
window[_func] = func[_func]
}
return $
})(window, window.$ || {})