jqh 4 years ago
parent
commit
75b8cc7856
3 changed files with 12 additions and 80 deletions
  1. 2 70
      src/Application.php
  2. 6 10
      src/Http/Controllers/AuthController.php
  3. 4 0
      src/Support/Helper.php

+ 2 - 70
src/Application.php

@@ -46,19 +46,11 @@ class Application
         return $this->apps ?: ($this->apps = (array) config('admin.multi_app'));
     }
 
-    /**
-     * 获取已经启用的 app 列表
-     */
-    public function enableApps()
+    public function getEnabledApps()
     {
-        return array_filter($this->apps);
+        return array_filter($this->getApps());
     }
 
-    /**
-     * 设置当前应用配置.
-     *
-     * @param string $app
-     */
     public function switch(string $app = null)
     {
         $this->withName($app);
@@ -66,29 +58,16 @@ class Application
         $this->withConfig($this->name);
     }
 
-    /**
-     * 设置应用名称.
-     *
-     * @param string $app
-     */
     public function withName(string $app)
     {
         $this->name = $app;
     }
 
-    /**
-     * 获取当前应用名称.
-     *
-     * @return string
-     */
     public function getName()
     {
         return $this->name ?: static::DEFAULT;
     }
 
-    /**
-     * 注册应用.
-     */
     public function boot()
     {
         $this->registerRoute(static::DEFAULT);
@@ -100,11 +79,6 @@ class Application
         }
     }
 
-    /**
-     * 注册路由.
-     *
-     * @param string|\Closure $pathOrCallback
-     */
     public function routes($pathOrCallback)
     {
         $this->loadRoutesFrom($pathOrCallback, static::DEFAULT);
@@ -131,31 +105,16 @@ class Application
         }
     }
 
-    /**
-     * @return string
-     */
     public function getCurrentApiRoutePrefix()
     {
         return $this->getApiRoutePrefix($this->getName());
     }
 
-    /**
-     * @param string|null $app
-     *
-     * @return string
-     */
     public function getApiRoutePrefix(?string $app = null)
     {
         return $this->getRoutePrefix($app).'dcat-api.';
     }
 
-    /**
-     * 获取路由别名前缀.
-     *
-     * @param string|null $app
-     *
-     * @return string
-     */
     public function getRoutePrefix(?string $app = null)
     {
         $app = $app ?: $this->getName();
@@ -163,25 +122,11 @@ class Application
         return 'dcat.'.$app.'.';
     }
 
-    /**
-     * 获取路由别名.
-     *
-     * @param string|null $route
-     * @param array $params
-     * @param bool $absolute
-     *
-     * @return string
-     */
     public function getRoute(?string $route, array $params = [], $absolute = true)
     {
         return route($this->getRoutePrefix().$route, $params, $absolute);
     }
 
-    /**
-     * 注册应用路由.
-     *
-     * @param string|null $app
-     */
     protected function registerRoute(?string $app)
     {
         $this->switch($app);
@@ -195,11 +140,6 @@ class Application
         }
     }
 
-    /**
-     * 设置应用配置.
-     *
-     * @param string $app
-     */
     protected function withConfig(string $app)
     {
         if (! isset($this->configs[$app])) {
@@ -209,14 +149,6 @@ class Application
         config(['admin' => $this->configs[$app]]);
     }
 
-    /**
-     * 加载路由文件.
-     *
-     * @param  string  $path
-     * @param  string  $app
-     *
-     * @return void
-     */
     protected function loadRoutesFrom($path, ?string $app)
     {
         Route::group(array_filter([

+ 6 - 10
src/Http/Controllers/AuthController.php

@@ -242,17 +242,13 @@ class AuthController extends Controller
     {
         $request->session()->regenerate();
 
-        $response = $this->response()
-            ->success(trans('admin.login_successful'))
-            ->locationToIntended($this->getRedirectPath());
-
-        // 如果当前启用了多应用后台,
-        // 不要跳去 session 存储的 path
-        if (! empty(Admin::app()->enableApps())) {
-            $response->location($this->getRedirectPath());
-        }
+        $path = $this->getRedirectPath();
 
-        return $response->send();
+        return $this->response()
+            ->success(trans('admin.login_successful'))
+            ->locationToIntended($path)
+            ->locationIf(Admin::app()->getEnabledApps(), $path)
+            ->send();
     }
 
     /**

+ 4 - 0
src/Support/Helper.php

@@ -97,6 +97,10 @@ class Helper
             $value = $value(...(array) $params);
         }
 
+        if ($value instanceof Grid) {
+            return (string) $value->render();
+        }
+
         if ($value instanceof Renderable) {
             return (string) $value->render();
         }