diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 5c4ac2f..162c0d1 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -1,5 +1,6 @@ 'require', ],[ - 'name.require' => '名称必须', + 'name.require' => '菜单名称不能为空', ] )->save($this->request->post()); if(false === $result){ @@ -250,17 +251,17 @@ 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()); + $data = $this->request->put(); + $validate = new Validate([ + 'name' => 'require', + ],[ + 'name.require' => '菜单名称不能为空', + ]); + if(!$validate->check($data)){ + $this->error($validate->getError()); }else{ + $menuModel = new \app\admin\model\Menu(); + $menuModel->allowField(true)->update($data); $this->success('操作成功!', url('Menu/index')); } }else{ @@ -269,8 +270,8 @@ class Menu extends Base { $form = [ 'tempType' => 'edit', 'formAttr' => [ - 'target' => url('Menu/add'), - 'formId' => 'add-menu-form', + 'target' => url('Menu/edit'), + 'formId' => 'edit-menu-form', 'backUrl' => url('Menu/index'), ], 'formList' => [ @@ -284,6 +285,16 @@ class Menu extends Base { 'placeholder' => '' ] ], + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => 'id', + 'value' => $detail['id'], + 'placeholder' => '' + ] + ], [ 'module' => 'select', 'description' => '', diff --git a/public/admin/static/js/template.js b/public/admin/static/js/template.js index c2a0820..424d41c 100644 --- a/public/admin/static/js/template.js +++ b/public/admin/static/js/template.js @@ -30,7 +30,8 @@ * @param msg * @param wait 等待时间(毫秒) */ - $.alertMsg = function( msg, wait = 2800 ){ + $.alertMsg = function( msg, wait ){ + wait = wait ? wait : 2800; var dialog = bootbox.dialog({ message: '

'+msg+'

', closeButton: false @@ -45,7 +46,8 @@ * @param url * @param urlData */ - $.refresh = function ( url, urlData = '' ) { + $.refresh = function ( url, urlData ) { + urlData = urlData ? urlData : ''; $.ajax({ type: "GET", url: url, @@ -98,7 +100,7 @@ }; /** - * Ajax Post 表单提交(增) + * Ajax Post 表单提交(增) * */ bodyDom.on('click', '.ajax-post', function() { var message,query,form,target; @@ -139,7 +141,7 @@ }); /** - * Ajax Put 表单提交(改) + * Ajax Put 表单提交(改) * */ bodyDom.on('click', '.ajax-put', function() { var message,query,form,target; @@ -162,18 +164,11 @@ $.alertMsg(message); setTimeout(function() { if (data.url) { - location.href = data.url; - } else { - location.reload(); + $.refresh(data.url); } }, wait); } else { $.alertMsg(data.msg); - setTimeout(function() { - if (data.url) { - location.href = data.url; - } - }, wait); } }); return false; diff --git a/public/admin/static/js/template/form.js b/public/admin/static/js/template/form.js index df161ed..aa7afb2 100644 --- a/public/admin/static/js/template/form.js +++ b/public/admin/static/js/template/form.js @@ -8,7 +8,7 @@ * @returns {string} */ $.buildAddForm = function ( formObj ) { - return buildForm(formObj, 'box-success'); + return buildForm(formObj, 'box-success', 'ajax-post'); }; /** @@ -17,16 +17,17 @@ * @returns {string} */ $.buildEditForm = function ( formObj ) { - return buildForm(formObj, 'box-warning'); + return buildForm(formObj, 'box-warning', 'ajax-put'); }; /** * 根据规则创建表单 * @param formObj 表单数据对象 * @param boxType box样式 + * @param method 数据提交方式 * @returns {string} */ - function buildForm( formObj, boxType ) { + function buildForm( formObj, boxType, method ) { var formHtml = '
'; formHtml += '

新增菜单

'; formHtml += '
'; @@ -41,10 +42,13 @@ case 'radio': formHtml += buildRadio(value); break; + case 'hidden': + formHtml += buildHidden(value); + break; } }); formHtml += '
'; return formHtml; } @@ -96,6 +100,15 @@ formHtml += ''; return formHtml; } + + /** + * 创建隐藏表单 + * @param hiddenObj + * @returns {string} + */ + function buildHidden( hiddenObj ) { + return ''; + } function buildTextarea( textareaObj ) {