added 完善js生成表格数据的实现

This commit is contained in:
zhaoxiang 2016-11-08 00:02:14 +08:00
parent 6d9bb7e319
commit 7493f0f0c3
4 changed files with 63 additions and 25 deletions

View File

@ -43,18 +43,18 @@ class Menu extends Base {
],
'topButton' => [
[
'href' => 'Menu/add',
'class'=> 'am-btn-success',
'href' => url('Menu/add'),
'class'=> 'btn-success',
'info'=> '新增',
'icon' => 'plus',
'ajax' => 0,
'confirm' => 0,
],
[
'href' => 'Menu/del',
'class'=> 'am-btn-danger del-all',
'href' => url('Menu/del'),
'class'=> 'btn-danger',
'info'=> '删除',
'icon' => 'trash',
'ajax' => 1,
'confirm' => 1,
]
],
'rightButton' => [
@ -92,15 +92,13 @@ class Menu extends Base {
'module' => 'label',
'rule' => [
[
'info' => '显示',
'class' => 'success',
'show' => ['hide', 1]
'info' => '隐藏',
'class' => 'warning'
],
[
'info' => '隐藏',
'class' => 'warning',
'show' => ['hide', 0]
]
'info' => '显示',
'class' => 'success'
],
]
],
'type' => [
@ -108,13 +106,11 @@ class Menu extends Base {
'rule' => [
[
'info' => '方法类功能',
'class' => 'secondary',
'show' => ['type', 0]
'class' => 'secondary'
],
[
'info' => '模块类功能',
'class' => 'primary',
'show' => ['type', 1]
'class' => 'primary'
]
]
]

View File

@ -16,6 +16,17 @@
font-size: 1.6rem;
font-family: "Segoe UI","Lucida Grande",Helvetica,Arial,"Microsoft YaHei",FreeSans,Arimo,"Droid Sans","wenquanyi micro hei","Hiragino Sans GB","Hiragino Sans GB W3",FontAwesome,sans-serif;
}
.builder-data-empty {
margin-bottom: 20px;
background-color: #f9f9f9;
}
.no-data {
padding: 130px 0;
color: #555;
}
.am-text-center {
text-align: center !important;
}
</style>
{block name="myStyle"}{/block}
<!--[if lt IE 9]>

View File

@ -7,31 +7,63 @@
if( tableObj.topButton ){
tableHtml += buildTopButton( tableObj );
}
tableHtml += '<table class="table table-bordered"> <tbody>';
if( tableObj.header ){
tableHtml += buildHeader( tableObj );
}
if( tableObj.data ){
tableHtml += buildDataList( tableObj );
}else{
tableHtml += buildEmptyTable();
tableHtml += buildEmptyTable( tableObj );
}
tableHtml += '</div></div>';
tableHtml += '</tbody></table></div></div>';
return tableHtml;
};
function buildHeader( tableObj ) {
var headerHtml = '<tr><th style="width: 10px"><input type="checkbox"></th>';
$.each(tableObj.header, function (index, value) {
headerHtml += '<th>'+ value.info +'</th>';
});
headerHtml += '</tr>';
return headerHtml;
}
function buildTopButton( tableObj ) {
var topHtml = '<div class="btn-group margin-bottom">';
if( tableObj.topButton ){
$.each(tableObj.topButton, function(index, value) {
if( value.confirm ){
value.class += ' confirm';
}
if( value.icon ){
topHtml += '<button href="'+value.href+'" type="button" class="btn '+value.class+'"><i class="'+value.icon+'"></i> '+value.info+'</button>';
}else{
topHtml += '<button href="'+value.href+'" type="button" class="btn '+value.class+'">'+value.info+'</button>';
}
});
}
topHtml += '</div>';
return topHtml;
}
function buildDataList( tableObj ) {
var dataListHtml = '<tr><td><input type="checkbox"></td>';
$.each(tableObj.data, function (index, value) {
dataListHtml += '<td></td>';
});
dataListHtml += '</tr>';
return dataListHtml;
}
function buildEmptyTable() {
function buildEmptyTable( tableObj ) {
var emptyHtml = '<tr>';
var spanNum = tableObj.header.length + 1;
emptyHtml += '<td colspan="'+spanNum+'" class="builder-data-empty">';
emptyHtml += '<div class="am-text-center no-data" >';
emptyHtml += '<i class="fa fa-cogs"></i> 暂时没有数据<br>';
emptyHtml += '<small> 本系统由<b> 七维视觉科技有限公司 </b>开发维护</small>';
emptyHtml += '</div></td></tr>';
return emptyHtml;
}
})(jQuery);

File diff suppressed because one or more lines are too long