_childMenu($menu); } private function _childMenu($parentArray){ $menuResult = []; foreach($parentArray as $key => $parentMenu){ // 菜单是否显示 if(isset($parentMenu['show']) && !$parentMenu['show']){ continue; } // 子菜单同样设置 if(isset($parentMenu['child']) && !empty($parentMenu['child'])){ $parentMenu['child'] = $this->_childMenu($parentMenu['child']); } $menuResult[] = $parentMenu; } return $menuResult; } // "visible":true, 是否在菜单可见 // "icon":"ri-computer-line", 图标 // "schemaApi":"/page/home", 拉取页面的地址 // "label":"控制台", 显示的名字 // "leaf":true, 是否有子数据 // "url":"home" 浏览器的url private function _testMenu($parentArray){ $menuResult = []; foreach($parentArray as $key => $parentMenu){ $temp = []; $hasSon = isset($parentMenu['child']) && !empty($parentMenu['child']) ? true : false; $temp['visible'] = isset($parentMenu['show']) && $parentMenu['show']=="1" ? true : false; $temp['icon'] = isset($parentMenu['icon']) ? $parentMenu['icon'] : ""; $temp['label'] = $parentMenu['name']; $temp['leaf'] = $hasSon;// 是否有子节点 if (!$hasSon) { $temp['url'] = "/".$parentMenu['routePath']; // 浏览器上展示的前端路由 $temp['schemaApi'] = isset($parentMenu['schemaApi']) ? $parentMenu['schemaApi'] : "/page/aa"; // 获取页面的请求.之前没有,之前是请求的后端api请求 }else { if (strpos($parentMenu['routePath'], "/") !== false) { // 如果包含/ , 表示需要展示到页面上 $temp['schemaApi'] = isset($parentMenu['schemaApi']) ? $parentMenu['schemaApi'] : "/page/aa"; // 获取页面的请求.之前没有,之前是请求的后端api请求 } } if(isset($parentMenu['child']) && !empty($parentMenu['child'])){ $temp['children'] = $this->_testMenu($parentMenu['child']); } $menuResult[] = $temp; } return $menuResult; } public function actionTestmenu(){ $menu = require Yii::getAlias('@backendApi/config/menu.php'); $menu = $this->_testMenu($menu); $children = [ 'children' => $menu ]; $pages = [ 'pages' => $children ]; $ret = [ 'msg' => 'success', 'data' => $pages, 'status' => 0 ]; return static::notice($ret); } // 获取页面 public function actionPage(){ $request = Yii::$app->request; $sqlCode = $request->get('code', ''); $pageInfo = PageDetails::getInfoByCode($sqlCode); $a = [ $pageInfo['page_json'] ]; Yii::$app->response->format = Response::FORMAT_HTML; return $pageInfo['page_json']; } public function actionInfo(){ $userInfo = User::find()->where(['ID'=>Yii::$app->user->id])->asArray()->one(); unset($userInfo['PASSWORD_HASH'], $userInfo['PASSWORD_RESET_TOKEN'], $userInfo['AUTH_KEY']); return static::notice($userInfo); } /** * 登录 * @return mixed * @throws HttpException * @throws \yii\base\Exception */ public function actionLogin() { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { $token = Yii::$app->getUser()->getToken(); return static::notice($token); } else { $firstError = $model->getFirstError('LoginForm'); if( $firstError === LoginForm::ERROR_IS_MODIFY_PASSWORD ) { return static::notice(LoginForm::ERROR_IS_MODIFY_PASSWORD, 403); } return static::notice(Form::formatErrorsForApi($model->getErrors()), 401); } } public function actionNoLoginModifyPassword() { $form = new AdminForm(); $form->scenario = 'noLoginModifyPassword'; if(Yii::$app->request->isPost && $form->load(Yii::$app->request->post(), '') && $result = $form->edit()){ // Log::adminHandle('管理员'.$result->ADMIN_NAME.'重置密码'); return static::notice('重置密码成功'); } else { return static::notice(Form::formatErrorsForApi($form->getErrors()), 400); } } /** * 用refreshToken刷新accessToken和refreshToken * @return mixed * @throws HttpException */ public function actionRefreshToken(){ $refreshToken = Yii::$app->request->get('refresh-token'); Yii::$app->user->refreshToken($refreshToken); $token = Yii::$app->getUser()->getToken(); if($token){ return static::notice($token); } else { return static::notice('更新Token失败', 401); } } /** * 用refreshToken刷新accessToken * @return mixed * @throws HttpException */ public function actionRefreshAccessToken(){ $refreshToken = Yii::$app->request->get('refresh-token'); Yii::$app->user->refreshAccessToken($refreshToken); $token = Yii::$app->getUser()->getToken(); if($token){ return static::notice($token); } else { return static::notice('更新Token失败', 401); } } /** * 用refreshToken刷新refreshToken * @return mixed * @throws HttpException */ public function actionRefreshRefreshToken(){ $refreshToken = Yii::$app->request->get('refresh-token'); Yii::$app->user->refreshRefreshToken($refreshToken); $token = Yii::$app->getUser()->getToken(); if($token){ return static::notice($token); } else { return static::notice('更新Token失败', 401); } } public function actionTest(){ return static::notice(['test'=>Yii::$app->getUser()->id]); } }