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' => [
[
'desc' => '编辑',
'href' => 'Menu/edit',
'info' => '编辑',
'href' => url('Menu/edit'),
'class'=> 'success',
'param'=> $this->primaryKey,
'param'=> [$this->primaryKey],
'icon' => 'check',
'confirm' => 0,
'show' => ''
],
[
'desc' => '删除',
'href' => 'Menu/del',
'info' => '删除',
'href' => url('Menu/del'),
'class'=> 'danger',
'param'=> $this->primaryKey,
'param'=> [$this->primaryKey],
'icon' => 'trash',
'confirm' => 1,
'show' => ''
@ -75,13 +75,11 @@ class Menu extends Base {
],
'typeRule' => [
'name' => [
[
'module' => 'a',
'rule' => [
'info' => '',
'href' => 'Menu/add',
'param'=> $this->primaryKey,
]
'module' => 'a',
'rule' => [
'info' => '',
'href' => url('Menu/add'),
'param'=> [$this->primaryKey],
]
],
'hide' => [
@ -89,11 +87,11 @@ class Menu extends Base {
'rule' => [
[
'info' => '隐藏',
'class' => 'warning'
'class' => 'label label-warning'
],
[
'info' => '显示',
'class' => 'success'
'class' => 'label label-success'
],
]
],
@ -102,16 +100,26 @@ class Menu extends Base {
'rule' => [
[
'info' => '方法类功能',
'class' => 'secondary'
'class' => 'label label-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);
}

View File

@ -27,6 +27,9 @@
.am-text-center {
text-align: center !important;
}
a{
cursor:pointer;
}
</style>
{block name="myStyle"}{/block}
<!--[if lt IE 9]>
@ -614,18 +617,23 @@
success: function(data){
if( data.code == 200 ){
if( data.data.tempType == 'table' ){
if( $.buildTable ){
$('#content').html($.buildTable(data.data));
$('#tableBox').hide().fadeIn(800);
}else{
// if( $.buildTable ){
// $('#content').html($.buildTable(data.data));
// $('#tableBox').hide().fadeIn(800);
// }else{
$.getScript('__JS__/template/table.js', function (){
$('#content').html($.buildTable(data.data));
$('#tableBox').hide().fadeIn(800);
});
}
// }
}
}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.
*/
(function ($) {
$.buildTable = function ( tableObj ) {
var tableHtml = '<div class="box" id="tableBox"><div class="box-body">';
if( tableObj.rightButton && tableObj.rightButton.length ){
@ -67,13 +68,66 @@
*/
function buildDataList( tableObj ) {
var dataListHtml = '<tr><td><input type="checkbox"></td>';
$.each(tableObj.data, function (index, value) {
dataListHtml += '<td></td>';
$.each(tableObj.data, function (dataIndex, dataValue) {
$.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>';
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