added 修复数据显示的BUG

This commit is contained in:
zhaoxiang 2016-11-09 21:03:38 +08:00
parent ca80b59829
commit dc6a37a284
2 changed files with 157 additions and 13 deletions

View File

@ -9,6 +9,7 @@ namespace app\admin\controller;
class Menu extends Base { class Menu extends Base {
public function index(){ public function index(){
$data = \app\admin\model\Menu::all();
$table = [ $table = [
'tempType' => 'table', 'tempType' => 'table',
'header' => [ 'header' => [
@ -85,14 +86,14 @@ class Menu extends Base {
'hide' => [ 'hide' => [
'module' => 'label', 'module' => 'label',
'rule' => [ 'rule' => [
[
'info' => '隐藏',
'class' => 'label label-warning'
],
[ [
'info' => '显示', 'info' => '显示',
'class' => 'label label-success' 'class' => 'label label-success'
], ],
[
'info' => '隐藏',
'class' => 'label label-warning'
]
] ]
], ],
'type' => [ 'type' => [
@ -109,15 +110,28 @@ class Menu extends Base {
] ]
] ]
], ],
'data' => [] //这个数据应该是从数据库中查出来 'data' => $data //这个数据应该是从数据库中查出来
]; ];
$this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS);
} }
public function add(){ public function add(){
if( $this->request->isPost() ){ if( $this->request->isPost() ){
$menuModel = new \app\admin\model\Menu();
$result = $menuModel->allowField(true)->validate(
[
'name' => 'require',
],[
'name.require' => '名称必须',
]
)->save($this->request->post());
if(false === $result){
$this->error($menuModel->getError());
}else{
$this->success('操作成功!', url('Menu/index'));
}
}else{ }else{
$data = \app\admin\model\Menu::where([])->column('name',$this->primaryKey);
$form = [ $form = [
'tempType' => 'add', 'tempType' => 'add',
'formAttr' => [ 'formAttr' => [
@ -143,7 +157,7 @@ class Menu extends Base {
'attr' => [ 'attr' => [
'name' => 'fid', 'name' => 'fid',
'value' => '', 'value' => '',
'options' => [] 'options' => $data
] ]
], ],
[ [
@ -223,8 +237,8 @@ class Menu extends Base {
'description' => '', 'description' => '',
'info' => '排序:「数字越小顺序越靠前」', 'info' => '排序:「数字越小顺序越靠前」',
'attr' => [ 'attr' => [
'name' => 'order', 'name' => 'sort',
'value' => '', 'value' => '0',
'placeholder' => '' 'placeholder' => ''
] ]
] ]
@ -235,7 +249,137 @@ class Menu extends Base {
} }
public function edit(){ public function edit(){
if( $this->request->isPut() ){
$menuModel = new \app\admin\model\Menu();
$result = $menuModel->allowField(true)->validate(
[
'name' => 'require',
],[
'name.require' => '名称必须',
]
)->update($this->request->put());
if(false === $result){
$this->error($menuModel->getError());
}else{
$this->success('操作成功!', url('Menu/index'));
}
}else{
$data = \app\admin\model\Menu::where([])->column('name',$this->primaryKey);
$detail = \app\admin\model\Menu::get($this->request->get($this->primaryKey))->toArray();
$form = [
'tempType' => 'edit',
'formAttr' => [
'target' => url('Menu/add'),
'formId' => 'add-menu-form',
'backUrl' => url('Menu/index'),
],
'formList' => [
[
'module' => 'text',
'description' => '',
'info' => '菜单名称:',
'attr' => [
'name' => 'name',
'value' => $detail['name'],
'placeholder' => ''
]
],
[
'module' => 'select',
'description' => '',
'info' => '父级菜单:',
'attr' => [
'name' => 'fid',
'value' => $detail['fid'],
'options' => $data
]
],
[
'module' => 'select',
'description' => '',
'info' => '菜单等级:',
'attr' => [
'name' => 'level',
'value' => $detail['level'],
'options' => [
'普通认证',
'Log记录'
]
]
],
[
'module' => 'radio',
'description' => '',
'info' => '菜单类型:',
'attr' => [
'name' => 'type',
'value' => $detail['type'],
'options' => [
'模块类功能',
'方法类功能'
]
]
],
[
'module' => 'radio',
'description' => '',
'info' => '是否显示:「该配置只对模块类功能生效」',
'attr' => [
'name' => 'hide',
'value' => $detail['hide'],
'options' => [
'显示菜单',
'隐藏菜单',
]
]
],
[
'module' => 'radio',
'description' => '',
'info' => '是否推荐:「该配置只对模块类功能生效」',
'attr' => [
'name' => 'recommend',
'value' => $detail['recommend'],
'options' => [
'普通模块',
'推荐模块'
]
]
],
[
'module' => 'text',
'description' => '',
'info' => '菜单图标:「该配置只对模块类功能生效」',
'attr' => [
'name' => 'icon',
'value' => $detail['icon'],
'placeholder' => ''
]
],
[
'module' => 'text',
'description' => '',
'info' => '菜单URL「该配置只对无模块类功能子菜单的菜单生效」[具体格式为:控制器/方法名]',
'attr' => [
'name' => 'url',
'value' => $detail['url'],
'placeholder' => ''
]
],
[
'module' => 'text',
'description' => '',
'info' => '排序:「数字越小顺序越靠前」',
'attr' => [
'name' => 'sort',
'value' => $detail['sort'],
'placeholder' => ''
]
]
]
];
$this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS);
}
} }
public function del(){ public function del(){

View File

@ -67,9 +67,9 @@
* @returns {string} * @returns {string}
*/ */
function buildDataList( tableObj ) { function buildDataList( tableObj ) {
var paramStr; var paramStr, dataListHtml = '';
var dataListHtml = '<tr><td><input type="checkbox"></td>';
$.each(tableObj.data, function (dataIndex, dataValue) { $.each(tableObj.data, function (dataIndex, dataValue) {
dataListHtml += '<tr><td><input type="checkbox"></td>';
$.each(tableObj.header, function (fieldIndex, fieldValue) { $.each(tableObj.header, function (fieldIndex, fieldValue) {
var fieldName = fieldValue.field; var fieldName = fieldValue.field;
if( fieldName == 'action' ){ if( fieldName == 'action' ){
@ -107,8 +107,8 @@
} }
} }
}); });
dataListHtml += '</tr>';
}); });
dataListHtml += '</tr>';
return dataListHtml; return dataListHtml;
} }