初始化

This commit is contained in:
2026-03-09 17:35:53 +08:00
commit 74f322b7c2
577 changed files with 57404 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace app\common\middleware;
use Closure;
use Throwable;
use think\facade\Config;
use app\admin\model\AdminLog as AdminLogModel;
class AdminLog
{
/**
* 写入管理日志
* @throws Throwable
*/
public function handle($request, Closure $next)
{
$response = $next($request);
if (($request->isPost() || $request->isDelete()) && Config::get('buildadmin.auto_write_admin_log')) {
AdminLogModel::instance()->record();
}
return $response;
}
}

View File

@@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\middleware;
use Closure;
use think\Request;
use think\Response;
use think\facade\Config;
/**
* 跨域请求支持
* 安全起见,只支持了配置中的域名
*/
class AllowCrossDomain
{
protected array $header = [
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => 1800,
'Access-Control-Allow-Methods' => '*',
'Access-Control-Allow-Headers' => '*',
];
/**
* 跨域请求检测
* @access public
* @param Request $request
* @param Closure $next
* @param array|null $header
* @return Response
*/
public function handle(Request $request, Closure $next, ?array $header = []): Response
{
$header = !empty($header) ? array_merge($this->header, $header) : $this->header;
$origin = $request->header('origin');
if ($origin && !isset($header['Access-Control-Allow-Origin'])) {
$info = parse_url($origin);
// 获取跨域配置
$corsDomain = explode(',', Config::get('buildadmin.cors_request_domain'));
$corsDomain[] = $request->host(true);
if (in_array("*", $corsDomain) || in_array($origin, $corsDomain) || (isset($info['host']) && in_array($info['host'], $corsDomain))) {
$header['Access-Control-Allow-Origin'] = $origin;
}
}
if ($request->isOptions()) {
return response('', 204, $header);
}
$request->allowCrossDomainHeaders = $header;
return $next($request)->header($header);
}
}