新增模块管理
This commit is contained in:
parent
dc4855f5c1
commit
ee624300b6
@ -11,6 +11,8 @@
|
||||
namespace catchAdmin\system;
|
||||
|
||||
use catchAdmin\system\events\AttachmentEvent;
|
||||
use catcher\command\MigrateRunCommand;
|
||||
use catcher\command\SeedRunCommand;
|
||||
use catcher\ModuleService;
|
||||
|
||||
class SystemService extends ModuleService
|
||||
@ -28,4 +30,12 @@ class SystemService extends ModuleService
|
||||
'attachment' => [ AttachmentEvent::class ],
|
||||
];
|
||||
}
|
||||
|
||||
protected function registerCommands()
|
||||
{
|
||||
$this->commands([
|
||||
MigrateRunCommand::class,
|
||||
SeedRunCommand::class,
|
||||
]);
|
||||
}
|
||||
}
|
52
catch/system/controller/Module.php
Normal file
52
catch/system/controller/Module.php
Normal 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();
|
||||
}
|
||||
}
|
@ -31,9 +31,15 @@ $router->group(function () use ($router) {
|
||||
|
||||
// 敏感词
|
||||
$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');
|
||||
|
||||
//developer路由
|
||||
$router->resource('developer', '\catchAdmin\system\controller\Developer')->middleware('auth');
|
||||
// 开发者认证
|
||||
$router->post('developer/authenticate', '\catchAdmin\system\controller\Developer@authenticate');
|
||||
|
||||
|
@ -110,9 +110,9 @@ class InstallLocalModule
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user