feat: 分离前端列表

This commit is contained in:
JaguarJack
2022-12-06 19:27:38 +08:00
parent 0024080c28
commit 727e887729
38 changed files with 552 additions and 146 deletions

View File

@@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Catch\Base;
use Catch\Enums\Code;
use Catch\Exceptions\FailedException;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
@@ -29,6 +31,12 @@ abstract class CatchController extends Controller
*/
protected function getLoginUser($guard = null): Authenticatable
{
return Auth::guard($guard ?: getGuardName())->user();
$user = Auth::guard($guard ?: getGuardName())->user();
if (! $user) {
throw new FailedException('登录失效, 请重新登录', Code::LOST_LOGIN);
}
return $user;
}
}

View File

@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Catch;
use Catch\Support\Module\Installer;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
@@ -360,4 +361,20 @@ class CatchAdmin
{
return Str::replaceFirst(base_path(), '.', $path);
}
/**
*
* @param string $module
* @return Installer
*/
public static function getModuleInstaller(string $module): Installer
{
$installer = self::getModuleServiceProviderNamespace($module).'Installer';
if (class_exists($installer)) {
return app($installer);
}
throw new \RuntimeException("Installer [$installer] Not Found");
}
}

View File

@@ -51,7 +51,7 @@ abstract class CatchCommand extends Command
protected function initialize(InputInterface $input, OutputInterface $output): void
{
if ($input->hasArgument('module')
&& ! Module::all()->pluck('name')->merge(Collection::make(config('catch.module.default')))->contains(lcfirst($input->getArgument('module')))
&& ! Module::getEnabled()->pluck('name')->merge(Collection::make(config('catch.module.default')))->contains(lcfirst($input->getArgument('module')))
) {
$this->error(sprintf('Module [%s] Not Found', $input->getArgument('module')));
exit;

View File

@@ -6,6 +6,7 @@ use Catch\Enums\Code;
use Catch\Events\User as UserEvent;
use Catch\Exceptions\FailedException;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
@@ -20,11 +21,13 @@ class AuthMiddleware
try {
$guardName = getGuardName();
if (Auth::guard($guardName)->check()) {
$user = Auth::guard($guardName)->user();
Event::dispatch(new UserEvent($user));
if (! $user = Auth::guard($guardName)->user()) {
throw new AuthenticationException();
}
Event::dispatch(new UserEvent($user));
return $next($request);
} catch (Exception|Throwable $e) {
if ($e instanceof TokenExpiredException) {
throw new FailedException(Code::LOGIN_EXPIRED->message(), Code::LOGIN_EXPIRED);
@@ -35,8 +38,6 @@ class AuthMiddleware
}
throw new FailedException(Code::LOST_LOGIN->message().":{$e->getMessage()}", Code::LOST_LOGIN);
} finally {
return $next($request);
}
}
}

View File

@@ -185,8 +185,8 @@ class CatchAdminServiceProvider extends ServiceProvider
protected function bootModuleProviders()
{
foreach ($this->app->make(ModuleRepositoryInterface::class)->getEnabled() as $module) {
if (class_exists($module['service'])) {
$this->app->register($module['service']);
if (class_exists($module['provider'])) {
$this->app->register($module['provider']);
}
}
}

View File

@@ -64,7 +64,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
'path' => $module['path'],
'description' => $module['desc'],
'keywords' => $module['keywords'],
'service' => sprintf('\\%s%s', CatchAdmin::getModuleNamespace($module['name']), ucfirst($module['name']).'ServiceProvider'),
'provider' => sprintf('\\%s%s', CatchAdmin::getModuleNamespace($module['name']), ucfirst($module['name']).'ServiceProvider'),
]);
}
@@ -92,7 +92,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
->update([
'name' => $module['name'],
'alias' => $module['alias'],
'path' => $module['path'],
'description' => $module['desc'],
'keywords' => $module['keywords'],
]);
@@ -146,7 +146,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
throw new FailedException(sprintf('Module [%s] has been created', $module['name']));
}
if ($this->model->where('alias', $module['alias'])->first()) {
if ($this->model->where('path', $module['path'])->first()) {
throw new FailedException(sprintf('Module Alias [%s] has been exised', $module['alias']));
}
}

View File

@@ -78,7 +78,7 @@ class FileDriver implements ModuleRepositoryInterface
$this->hasSameModule($module, $modules);
$module['service'] = sprintf('\\%s', CatchAdmin::getModuleServiceProvider($module['path']));
$module['provider'] = sprintf('\\%s', CatchAdmin::getModuleServiceProvider($module['path']));
$module['version'] = '1.0.0';
$module['enable'] = true;

View File

@@ -73,7 +73,7 @@ abstract class Installer
*
* @return void
*/
public function __invoke(): void
public function install(): void
{
// TODO: Implement __invoke() method.
$this->moduleRepository->create($this->info());

View File

@@ -23,6 +23,10 @@ use Illuminate\Support\Facades\Request;
*/
trait BaseOperate
{
protected string $sortField = 'sort';
protected bool $sortDesc = true;
/**
*
*
@@ -46,10 +50,18 @@ trait BaseOperate
{
$queryBuilder = self::query()->select($this->fieldsInList)->quickSearch();
if (in_array($this->sortField, $this->getFillable())) {
$queryBuilder = $queryBuilder->orderBy($this->sortField, $this->sortDesc ? 'desc' : 'asc');
}
$queryBuilder = $queryBuilder->orderByDesc('id');
if ($this->isPaginate) {
return $queryBuilder->paginate(Request::get('limit', $this->perPage));
}
return $queryBuilder->get();
}