webman迁移
This commit is contained in:
@@ -32,13 +32,19 @@ class Index extends Backend
|
||||
return $this->error(__('No background menu, please contact super administrator!'));
|
||||
}
|
||||
|
||||
$apiUrl = config('buildadmin.api_url');
|
||||
if (!$apiUrl || $apiUrl === 'https://api.buildadmin.com') {
|
||||
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$apiUrl = $scheme . '://' . $request->host();
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'adminInfo' => $adminInfo,
|
||||
'menus' => $menus,
|
||||
'siteConfig' => [
|
||||
'siteName' => get_sys_config('site_name'),
|
||||
'version' => get_sys_config('version'),
|
||||
'apiUrl' => config('buildadmin.api_url'),
|
||||
'apiUrl' => $apiUrl,
|
||||
'upload' => keys_to_camel_case(get_upload_config($request), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types']),
|
||||
'cdnUrl' => full_url(),
|
||||
'cdnUrlParams' => config('buildadmin.cdn_url_params'),
|
||||
|
||||
@@ -25,9 +25,10 @@ class Admin extends Backend
|
||||
|
||||
protected string $dataLimitField = 'id';
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminModel();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
@@ -262,11 +263,11 @@ class Admin extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉(Admin 无自定义,返回 null 走默认列表)
|
||||
* 远程下拉(Admin 无自定义,走父类默认列表)
|
||||
*/
|
||||
protected function select(Request $request): ?Response
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
return null;
|
||||
return parent::select($request);
|
||||
}
|
||||
|
||||
private function checkGroupAuth(array $groups): ?Response
|
||||
|
||||
@@ -18,9 +18,10 @@ class AdminLog extends Backend
|
||||
|
||||
protected string|array $quickSearchField = ['title'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminLogModel();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
@@ -52,10 +53,10 @@ class AdminLog extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉(AdminLog 无自定义,返回 null 走默认列表)
|
||||
* 远程下拉(AdminLog 无自定义,走父类默认列表)
|
||||
*/
|
||||
protected function select(Request $request): ?Response
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
return null;
|
||||
return parent::select($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class Group extends Backend
|
||||
|
||||
protected array $adminGroups = [];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminGroup();
|
||||
$this->tree = Tree::instance();
|
||||
@@ -48,6 +48,7 @@ class Group extends Backend
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
|
||||
$this->adminGroups = Db::name('admin_group_access')->where('uid', $this->auth->id)->column('group_id');
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -34,7 +34,7 @@ class Rule extends Backend
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminRule();
|
||||
$this->tree = Tree::instance();
|
||||
@@ -43,6 +43,7 @@ class Rule extends Backend
|
||||
$this->initValue = is_array($this->initValue) ? array_filter($this->initValue) : [];
|
||||
$this->keyword = $request->get('quickSearch') ?? $request->post('quickSearch') ?? '';
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -16,10 +16,11 @@ class AdminInfo extends Backend
|
||||
protected array|string $preExcludeFields = ['username', 'last_login_time', 'password', 'salt', 'status'];
|
||||
protected array $authAllowFields = ['id', 'username', 'nickname', 'avatar', 'email', 'mobile', 'motto', 'last_login_time'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->auth->setAllowFields($this->authAllowFields);
|
||||
$this->model = $this->auth->getAdmin();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -17,9 +17,10 @@ class Attachment extends Backend
|
||||
protected array $withJoinTable = ['admin', 'user'];
|
||||
protected array|string $defaultSortField = ['last_upload_time' => 'desc'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AttachmentModel();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function del(Request $request): Response
|
||||
|
||||
@@ -23,9 +23,10 @@ class Config extends Backend
|
||||
'backendEntranceStub' => 'app/admin/library/stubs/backendEntrance.stub',
|
||||
];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new ConfigModel();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -18,9 +18,10 @@ class Group extends Backend
|
||||
protected array|string $preExcludeFields = ['update_time', 'create_time'];
|
||||
protected array|string $quickSearchField = 'name';
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new UserGroup();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function add(Request $request): Response
|
||||
|
||||
@@ -18,9 +18,10 @@ class MoneyLog extends Backend
|
||||
protected array|string $preExcludeFields = ['create_time'];
|
||||
protected array|string $quickSearchField = ['user.username', 'user.nickname'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new UserMoneyLog();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function add(Request $request): Response
|
||||
|
||||
@@ -22,7 +22,7 @@ class Rule extends Backend
|
||||
protected array|string $defaultSortField = ['weigh' => 'desc'];
|
||||
protected array|string $quickSearchField = 'title';
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new UserRule();
|
||||
$this->tree = Tree::instance();
|
||||
@@ -31,6 +31,7 @@ class Rule extends Backend
|
||||
$this->initValue = is_array($this->initValue) ? array_filter($this->initValue) : [];
|
||||
$this->keyword = $request->get('quickSearch', $request->post('quickSearch', ''));
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -18,9 +18,10 @@ class ScoreLog extends Backend
|
||||
protected array|string $preExcludeFields = ['create_time'];
|
||||
protected array|string $quickSearchField = ['user.username', 'user.nickname'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new UserScoreLog();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function add(Request $request): Response
|
||||
|
||||
@@ -18,9 +18,10 @@ class User extends Backend
|
||||
protected array|string $preExcludeFields = ['last_login_time', 'login_failure', 'password', 'salt'];
|
||||
protected array|string $quickSearchField = ['username', 'nickname', 'id'];
|
||||
|
||||
protected function initController(Request $request): void
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new UserModel();
|
||||
return null;
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
|
||||
@@ -21,6 +21,38 @@ class AllowCrossDomain implements MiddlewareInterface
|
||||
'Access-Control-Allow-Headers' => '*',
|
||||
];
|
||||
|
||||
/**
|
||||
* 返回 CORS 预检(OPTIONS)响应,供路由直接调用(Webman 未匹配路由时不走中间件)
|
||||
*/
|
||||
public static function optionsResponse(Request $request): Response
|
||||
{
|
||||
$header = [
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => '1800',
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
||||
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, batoken, ba-user-token, think-lang',
|
||||
];
|
||||
$origin = $request->header('origin');
|
||||
if (is_array($origin)) {
|
||||
$origin = $origin[0] ?? '';
|
||||
}
|
||||
$origin = is_string($origin) ? trim($origin) : '';
|
||||
if ($origin !== '') {
|
||||
$info = parse_url($origin);
|
||||
$host = $info['host'] ?? '';
|
||||
$corsDomain = array_map('trim', explode(',', config('buildadmin.cors_request_domain', '')));
|
||||
$corsDomain[] = $request->host(true);
|
||||
$allowed = in_array('*', $corsDomain)
|
||||
|| in_array($origin, $corsDomain)
|
||||
|| in_array($host, $corsDomain)
|
||||
|| ($host === 'localhost' || $host === '127.0.0.1');
|
||||
if ($allowed) {
|
||||
$header['Access-Control-Allow-Origin'] = $origin;
|
||||
}
|
||||
}
|
||||
return response('', 204, $header);
|
||||
}
|
||||
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$path = trim($request->path(), '/');
|
||||
@@ -31,16 +63,23 @@ class AllowCrossDomain implements MiddlewareInterface
|
||||
$header = $this->header;
|
||||
|
||||
$origin = $request->header('origin');
|
||||
if ($origin) {
|
||||
if (is_array($origin)) {
|
||||
$origin = $origin[0] ?? '';
|
||||
}
|
||||
$origin = is_string($origin) ? trim($origin) : '';
|
||||
|
||||
if ($origin !== '') {
|
||||
$info = parse_url($origin);
|
||||
$corsDomain = explode(',', config('buildadmin.cors_request_domain', ''));
|
||||
$host = $info['host'] ?? '';
|
||||
$corsDomain = array_map('trim', explode(',', config('buildadmin.cors_request_domain', '')));
|
||||
$corsDomain[] = $request->host(true);
|
||||
|
||||
if (
|
||||
in_array('*', $corsDomain)
|
||||
$allowed = in_array('*', $corsDomain)
|
||||
|| in_array($origin, $corsDomain)
|
||||
|| (isset($info['host']) && in_array($info['host'], $corsDomain))
|
||||
) {
|
||||
|| in_array($host, $corsDomain)
|
||||
|| ($host === 'localhost' || $host === '127.0.0.1');
|
||||
|
||||
if ($allowed) {
|
||||
$header['Access-Control-Allow-Origin'] = $origin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,37 @@
|
||||
namespace app\process;
|
||||
|
||||
use Webman\App;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class Http extends App
|
||||
{
|
||||
|
||||
/**
|
||||
* 在父类处理前拦截 OPTIONS 预检,直接返回 CORS 头(避免预检未命中路由时无 CORS)
|
||||
*/
|
||||
public function onMessage($connection, $request): void
|
||||
{
|
||||
$method = $request->method();
|
||||
if (is_string($method) && strtoupper($method) === 'OPTIONS') {
|
||||
$path = $request->path();
|
||||
$path = is_string($path) ? trim($path, '/') : '';
|
||||
$isApiOrAdmin = $path !== '' && (str_starts_with($path, 'api') || str_starts_with($path, 'admin'));
|
||||
if ($isApiOrAdmin) {
|
||||
$origin = $request->header('origin');
|
||||
$origin = is_array($origin) ? ($origin[0] ?? '') : (is_string($origin) ? trim($origin) : '');
|
||||
if ($origin === '') {
|
||||
$origin = '*';
|
||||
}
|
||||
$headers = [
|
||||
'Access-Control-Allow-Origin' => $origin,
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => '1800',
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
||||
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, batoken, ba-user-token, think-lang',
|
||||
];
|
||||
$connection->send(new Response(204, $headers, ''));
|
||||
return;
|
||||
}
|
||||
}
|
||||
parent::onMessage($connection, $request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user