mirror of
http://124.126.16.154:8888/singularity/hyperf-admin.git
synced 2026-01-15 05:35:08 +08:00
perf: add remote scaffold
This commit is contained in:
@@ -60,7 +60,7 @@ class MenuController extends AdminAbstractController
|
||||
'when' => ['=', 1],
|
||||
'set' => [
|
||||
'path' => [
|
||||
'rule' => 'required',
|
||||
'rule' => 'requir渲染方式ed',
|
||||
],
|
||||
'label' => [
|
||||
'title' => '菜单标题',
|
||||
@@ -148,6 +148,7 @@ class MenuController extends AdminAbstractController
|
||||
'options' => [
|
||||
1 => '脚手架',
|
||||
0 => '自定义',
|
||||
2 => '配置化脚手架',
|
||||
],
|
||||
'default' => 1,
|
||||
'col' => [
|
||||
@@ -162,6 +163,13 @@ class MenuController extends AdminAbstractController
|
||||
],
|
||||
],
|
||||
],
|
||||
'config|脚手架配置' => [
|
||||
"type" => 'json',
|
||||
'depend' => [
|
||||
'field' => 'is_scaffold',
|
||||
'value' => 2
|
||||
]
|
||||
],
|
||||
'view|组件路径' => [
|
||||
'rule' => 'string|max:50',
|
||||
'default' => '',
|
||||
@@ -395,7 +403,9 @@ class MenuController extends AdminAbstractController
|
||||
$data['path'] = '#';
|
||||
}
|
||||
$data['is_menu'] = $data['type'] == 2 ? 0 : $data['is_menu'];
|
||||
$data['permission'] = implode(',', $data['permission'] ?? []);
|
||||
if ($data['permission']) {
|
||||
$data['permission'] = implode(',', $data['permission'] ?? []);
|
||||
}
|
||||
$pid = array_pop($data['pid']);
|
||||
if ($pid == $id) {
|
||||
$pid = array_pop($data['pid']);
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
namespace HyperfAdmin\Admin\Controller;
|
||||
|
||||
use Hyperf\Utils\Str;
|
||||
use HyperfAdmin\Admin\Model\FrontRoutes;
|
||||
use HyperfAdmin\Admin\Service\CommonConfig;
|
||||
use HyperfAdmin\Admin\Service\ModuleProxy;
|
||||
use HyperfAdmin\BaseUtils\Constants\ErrorCode;
|
||||
use HyperfAdmin\BaseUtils\Guzzle;
|
||||
|
||||
class SystemController extends AdminAbstractController
|
||||
{
|
||||
@@ -40,4 +43,81 @@ class SystemController extends AdminAbstractController
|
||||
});
|
||||
return $this->success(array_values($routes));
|
||||
}
|
||||
|
||||
public function listInfo(int $id)
|
||||
{
|
||||
$config = FrontRoutes::query()->find($id)->getAttributeValue("config");
|
||||
$this->options = $config;
|
||||
return $this->info();
|
||||
}
|
||||
|
||||
public function listDetail(int $id)
|
||||
{
|
||||
$config = FrontRoutes::query()->find($id)->getAttributeValue("config");
|
||||
$listApi = $config['listApi'] ?? '';
|
||||
if (!$listApi) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '脚手架配置错误, 缺少列表接口');
|
||||
}
|
||||
try {
|
||||
return Guzzle::proxy($listApi, $this->request);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '外部接口转发失败 ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function formInfo($route_id, $id)
|
||||
{
|
||||
$config = FrontRoutes::query()->find($route_id)->getAttributeValue("config");
|
||||
try {
|
||||
$this->options = $config;
|
||||
$form = $this->form();
|
||||
if ($id) {
|
||||
// todo token or aksk
|
||||
$getApi = str_var_replace($config['getApi'] ?? '', ['id' => $id]);
|
||||
$result = Guzzle::proxy($getApi, $this->request);
|
||||
if ($result['code'] !== 0) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '外部接口转发失败 ' . $result['message'] ?? '');
|
||||
}
|
||||
foreach ($form['payload']['form'] as &$item) {
|
||||
$item['value'] = $result['payload'][$item['field']] ?? null;
|
||||
unset($item);
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '外部接口转发失败 ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function formSave($route_id, $id)
|
||||
{
|
||||
$config = FrontRoutes::query()->find($route_id)->getAttributeValue("config");
|
||||
$saveApi = str_var_replace($config['saveApi'] ?? '', ['id' => $id]);
|
||||
if (!$saveApi) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '脚手架配置错误, 缺少列表接口');
|
||||
}
|
||||
try {
|
||||
return Guzzle::post($saveApi, $this->request);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '外部接口转发失败 ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
}
|
||||
|
||||
public function proxy()
|
||||
{
|
||||
$proxyUrl = $this->request->query('proxy_url');
|
||||
|
||||
if (!$proxyUrl) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '脚手架配置错误, 缺少列表接口');
|
||||
}
|
||||
try {
|
||||
return Guzzle::proxy($proxyUrl, $this->request);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail(ErrorCode::CODE_ERR_SYSTEM, '外部接口转发失败 ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class UpdateCommand extends HyperfCommand
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$version = $input->getArgument('version');
|
||||
$version = $this->input->getArgument('version');
|
||||
$db_conf = config('databases.hyperf_admin');
|
||||
if (!$db_conf || !$db_conf['host']) {
|
||||
$this->output->error('place set hyperf_admin db config in env');
|
||||
|
||||
@@ -54,8 +54,9 @@ CREATE TABLE `front_routes` (
|
||||
`type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '菜单类型 0 目录 1 菜单 2 其他',
|
||||
`page_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '页面类型: 0 列表 1 表单',
|
||||
`scaffold_action` varchar(255) NOT NULL DEFAULT '' COMMENT '脚手架预置权限',
|
||||
`config` text COMMENT '配置化脚手架',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8mb4 COMMENT='前端路由(菜单)';;
|
||||
|
||||
CREATE TABLE `global_config` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -37,6 +37,7 @@ class FrontRoutes extends BaseModel
|
||||
'permission',
|
||||
'http_method',
|
||||
'page_type',
|
||||
'config'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -48,6 +49,7 @@ class FrontRoutes extends BaseModel
|
||||
'is_scaffold' => 'integer',
|
||||
'page_type' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'config' => 'json',
|
||||
];
|
||||
|
||||
const HTTP_METHOD_ANY = 0;
|
||||
|
||||
@@ -39,3 +39,9 @@ register_route('/cconf', CommonConfigController::class, function ($controller) {
|
||||
|
||||
Router::get('/system/config', [SystemController::class, 'config']);
|
||||
Router::get('/system/routes', [SystemController::class, 'routes']);
|
||||
Router::get('/system/proxy', [SystemController::class, 'proxy']);
|
||||
Router::get('/system/list_info/{id:\d+}', [SystemController::class, 'listInfo']);
|
||||
Router::get('/system/list/{id:\d+}', [SystemController::class, 'listDetail']);
|
||||
Router::get('/system/form/{route_id:\d+}/form', [SystemController::class, 'formInfo']);
|
||||
Router::get('/system/form/{route_id:\d+}/{id:\d+}', [SystemController::class, 'formInfo']);
|
||||
Router::post('/system/form/{route_id:\d+}/{id:\d+}', [SystemController::class, 'formSave']);
|
||||
|
||||
@@ -107,7 +107,6 @@ class ConfigProvider
|
||||
'exceptions' => [
|
||||
'handler' => [
|
||||
'http' => [
|
||||
HyperfHttpExceptionHandler::class,
|
||||
HttpExceptionHandler::class,
|
||||
],
|
||||
],
|
||||
|
||||
@@ -39,6 +39,9 @@ class CrontabDispatcherProcess extends ProcessCrontabDispatcherProcess
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (!config('cron_center.enable', false)) {
|
||||
return;
|
||||
}
|
||||
$this->event->dispatch(new CrontabDispatcherStarted());
|
||||
while (true) {
|
||||
$this->cron_manager->createOrUpdateNode();
|
||||
|
||||
Reference in New Issue
Block a user