From 21cc5142f2a1476064c271adc5ec0b6bb40b73f0 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 9 Nov 2016 22:57:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?added=20=E6=96=B0=E5=A2=9E=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E7=9A=84icon=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/admin/static/js/template/table.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/admin/static/js/template/table.js b/public/admin/static/js/template/table.js index c0f7ea9..f4e349d 100644 --- a/public/admin/static/js/template/table.js +++ b/public/admin/static/js/template/table.js @@ -101,6 +101,14 @@ case 'date': dataListHtml += '' + $.formatDate(dataValue[fieldName]) + ''; break; + case 'icon': + if( rule.rule[dataValue[fieldName]] ){ + styleList = rule.rule[dataValue[fieldName]]; + dataListHtml += ''; + }else{ + dataListHtml += '' + dataValue[fieldName] + ''; + } + break; } }else{ dataListHtml += '' + dataValue[fieldName] + ''; From b19f11264ae28bca80f07e0e7f0c56b4b3a525c8 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 9 Nov 2016 23:49:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?modified=20=E7=BB=86=E8=8A=82=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=AE=8C=E6=88=90=E6=95=B0=E6=8D=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Menu.php | 37 ++++++++++++++++--------- public/admin/static/js/template.js | 19 +++++-------- public/admin/static/js/template/form.js | 21 +++++++++++--- 3 files changed, 48 insertions(+), 29 deletions(-) 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 ) { From a3ccc69e18ef298cb1f0b083709481ca276d1371 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 9 Nov 2016 23:59:01 +0800 Subject: [PATCH 3/5] =?UTF-8?q?modified=20=E6=89=A9=E5=85=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84class=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Menu.php | 4 +++- public/admin/static/js/template/table.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 162c0d1..0345cec 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -82,6 +82,7 @@ class Menu extends Base { 'info' => '', 'href' => url('Menu/add'), 'param'=> [$this->primaryKey], + 'class' => 'refresh' ] ], 'hide' => [ @@ -133,6 +134,7 @@ class Menu extends Base { } }else{ $data = \app\admin\model\Menu::where([])->column('name',$this->primaryKey); + $defaultFather = $this->request->get($this->primaryKey); $form = [ 'tempType' => 'add', 'formAttr' => [ @@ -157,7 +159,7 @@ class Menu extends Base { 'info' => '父级菜单:', 'attr' => [ 'name' => 'fid', - 'value' => '', + 'value' => $defaultFather, 'options' => $data ] ], diff --git a/public/admin/static/js/template/table.js b/public/admin/static/js/template/table.js index f4e349d..478e956 100644 --- a/public/admin/static/js/template/table.js +++ b/public/admin/static/js/template/table.js @@ -81,7 +81,7 @@ }else{ if( tableObj.typeRule[fieldName] ){ var rule = tableObj.typeRule[fieldName]; - var styleList ,detailInfo; + var styleList ,detailInfo, classAttr = ''; switch (rule.module){ case 'label': if( rule.rule[dataValue[fieldName]] ){ @@ -96,7 +96,10 @@ styleList = rule.rule; detailInfo = prepareInfo( styleList, dataValue, fieldName); paramStr = prepareParamStr( styleList, dataValue ); - dataListHtml += '' + detailInfo + ''; + if( styleList['class'] ){ + classAttr = 'class="'+ styleList['class'] +'"'; + } + dataListHtml += '' + detailInfo + ''; break; case 'date': dataListHtml += '' + $.formatDate(dataValue[fieldName]) + ''; From b1fd6a1f568da5e50117cf1e18dd0b4ae1d300bf Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Thu, 10 Nov 2016 00:10:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?added=20=E6=96=B0=E5=A2=9E=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Menu.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 0345cec..9551770 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -396,7 +396,18 @@ class Menu extends Base { } public function del(){ - $this->error('失败'); + if( $this->request->isDelete() ){ + $key = $this->request->delete($this->primaryKey); + $childNum = \app\admin\model\Menu::where(['fid' => $key])->count(); + if( $childNum ){ + $this->error('当前菜单存在子菜单,删除失败!'); + } + $delNum = \app\admin\model\Menu::destroy($key); + if( $delNum ){ + $this->success('操作成功!', url('Menu/index')); + } + } + $this->error('操作失败!'); } } \ No newline at end of file From 621fbc5a77c911a81a3be37e85ce3025cd1a30b3 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Thu, 10 Nov 2016 00:42:26 +0800 Subject: [PATCH 5/5] =?UTF-8?q?modified=20=E4=BC=98=E5=8C=96=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=9D=83=E9=99=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Menu.php | 155 ++++++++++++++++-------- public/admin/static/js/template/form.js | 24 ++++ 2 files changed, 128 insertions(+), 51 deletions(-) diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 9551770..eedba7b 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -22,14 +22,26 @@ class Menu extends Base { 'field' => 'url', 'info' => '菜单URL' ], - [ - 'field' => 'type', - 'info' => '菜单类型' - ], [ 'field' => 'level', 'info' => '等级' ], + [ + 'field' => 'post', + 'info' => 'Post' + ], + [ + 'field' => 'get', + 'info' => 'Get' + ], + [ + 'field' => 'put', + 'info' => 'Put' + ], + [ + 'field' => 'delete', + 'info' => 'Delete' + ], [ 'field' => 'hide', 'info' => '隐藏' @@ -98,21 +110,60 @@ class Menu extends Base { ] ] ], - 'type' => [ - 'module' => 'label', + 'post' => [ + 'module' => 'icon', 'rule' => [ [ - 'info' => '方法类功能', - 'class' => 'label label-info' + 'info' => '', + 'class' => 'fa fa-close' ], [ - 'info' => '模块类功能', - 'class' => 'label label-primary' + 'info' => '', + 'class' => 'fa fa-check' + ] + ] + ], + 'get' => [ + 'module' => 'icon', + 'rule' => [ + [ + 'info' => '', + 'class' => 'fa fa-close' + ], + [ + 'info' => '', + 'class' => 'fa fa-check' + ] + ] + ], + 'put' => [ + 'module' => 'icon', + 'rule' => [ + [ + 'info' => '', + 'class' => 'fa fa-close' + ], + [ + 'info' => '', + 'class' => 'fa fa-check' + ] + ] + ], + 'delete' => [ + 'module' => 'icon', + 'rule' => [ + [ + 'info' => '', + 'class' => 'fa fa-close' + ], + [ + 'info' => '', + 'class' => 'fa fa-check' ] ] ] ], - 'data' => $data //这个数据应该是从数据库中查出来 + 'data' => $data ]; $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); } @@ -177,15 +228,29 @@ class Menu extends Base { ] ], [ - 'module' => 'radio', + 'module' => 'checkbox', 'description' => '', - 'info' => '菜单类型:', + 'info' => '访客权限:', 'attr' => [ - 'name' => 'type', - 'value' => '', - 'options' => [ - '模块类功能', - '方法类功能' + [ + 'name' => 'auth[get]', + 'desc' => 'GET', + 'value' => '' + ], + [ + 'name' => 'auth[put]', + 'desc' => 'PUT', + 'value' => '' + ], + [ + 'name' => 'auth[post]', + 'desc' => 'POST', + 'value' => '' + ], + [ + 'name' => 'auth[delete]', + 'desc' => 'DELETE', + 'value' => '' ] ] ], @@ -202,19 +267,6 @@ class Menu extends Base { ] ] ], - [ - 'module' => 'radio', - 'description' => '', - 'info' => '是否推荐:「该配置只对模块类功能生效」', - 'attr' => [ - 'name' => 'recommend', - 'value' => '', - 'options' => [ - '普通模块', - '推荐模块' - ] - ] - ], [ 'module' => 'text', 'description' => '', @@ -321,15 +373,29 @@ class Menu extends Base { ] ], [ - 'module' => 'radio', + 'module' => 'checkbox', 'description' => '', - 'info' => '菜单类型:', + 'info' => '访客权限:', 'attr' => [ - 'name' => 'type', - 'value' => $detail['type'], - 'options' => [ - '模块类功能', - '方法类功能' + [ + 'name' => 'auth[get]', + 'desc' => 'GET', + 'value' => '' + ], + [ + 'name' => 'auth[put]', + 'desc' => 'PUT', + 'value' => '' + ], + [ + 'name' => 'auth[post]', + 'desc' => 'POST', + 'value' => '' + ], + [ + 'name' => 'auth[delete]', + 'desc' => 'DELETE', + 'value' => '' ] ] ], @@ -346,19 +412,6 @@ class Menu extends Base { ] ] ], - [ - 'module' => 'radio', - 'description' => '', - 'info' => '是否推荐:「该配置只对模块类功能生效」', - 'attr' => [ - 'name' => 'recommend', - 'value' => $detail['recommend'], - 'options' => [ - '普通模块', - '推荐模块' - ] - ] - ], [ 'module' => 'text', 'description' => '', diff --git a/public/admin/static/js/template/form.js b/public/admin/static/js/template/form.js index aa7afb2..940d62e 100644 --- a/public/admin/static/js/template/form.js +++ b/public/admin/static/js/template/form.js @@ -45,6 +45,9 @@ case 'hidden': formHtml += buildHidden(value); break; + case 'checkbox': + formHtml += buildCheckbox(value); + break; } }); formHtml += '