diff --git a/application/admin/controller/ApiFieldsManager.php b/application/admin/controller/ApiFieldsManager.php index 56d9f97..784bc90 100644 --- a/application/admin/controller/ApiFieldsManager.php +++ b/application/admin/controller/ApiFieldsManager.php @@ -7,6 +7,7 @@ namespace app\admin\controller; +use app\admin\model\ApiBack; use app\admin\model\ApiFields; class ApiFieldsManager extends Base { @@ -24,11 +25,11 @@ class ApiFieldsManager extends Base { ]; public function index(){ - if( !session('apiId') ){ - if( $this->request->get($this->primaryKey) ){ - session('apiId', $this->request->get($this->primaryKey)); - session('apiName', $this->request->get('name')); - }else{ + if( $this->request->get($this->primaryKey) ){ + session('apiId', $this->request->get($this->primaryKey)); + session('apiName', $this->request->get('name')); + }else{ + if( !session('apiId') ){ $this->error('缺少必要参数', ''); } } @@ -115,7 +116,77 @@ class ApiFieldsManager extends Base { } public function back(){ - + if( $this->request->get($this->primaryKey) ){ + session('apiId', $this->request->get($this->primaryKey)); + session('apiName', $this->request->get('name')); + }else{ + if( !session('apiId') ){ + $this->error('缺少必要参数', ''); + } + } + $data = ApiBack::all(['apiId' => session('apiId')]); + $table = [ + 'tempType' => 'table', + 'header' => [ + [ + 'field' => 'name', + 'info' => '字段名称' + ], + [ + 'field' => 'type', + 'info' => '字段类型' + ], + [ + 'field' => 'info', + 'info' => '字段说明' + ] + ], + 'topButton' => [ + [ + 'href' => 'ApiFieldsManager/backAdd', + 'class'=> 'btn-success', + 'info'=> '新增', + 'icon' => 'fa fa-plus', + 'confirm' => 0, + ], + [ + 'href' => 'ApiFieldsManager/backDel', + 'class'=> 'btn-danger ajax-delete', + 'info'=> '删除', + 'icon' => 'fa fa-trash', + 'confirm' => 1, + ] + ], + 'rightButton' => [ + [ + 'info' => '编辑', + 'href' => 'ApiFieldsManager/backEdit', + 'class'=> 'btn-primary', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-pencil', + 'confirm' => 0, + 'show' => '' + ], + [ + 'info' => '删除', + 'href' => 'ApiFieldsManager/backDel', + 'class'=> 'btn-danger ajax-delete', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-trash', + 'confirm' => 1, + 'show' => '' + ] + ], + 'typeRule' => [ + 'type' => [ + 'module' => 'listValue', + 'rule' => $this->dataType + ], + ], + 'data' => $data + ]; + $table = $this->_prepareTemplate($table); + $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); } public function add(){ @@ -207,7 +278,68 @@ class ApiFieldsManager extends Base { } public function backAdd(){ - + if( $this->request->isPost() ){ + $apiModel = new ApiBack(); + $result = $apiModel->allowField(true)->save($this->request->post()); + if(false === $result){ + $this->error($apiModel->getError()); + }else{ + $this->success('操作成功!', url('ApiFieldsManager/back')); + } + }else{ + $form = [ + 'formTitle' => $this->menuInfo['name']."(".session('apiName').")", + 'tempType' => 'add', + 'formAttr' => [ + 'target' => url('ApiFieldsManager/backAdd'), + 'formId' => 'add-ApiFieldsManager-form', + 'backUrl' => url('ApiFieldsManager/back'), + ], + 'formList' => [ + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => 'apiId', + 'value' => session('apiId'), + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '字段名称:', + 'attr' => [ + 'name' => 'name', + 'value' => '', + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '字段类型:', + 'attr' => [ + 'name' => 'type', + 'value' => '', + 'options' => $this->dataType + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '字段描述:', + 'attr' => [ + 'name' => 'info', + 'value' => '', + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } } public function edit(){ @@ -307,7 +439,76 @@ class ApiFieldsManager extends Base { } public function backEdit(){ - + if( $this->request->isPut() ){ + $data = $this->request->put(); + $apiModel = new ApiBack(); + $apiModel->update($data); + $this->success('操作成功!', url('ApiFieldsManager/back')); + }else{ + $detail = ApiBack::get($this->request->get($this->primaryKey))->toArray(); + $form = [ + 'formTitle' => $this->menuInfo['name']."(".session('apiName').")", + 'tempType' => 'edit', + 'formAttr' => [ + 'target' => url('ApiFieldsManager/backEdit'), + 'formId' => 'edit-ApiFieldsManager-form', + 'backUrl' => url('ApiFieldsManager/back'), + ], + 'formList' => [ + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => $this->primaryKey, + 'value' => $detail[$this->primaryKey], + 'placeholder' => '' + ] + ], + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => 'apiId', + 'value' => session('apiId'), + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '字段名称:', + 'attr' => [ + 'name' => 'name', + 'value' => $detail['name'], + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '字段类型:', + 'attr' => [ + 'name' => 'type', + 'value' => $detail['type'], + 'options' => $this->dataType + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '字段描述:', + 'attr' => [ + 'name' => 'info', + 'value' => $detail['info'], + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } } public function del(){ @@ -322,6 +523,13 @@ class ApiFieldsManager extends Base { } public function backDel(){ - + if( $this->request->isDelete() ){ + $key = $this->request->delete($this->primaryKey); + $delNum = ApiBack::destroy($key); + if( $delNum ){ + $this->success('操作成功!', url('ApiFieldsManager/back')); + } + } + $this->error('操作失败!'); } } \ No newline at end of file