diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index b7b2551..5c4ac2f 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -9,6 +9,7 @@ namespace app\admin\controller; class Menu extends Base { public function index(){ + $data = \app\admin\model\Menu::all(); $table = [ 'tempType' => 'table', 'header' => [ @@ -85,14 +86,14 @@ class Menu extends Base { 'hide' => [ 'module' => 'label', 'rule' => [ - [ - 'info' => '隐藏', - 'class' => 'label label-warning' - ], [ 'info' => '显示', 'class' => 'label label-success' ], + [ + 'info' => '隐藏', + 'class' => 'label label-warning' + ] ] ], 'type' => [ @@ -109,15 +110,28 @@ class Menu extends Base { ] ] ], - 'data' => [] //这个数据应该是从数据库中查出来 + 'data' => $data //这个数据应该是从数据库中查出来 ]; $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); } public function add(){ 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{ + $data = \app\admin\model\Menu::where([])->column('name',$this->primaryKey); $form = [ 'tempType' => 'add', 'formAttr' => [ @@ -143,7 +157,7 @@ class Menu extends Base { 'attr' => [ 'name' => 'fid', 'value' => '', - 'options' => [] + 'options' => $data ] ], [ @@ -223,8 +237,8 @@ class Menu extends Base { 'description' => '', 'info' => '排序:「数字越小顺序越靠前」', 'attr' => [ - 'name' => 'order', - 'value' => '', + 'name' => 'sort', + 'value' => '0', 'placeholder' => '' ] ] @@ -235,7 +249,137 @@ class Menu extends Base { } 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(){ diff --git a/public/admin/static/js/template/table.js b/public/admin/static/js/template/table.js index 5a586a4..c0f7ea9 100644 --- a/public/admin/static/js/template/table.js +++ b/public/admin/static/js/template/table.js @@ -67,9 +67,9 @@ * @returns {string} */ function buildDataList( tableObj ) { - var paramStr; - var dataListHtml = ''; + var paramStr, dataListHtml = ''; $.each(tableObj.data, function (dataIndex, dataValue) { + dataListHtml += ''; $.each(tableObj.header, function (fieldIndex, fieldValue) { var fieldName = fieldValue.field; if( fieldName == 'action' ){ @@ -107,8 +107,8 @@ } } }); + dataListHtml += ''; }); - dataListHtml += ''; return dataListHtml; }