新增模块管理

This commit is contained in:
JaguarJack 2020-09-12 17:22:43 +08:00
parent dc4855f5c1
commit ee624300b6
4 changed files with 74 additions and 6 deletions

View File

@ -11,6 +11,8 @@
namespace catchAdmin\system; namespace catchAdmin\system;
use catchAdmin\system\events\AttachmentEvent; use catchAdmin\system\events\AttachmentEvent;
use catcher\command\MigrateRunCommand;
use catcher\command\SeedRunCommand;
use catcher\ModuleService; use catcher\ModuleService;
class SystemService extends ModuleService class SystemService extends ModuleService
@ -28,4 +30,12 @@ class SystemService extends ModuleService
'attachment' => [ AttachmentEvent::class ], 'attachment' => [ AttachmentEvent::class ],
]; ];
} }
protected function registerCommands()
{
$this->commands([
MigrateRunCommand::class,
SeedRunCommand::class,
]);
}
} }

View File

@ -0,0 +1,52 @@
<?php
namespace catchAdmin\system\controller;
use catcher\base\CatchController;
use catcher\CatchResponse;
use catcher\CatchAdmin;
use catcher\library\InstallCatchModule;
use catcher\library\InstallLocalModule;
class Module extends CatchController
{
/**
* 模块列表
*
* @return void
*/
public function index()
{
# code...
$modules = [];
foreach(CatchAdmin::getModulesDirectory() as $d) {
$modules[] = json_decode(file_get_contents($d . 'module.json'), true);
}
array_multisort(array_column($modules, 'order'), SORT_DESC, $modules);
return CatchResponse::success($modules);
}
/**
* 禁用/启用模块
*
* @param string $module
* @return void
*/
public function disOrEnable($module)
{
# code...
$moduleInfo = CatchAdmin::getModuleInfo(CatchAdmin::directory() . $module);
$install = new InstallLocalModule($module);
if (!$moduleInfo['enable']) {
$install->findModuleInPermissions() ? $install->enableModule() : $install->done();
} else {
$install->disableModule();
}
return CatchResponse::success();
}
}

View File

@ -31,9 +31,15 @@ $router->group(function () use ($router) {
// 敏感词 // 敏感词
$router->resource('sensitive/word', '\catchAdmin\system\controller\SensitiveWord'); $router->resource('sensitive/word', '\catchAdmin\system\controller\SensitiveWord');
//developer路由
$router->resource('developer', '\catchAdmin\system\controller\Developer')->middleware('auth');
// 开发者认证
$router->post('developer/authenticate', '\catchAdmin\system\controller\Developer@authenticate');
// 模块管理
$router->get('modules', '\catchAdmin\system\controller\Module@index');
$router->put('modules/<module>', '\catchAdmin\system\controller\Module@disOrEnable');
})->middleware('auth'); })->middleware('auth');
//developer路由
$router->resource('developer', '\catchAdmin\system\controller\Developer')->middleware('auth');
// 开发者认证
$router->post('developer/authenticate', '\catchAdmin\system\controller\Developer@authenticate');

View File

@ -110,9 +110,9 @@ class InstallLocalModule
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @return bool * @return bool
*/ */
protected function findModuleInPermissions() public function findModuleInPermissions()
{ {
return Permissions::where('module', $this->module)->find() ? true : false; return Permissions::withTrashed()->where('module', $this->module)->find() ? true : false;
} }
/** /**