作者 lyh

gx

@@ -64,6 +64,8 @@ class Kernel extends HttpKernel @@ -64,6 +64,8 @@ class Kernel extends HttpKernel
64 PreventRepeatQuitCallMiddleware::class, 64 PreventRepeatQuitCallMiddleware::class,
65 //操作日志中间件 65 //操作日志中间件
66 ManageLogMiddleware::class, 66 ManageLogMiddleware::class,
  67 + //允许跨域请求
  68 + \App\Http\Middleware\Aside\EnableCrossRequestMiddleware::class
67 ], 69 ],
68 //B端中间件组 70 //B端中间件组
69 'bside'=>[ 71 'bside'=>[
@@ -24,6 +24,13 @@ class HrLogic extends BaseLogic @@ -24,6 +24,13 @@ class HrLogic extends BaseLogic
24 $this->model = new ManageHr(); 24 $this->model = new ManageHr();
25 } 25 }
26 26
  27 + /**
  28 + * @remark :获取列表
  29 + * @name :getList
  30 + * @author :lyh
  31 + * @method :post
  32 + * @time :2023/7/24 11:50
  33 + */
27 public function getList($map,$page,$row,$order = 'id',$filed = ['*']){ 34 public function getList($map,$page,$row,$order = 'id',$filed = ['*']){
28 $lists = $this->model->lists($map,$page,$row,$order,$filed); 35 $lists = $this->model->lists($map,$page,$row,$order,$filed);
29 return $this->success($lists); 36 return $this->success($lists);
  1 +<?php
  2 +
  3 +namespace App\Http\Middleware\Aside;
  4 +
  5 +use Closure;
  6 +
  7 +class EnableCrossRequestMiddleware
  8 +{
  9 + /**
  10 + * Handle an incoming request.
  11 + *
  12 + * @param \Illuminate\Http\Request $request
  13 + * @param \Closure $next
  14 + * @return mixed
  15 + */
  16 + public function handle($request, Closure $next)
  17 + {
  18 + $response = $next($request);
  19 + $http_origin = "*";
  20 + if(isset($_SERVER['HTTP_ORIGIN'])){
  21 + $http_origin = $_SERVER['HTTP_ORIGIN'];
  22 + }
  23 + $response->header('Access-Control-Allow-Origin', $http_origin);
  24 + $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
  25 + $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization');
  26 + if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
  27 + exit;
  28 + }
  29 + return $response;
  30 + // 指定允许其他域名访问
  31 +// $http_origin = "*";
  32 +// if(isset($_SERVER['HTTP_ORIGIN'])){
  33 +// $http_origin = $_SERVER['HTTP_ORIGIN'];
  34 +// }
  35 +// header("Access-Control-Allow-Origin:".$http_origin);
  36 +// header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作
  37 +// header('Access-Control-Allow-Credentials: true');
  38 +// header('Access-Control-Max-Age: 1000');
  39 +// header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。
  40 +// if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
  41 +// exit;
  42 +// }
  43 +// return $next($request);
  44 + }
  45 +}