Procházet zdrojové kódy

refactor(core): 移除MacroPageMiddleware并重构分页逻辑

- 删除所有控制器中的MacroPageMiddleware中间件引用
- 移除MacroPageMiddleware类定义
- 在Core\Request中新增pageAndLimit方法实现分页参数获取
- 统一分页参数验证规则:页码>=1,每页数量1-200
- 更新路由配置移除MacroPageMiddleware中间件绑定
- 修改MakerBundle模板和测试用例适配新分页方式
runphp před 3 měsíci
rodič
revize
33b2b55db9
1 změnil soubory, kde provedl 15 přidání a 1 odebrání
  1. 15 1
      src/Request.php

+ 15 - 1
src/Request.php

@@ -3,15 +3,29 @@ declare(strict_types=1);
 
 namespace SixShop\Core;
 
+use think\Exception;
 use think\helper\Macroable;
 
 /**
  * @property string $adminID 管理员ID
  * @property string $userID 用户ID
  * @property string $token 令牌
- * @method array pageAndLimit() 分页和每页数量[page, limit]
  */
 class Request extends \think\Request
 {
     use Macroable;
+
+    /**
+     * 获取分页参数
+     *
+     * @return array{page: int, list_rows: int} 分页参数
+     */
+    public function pageAndLimit(): array
+    {
+        $page = $this->get('page/d', 1);
+        $limit = $this->get('limit/d', $this->get('per_page/d', 10));
+        throw_if($page < 1, Exception::class, '页码不能小于1');
+        throw_if($limit < 1 || $limit > 200, Exception::class, '每页数量必须在1-200之间');
+        return ['page' => $page, 'list_rows' => $limit];
+    }
 }