request->isAjax) { $data = []; $params = Yii::$app->request->get('Sysconfig'); $query = mergeParams($query,$params); $countQuery = clone $query; //分页 if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));} if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));} //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $sortWay = $_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC; $resultList = $query->orderBy([$_GET['sort']=>$sortWay])->all(); } else { $resultList = $query->orderBy(['id'=>SORT_ASC])->all(); } foreach($resultList as $result) { $data[] = array('id'=>$result->id,'name'=>$result->name,'bak'=>$result->bak,'type'=>$result->type,'typeTxt'=>Sysconfig::typeOptions($result->type),'is_system'=>$result->is_system, 'list_order'=>$result->list_order,'disabled'=>$result->disabled); } $result = ["total"=>$countQuery->count(),"totalNotFiltered"=>$countQuery->count(),"rows"=>$data]; echo_json($result); } $this->tableTitle = array( array('field'=>'id','title'=>Sysconfig::getAttributeName('id'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'), array('field'=>'bak','title'=>Sysconfig::getAttributeName('bak'),'align'=>'center','class'=>'col-md-2'), array('field'=>'name','title'=>Sysconfig::getAttributeName('name'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'), array('field'=>'typeTxt','title'=>Sysconfig::getAttributeName('type'),'align'=>'center','class'=>'col-md-2'), array('field'=>'disabled','title'=>Sysconfig::getAttributeName('disabled'),'align'=>'center','formatter'=>'switchFormatter','class'=>'col-md-2'), array('field'=>'operate','title'=>Sysconfig::getAttributeName('operate'),'align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter','class'=>'col-md-2'), ); $this->tableConfig = array('table'=>Sysconfig::shortTableName(),'url'=>$this->createRealUrl(['admin/sysconfig/list']),'setFieldUrl'=>$this->createRealUrl(['admin/sysconfig/setfield']),'idField'=>Sysconfig::modelPrimaryKey(),'checkbox'=>0,'dropmenu'=>1,'pagination'=>false,'pagesize'=>2,'refresh'=>true); return $this->render('list',array('model'=>new Sysconfig())); } //添加 function actionAdd() { $model = new Sysconfig(); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('add',array('model'=>$model)); } //编辑 function actionEdit() { $id = $this->getKeyId(); $model = Sysconfig::findOne($id); check_record_exists($model); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ $post = Yii::$app->request->post(); $model->is_system = $post['Sysconfig']['is_system']?$post['Sysconfig']['is_system']:0; $model->disabled = $post['Sysconfig']['disabled']?$post['Sysconfig']['disabled']:0; if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '成功']; } else { $msgdata = ['error' => 1,'msg' => '失败']; } } echo_json($msgdata); } return $this->renderAjax('add',array('model'=>$model)); } //配置 function actionConfig() { $id = $this->getKeyId(); $model = Sysconfig::findOne($id); check_record_exists($model); if(Yii::$app->request->isAjax&&Yii::$app->request->post()){ $data = Yii::$app->request->post(); if($model->type==1) { foreach($data['group-a'] as $uintData) { $value[$uintData['k']] = $uintData['v']; } if(!empty($value))$model->value = json_encode($value); } else if($model->type==2) { foreach($data['group-a'] as $uintData) { $value[] = $uintData['v']; } if(!empty($value))$model->value = json_encode($value); } else if($model->type==3) { $model->value = $data['v']; } if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } echo_json($msgdata); } if($model->type==1) { $view = 'config1'; } else if($model->type==2) { $view = 'config2'; } else if($model->type==3) { $view = 'config3'; } if($model->type==3) { $args = $model->value; } else { if(!empty($model->value)) { $args = json_decode($model->value,true); } else { $args = []; } } return $this->renderAjax($view,array('model'=>$model,'args'=>$args)); } //删除 public function actionDel() { $id = $this->getKeyId(); $model = Sysconfig::findOne($id); check_record_exists($model); if($model->delete()) { $msgdata = ['error' => 0,'msg' => '操作成功!']; } else { $msgdata = ['error' => 1,'msg' => '操作失败!']; } echo_json($msgdata); } }