fix(auth): 修复角色分配用户列表layui filter传参导致参数绑定错误

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
augushong
2026-07-18 21:33:33 +08:00
parent 3f7050bf65
commit 51d0ed7331

View File

@@ -101,9 +101,43 @@ class AuthBase extends AdminController
/**
* @NodeAnotation(title="分配用户")
*
* 兼容 layui table 的 filter 传参ua.table 把 where:{id:roleId} 放入
* filter JSONfilter={"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('数据不存在');