From 13943f5f3e146dfaddfeece881410c22e40dd9b8 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Mon, 12 Dec 2016 20:22:01 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E6=96=B0=E5=A2=9E=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?API=E5=AD=97=E6=AE=B5=E8=A7=84=E5=88=99=E7=9A=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E8=A1=A8=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/AppManager.php | 270 +++++++++++++++++--- application/admin/model/ApiBack.php | 12 + application/admin/model/ApiFields.php | 12 + 3 files changed, 260 insertions(+), 34 deletions(-) create mode 100644 application/admin/model/ApiBack.php create mode 100644 application/admin/model/ApiFields.php diff --git a/application/admin/controller/AppManager.php b/application/admin/controller/AppManager.php index bf99b93..2b4133a 100644 --- a/application/admin/controller/AppManager.php +++ b/application/admin/controller/AppManager.php @@ -1,6 +1,6 @@ */ @@ -13,9 +13,7 @@ use app\admin\model\App; class AppManager extends Base { public function index(){ - $data = []; -// $dataObj = App::all(); - + $data = App::all(); $table = [ 'tempType' => 'table', 'header' => [ @@ -24,32 +22,28 @@ class AppManager extends Base { 'info' => '应用名称' ], [ - 'field' => 'token', - 'info' => '应用唯一标识' - ], - [ - 'field' => 'baseUrl', - 'info' => '基础URL' - ], - [ - 'field' => 'keyGroup', - 'info' => '关联秘钥组' + 'field' => 'info', + 'info' => '应用描述' ], [ 'field' => 'type', - 'info' => '参与角色' + 'info' => '参与方式' + ], + [ + 'field' => 'status', + 'info' => '状态' ] ], 'topButton' => [ [ - 'href' => 'Menu/add', + 'href' => 'AppManager/add', 'class'=> 'btn-success', 'info'=> '新增', 'icon' => 'fa fa-plus', 'confirm' => 0, ], [ - 'href' => 'Menu/del', + 'href' => 'AppManager/del', 'class'=> 'btn-danger ajax-delete', 'info'=> '删除', 'icon' => 'fa fa-trash', @@ -57,10 +51,28 @@ class AppManager extends Base { ] ], 'rightButton' => [ + [ + 'info' => '启用', + 'href' => 'AppManager/open', + 'class'=> 'btn-success ajax-put-url', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-check', + 'confirm' => 1, + 'show' => ['status', 0] + ], + [ + 'info' => '禁用', + 'href' => 'AppManager/close', + 'class'=> 'btn-warning ajax-put-url', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-close', + 'confirm' => 1, + 'show' => ['status', 1] + ], [ 'info' => '编辑', - 'href' => 'Menu/edit', - 'class'=> 'btn-warning', + 'href' => 'AppManager/edit', + 'class'=> 'btn-primary', 'param'=> [$this->primaryKey], 'icon' => 'fa fa-pencil', 'confirm' => 0, @@ -68,7 +80,7 @@ class AppManager extends Base { ], [ 'info' => '删除', - 'href' => 'Menu/del', + 'href' => 'AppManager/del', 'class'=> 'btn-danger ajax-delete', 'param'=> [$this->primaryKey], 'icon' => 'fa fa-trash', @@ -77,25 +89,29 @@ class AppManager extends Base { ] ], 'typeRule' => [ - 'name' => [ - 'module' => 'a', - 'rule' => [ - 'info' => '', - 'href' => url('Menu/add'), - 'param'=> [$this->primaryKey], - 'class' => 'refresh' - ] - ], - 'hide' => [ + 'type' => [ 'module' => 'label', 'rule' => [ [ - 'info' => '显示', - 'class' => 'label label-success' + 'info' => '监视方式', + 'class' => 'label label-info' ], [ - 'info' => '隐藏', - 'class' => 'label label-warning' + 'info' => '网关方式', + 'class' => 'label label-primary' + ] + ] + ], + 'status' => [ + 'module' => 'label', + 'rule' => [ + [ + 'info' => '禁用', + 'class' => 'label label-danger' + ], + [ + 'info' => '启用', + 'class' => 'label label-success' ] ] ] @@ -106,4 +122,190 @@ class AppManager extends Base { $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); } + public function add(){ + if( $this->request->isPost() ){ + $appModel = new App(); + $result = $appModel->allowField(true)->save($this->request->post()); + if(false === $result){ + $this->error($appModel->getError()); + }else{ + $this->success('操作成功!', url('AppManager/index')); + } + }else{ + $form = [ + 'formTitle' => $this->menuInfo['name'], + 'tempType' => 'add', + 'formAttr' => [ + 'target' => url('AppManager/add'), + 'formId' => 'add-AppManager-form', + 'backUrl' => url('AppManager/index'), + ], + 'formList' => [ + [ + 'module' => 'text', + 'description' => '', + 'info' => '应用名称:', + 'attr' => [ + 'name' => 'name', + 'value' => '', + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '基础链接:', + 'attr' => [ + 'name' => 'baseUrl', + 'value' => '', + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '参与方式:', + 'attr' => [ + 'name' => 'type', + 'value' => '', + 'options' => [ + '监视方式', + '网关方式' + ] + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '应用描述:', + 'attr' => [ + 'name' => 'info', + 'value' => '', + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } + } + + public function open(){ + if( $this->request->isPut() ){ + $id = $this->request->put($this->primaryKey); + $appMemberObj = \app\admin\model\AppMember::get([$this->primaryKey => $id]); + if( is_null($appMemberObj) ){ + $this->error('管理员不存在',''); + }else{ + $appMemberObj->status = 1; + $appMemberObj->save(); + $this->success('操作成功', url('AppMember/index')); + } + } + } + + public function close(){ + if( $this->request->isPut() ){ + $id = $this->request->put($this->primaryKey); + $appMemberObj = \app\admin\model\AppMember::get([$this->primaryKey => $id]); + if( is_null($appMemberObj) ){ + $this->error('管理员不存在',''); + }else{ + $appMemberObj->status = 0; + $appMemberObj->save(); + $this->success('操作成功', url('AppMember/index')); + } + } + } + + public function del(){ + if( $this->request->isDelete() ){ + $key = $this->request->delete($this->primaryKey); + $delNum = \app\admin\model\AppMember::destroy($key); + if( $delNum ){ + $this->success('操作成功!', url('AppMember/index')); + } + } + $this->error('操作失败!'); + } + + public function edit(){ + if( $this->request->isPut() ){ + if( empty($this->request->put('name')) ){ + $this->error('应用名称不能为空', ''); + } + $data = $this->request->put(); + $appMemberModel = new App(); + $appMemberModel->update($data); + $this->success('操作成功!', url('AppManager/index')); + }else{ + $detail = App::get($this->request->get($this->primaryKey))->toArray(); + $form = [ + 'formTitle' => $this->menuInfo['name'], + 'tempType' => 'edit', + 'formAttr' => [ + 'target' => url('AppManager/edit'), + 'formId' => 'edit-AppManager-form', + 'backUrl' => url('AppManager/index'), + ], + 'formList' => [ + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => $this->primaryKey, + 'value' => $detail[$this->primaryKey], + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '应用名称:', + 'attr' => [ + 'name' => 'name', + 'value' => $detail['name'], + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '基础链接:', + 'attr' => [ + 'name' => 'baseUrl', + 'value' => $detail['baseUrl'], + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '参与方式:', + 'attr' => [ + 'name' => 'type', + 'value' => $detail['type'], + 'options' => [ + '监视方式', + '网关方式' + ] + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '应用描述:', + 'attr' => [ + 'name' => 'info', + 'value' => $detail['info'], + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } + } + } \ No newline at end of file diff --git a/application/admin/model/ApiBack.php b/application/admin/model/ApiBack.php new file mode 100644 index 0000000..83546b1 --- /dev/null +++ b/application/admin/model/ApiBack.php @@ -0,0 +1,12 @@ + + */ + +namespace app\admin\model; + + +class ApiBack extends Base { + +} \ No newline at end of file diff --git a/application/admin/model/ApiFields.php b/application/admin/model/ApiFields.php new file mode 100644 index 0000000..d0031cb --- /dev/null +++ b/application/admin/model/ApiFields.php @@ -0,0 +1,12 @@ + + */ + +namespace app\admin\model; + + +class ApiFields extends Base { + +} \ No newline at end of file