diff --git a/static/js/table.js b/static/js/table.js new file mode 100644 index 0000000..776d4e3 --- /dev/null +++ b/static/js/table.js @@ -0,0 +1,49 @@ +function Table(columns, data, actions, elementId) { + this.columns = columns + this.data = data + this.actions = actions + this.element = $(elementId) +} + +Table.prototype.Generic = function () { + let self = this + // 创建表格元素 + let $table = $(''); + // 创建表头 + let $thead = $(''); + let $theadRow = $(''); + self.columns.forEach(function(col) { + $theadRow.append(''); + }); + // 如果有操作按钮,添加操作列 + if (self.actions.length > 0) { + $theadRow.append(''); + } + $thead.append($theadRow); + $table.append($thead); + + // 创建表体 + let $tbody = $(''); + self.data.forEach(function(row) { + let $tr = $(''); + row.forEach(function(cell) { + $tr.append(''); + }); + // 如果有操作按钮,添加操作单元格 + if (self.actions.length > 0) { + let $actionTd = $('
' + col + '操作
' + cell + ''); + self.actions.forEach(function(action) { + let $button = $(''); + $button.on('click', function() { + action.onClick(row); + }); + $actionTd.append($button); + }); + $tr.append($actionTd); + } + $tbody.append($tr); + }); + $table.append($tbody); + // 将表格添加到目标元素中 + self.element.html($table); +} \ No newline at end of file diff --git a/view/user.html b/view/user.html index 9ad6ad7..079c0ff 100644 --- a/view/user.html +++ b/view/user.html @@ -2,9 +2,41 @@ {{end}} {{define "content"}} -

User

-

User page content goes here.

+
{{end}} {{define "script"}} + + {{end}} \ No newline at end of file