modified 完成表格部分样式适配

This commit is contained in:
zhaoxiang 2016-11-08 17:00:38 +08:00
parent 5e25837337
commit a48b7c4bf7
3 changed files with 96 additions and 26 deletions

View File

@ -55,19 +55,19 @@ class Menu extends Base {
], ],
'rightButton' => [ 'rightButton' => [
[ [
'desc' => '编辑', 'info' => '编辑',
'href' => 'Menu/edit', 'href' => url('Menu/edit'),
'class'=> 'success', 'class'=> 'success',
'param'=> $this->primaryKey, 'param'=> [$this->primaryKey],
'icon' => 'check', 'icon' => 'check',
'confirm' => 0, 'confirm' => 0,
'show' => '' 'show' => ''
], ],
[ [
'desc' => '删除', 'info' => '删除',
'href' => 'Menu/del', 'href' => url('Menu/del'),
'class'=> 'danger', 'class'=> 'danger',
'param'=> $this->primaryKey, 'param'=> [$this->primaryKey],
'icon' => 'trash', 'icon' => 'trash',
'confirm' => 1, 'confirm' => 1,
'show' => '' 'show' => ''
@ -75,13 +75,11 @@ class Menu extends Base {
], ],
'typeRule' => [ 'typeRule' => [
'name' => [ 'name' => [
[
'module' => 'a', 'module' => 'a',
'rule' => [ 'rule' => [
'info' => '', 'info' => '',
'href' => 'Menu/add', 'href' => url('Menu/add'),
'param'=> $this->primaryKey, 'param'=> [$this->primaryKey],
]
] ]
], ],
'hide' => [ 'hide' => [
@ -89,11 +87,11 @@ class Menu extends Base {
'rule' => [ 'rule' => [
[ [
'info' => '隐藏', 'info' => '隐藏',
'class' => 'warning' 'class' => 'label label-warning'
], ],
[ [
'info' => '显示', 'info' => '显示',
'class' => 'success' 'class' => 'label label-success'
], ],
] ]
], ],
@ -102,16 +100,26 @@ class Menu extends Base {
'rule' => [ 'rule' => [
[ [
'info' => '方法类功能', 'info' => '方法类功能',
'class' => 'secondary' 'class' => 'label label-info'
], ],
[ [
'info' => '模块类功能', 'info' => '模块类功能',
'class' => 'primary' 'class' => 'label label-primary'
] ]
] ]
] ]
], ],
'data' => [] 'data' => [
[
'id' => 1,
'name' => '测试',
'url' => 'ssssss',
'type' => 1,
'hide' => 1,
'level' => 3,
'sort' => 4
]
]
]; ];
$this->result($table,200); $this->result($table,200);
} }

View File

@ -27,6 +27,9 @@
.am-text-center { .am-text-center {
text-align: center !important; text-align: center !important;
} }
a{
cursor:pointer;
}
</style> </style>
{block name="myStyle"}{/block} {block name="myStyle"}{/block}
<!--[if lt IE 9]> <!--[if lt IE 9]>
@ -614,18 +617,23 @@
success: function(data){ success: function(data){
if( data.code == 200 ){ if( data.code == 200 ){
if( data.data.tempType == 'table' ){ if( data.data.tempType == 'table' ){
if( $.buildTable ){ // if( $.buildTable ){
$('#content').html($.buildTable(data.data)); // $('#content').html($.buildTable(data.data));
$('#tableBox').hide().fadeIn(800); // $('#tableBox').hide().fadeIn(800);
}else{ // }else{
$.getScript('__JS__/template/table.js', function (){ $.getScript('__JS__/template/table.js', function (){
$('#content').html($.buildTable(data.data)); $('#content').html($.buildTable(data.data));
$('#tableBox').hide().fadeIn(800); $('#tableBox').hide().fadeIn(800);
}); });
} // }
} }
}else{ }else{
$.alertMsg('请求失败!') $.alertMsg(data.msg);
setTimeout(function() {
if (data.url) {
location.href = data.url;
}
}, 1000*data.wait);
} }
} }
}); });

View File

@ -2,6 +2,7 @@
* Created by 7d-vision on 2016/11/7. * Created by 7d-vision on 2016/11/7.
*/ */
(function ($) { (function ($) {
$.buildTable = function ( tableObj ) { $.buildTable = function ( tableObj ) {
var tableHtml = '<div class="box" id="tableBox"><div class="box-body">'; var tableHtml = '<div class="box" id="tableBox"><div class="box-body">';
if( tableObj.rightButton && tableObj.rightButton.length ){ if( tableObj.rightButton && tableObj.rightButton.length ){
@ -67,13 +68,66 @@
*/ */
function buildDataList( tableObj ) { function buildDataList( tableObj ) {
var dataListHtml = '<tr><td><input type="checkbox"></td>'; var dataListHtml = '<tr><td><input type="checkbox"></td>';
$.each(tableObj.data, function (index, value) { $.each(tableObj.data, function (dataIndex, dataValue) {
dataListHtml += '<td></td>'; $.each(tableObj.header, function (fieldIndex, fieldValue) {
var fieldName = fieldValue.field;
if( fieldName == 'action' ){
}else{
if( tableObj.typeRule[fieldName] ){
var rule = tableObj.typeRule[fieldName];
var styleList ,detailInfo, paramStr;
switch (rule.module){
case 'label':
if( rule.rule[dataValue[fieldName]] ){
styleList = rule.rule[dataValue[fieldName]];
detailInfo = prepareInfo( styleList, dataValue, fieldName);
dataListHtml += '<td><span class="'+styleList['class']+'">'+detailInfo+'</span></td>';
}else{
dataListHtml += '<td style="color:red;">' + dataValue[fieldName] + '</td>';
}
break;
case 'a':
styleList = rule.rule;
detailInfo = prepareInfo( styleList, dataValue, fieldName);
paramStr = prepareParamStr( styleList, dataValue );
dataListHtml += '<td><a url="'+styleList['href']+'" data="'+paramStr+'">' + detailInfo + '</a></td>';
break;
case 'date':
dataListHtml += '<td>' + $.formatDate(dataValue[fieldName]) + '</td>';
break;
}
}else{
dataListHtml += '<td>' + dataValue[fieldName] + '</td>';
}
}
});
}); });
dataListHtml += '</tr>'; dataListHtml += '</tr>';
return dataListHtml; return dataListHtml;
} }
function prepareInfo( styleList, dataValue, fieldName ) {
var detailInfo;
if( styleList['info'] && styleList['info'].length ){
detailInfo = styleList['info'];
}else{
detailInfo = dataValue[fieldName];
}
return detailInfo;
}
function prepareParamStr( styleList, dataValue ) {
var paramStr = '';
if( styleList['param'].length ){
$.each(styleList['param'], function (paramIndex, paramValue) {
paramStr += paramValue + '=' + dataValue[paramValue] + '&';
});
paramStr = paramStr.substring(0, paramStr.length-1);
}
return paramStr;
}
/** /**
* 创建空数据表 * 创建空数据表
* @param tableObj * @param tableObj