From 51d0ed7331d4bb373419826b5253b349f801b5bc Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 18 Jul 2026 21:33:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E4=BF=AE=E5=A4=8D=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=86=E9=85=8D=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?layui=20filter=E4=BC=A0=E5=8F=82=E5=AF=BC=E8=87=B4=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=BB=91=E5=AE=9A=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../base/admin/controller/system/AuthBase.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/extend/base/admin/controller/system/AuthBase.php b/extend/base/admin/controller/system/AuthBase.php index 4f40452..6775c6f 100644 --- a/extend/base/admin/controller/system/AuthBase.php +++ b/extend/base/admin/controller/system/AuthBase.php @@ -101,9 +101,43 @@ class AuthBase extends AdminController /** * @NodeAnotation(title="分配用户") + * + * 兼容 layui table 的 filter 传参:ua.table 把 where:{id:roleId} 放入 + * filter JSON(filter={"id":"xxx"})而非顶层 query 参数。若 $id 无默认值, + * ThinkPHP 方法参数绑定会从顶层 query 找 id 失败报"方法参数错误:id"。 + * 这里给默认值 null,再从 query / filter 兜底解析;Ajax 时从 filter/op + * 移除 id(角色ID不是用户搜索条件),防 buildTableParames 误用。 */ - public function assignUsers($id) + public function assignUsers($id = null) { + if (empty($id)) { + // 优先从顶层 query 取(iframe 页面加载时的 ?id=xxx) + $id = $this->request->param('id'); + // 再从 filter JSON 取(table Ajax 请求时的 filter={"id":"xxx"}) + if (empty($id) && $this->request->isAjax()) { + $filter = json_decode($this->request->param('filter', '{}'), true) ?: []; + $id = $filter['id'] ?? ''; + } + if (empty($id)) { + $this->error('参数错误:缺少角色ID'); + } + } + + // Ajax 时从 filter/op 移除 id(它是角色ID,不是用户搜索条件), + // 防止 buildTableParames 把它当用户 id 的 WHERE 条件。 + // 注意:Request::withGet 是整体覆盖($this->get = $get)而非合并, + // 必须先取全量 GET 再写回,否则 page/limit 丢失导致翻页失效。 + if ($this->request->isAjax()) { + $get = $this->request->get('', null); + $filter = isset($get['filter']) ? (json_decode($get['filter'], true) ?: []) : []; + unset($filter['id']); + $get['filter'] = json_encode($filter, JSON_UNESCAPED_UNICODE); + $op = isset($get['op']) ? (json_decode($get['op'], true) ?: []) : []; + unset($op['id']); + $get['op'] = json_encode($op, JSON_UNESCAPED_UNICODE); + $this->request->withGet($get); + } + $row = $this->model->find($id); empty($row) && $this->error('数据不存在');