1.优化/admin/auth/admin中上级代理下拉框选项
This commit is contained in:
@@ -56,12 +56,45 @@ class Admin extends Backend
|
||||
} else {
|
||||
$this->initValue = [];
|
||||
}
|
||||
$this->keyword = (string) ($request->get('quickSearch') ?? $request->post('quickSearch') ?? '');
|
||||
$this->assembleTree = ($isTree === true || $isTree === '1' || $isTree === 1) && $this->initValue === [];
|
||||
$this->keyword = (string) ($request->get('quickSearch') ?? $request->post('quickSearch') ?? '');
|
||||
$this->assembleTree = self::isRequestTruthy($isTree) && $this->initValue === [];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析请求中的布尔参数(兼容 true / "true" / 1 / "1")
|
||||
*/
|
||||
private static function isRequestTruthy(mixed $value): bool
|
||||
{
|
||||
if ($value === false || $value === null || $value === '' || $value === 0 || $value === '0' || $value === 'false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉树形选项(isTree=1)
|
||||
*/
|
||||
private function shouldFormatSelectTree(Request $request): bool
|
||||
{
|
||||
$isTree = $request->get('isTree') ?? $request->post('isTree') ?? false;
|
||||
|
||||
return self::isRequestTruthy($isTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为远程下拉请求
|
||||
*/
|
||||
private function isRemoteSelectRequest(Request $request): bool
|
||||
{
|
||||
if ($request->get('select') ?? $request->post('select')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->shouldFormatSelectTree($request);
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
@@ -69,11 +102,8 @@ class Admin extends Backend
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($request->get('select') ?? $request->post('select')) {
|
||||
$selectRes = $this->select($request);
|
||||
if ($selectRes !== null) {
|
||||
return $selectRes;
|
||||
}
|
||||
if ($this->isRemoteSelectRequest($request)) {
|
||||
return $this->select($request);
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
@@ -218,82 +248,16 @@ class Admin extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉(重写:支持 top_group=1 仅返回顶级组管理员)
|
||||
* 远程下拉(兼容 Backend trait,统一走 select 树形)
|
||||
*/
|
||||
protected function _select(): Response
|
||||
{
|
||||
if (empty($this->model)) {
|
||||
return $this->success('', [
|
||||
'list' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
if ($this->request instanceof Request) {
|
||||
return $this->select($this->request);
|
||||
}
|
||||
|
||||
$pk = $this->model->getPk();
|
||||
|
||||
$fields = [$pk];
|
||||
$quickSearchArr = is_array($this->quickSearchField) ? $this->quickSearchField : explode(',', (string) $this->quickSearchField);
|
||||
foreach ($quickSearchArr as $f) {
|
||||
$f = trim((string) $f);
|
||||
if ($f === '') {
|
||||
continue;
|
||||
}
|
||||
$f = str_contains($f, '.') ? substr($f, strrpos($f, '.') + 1) : $f;
|
||||
if ($f !== '' && !in_array($f, $fields, true)) {
|
||||
$fields[] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$modelTable = strtolower($this->model->getTable());
|
||||
$mainAlias = ($alias[$modelTable] ?? $modelTable) . '.';
|
||||
|
||||
$selectFields = [];
|
||||
foreach ($fields as $f) {
|
||||
$f = trim((string) $f);
|
||||
if ($f === '') {
|
||||
continue;
|
||||
}
|
||||
$selectFields[] = $mainAlias . $f . ' as ' . $f;
|
||||
}
|
||||
|
||||
$qualifiedOrder = [];
|
||||
if (is_array($order)) {
|
||||
foreach ($order as $k => $v) {
|
||||
$k = (string) $k;
|
||||
$qualifiedOrder[str_contains($k, '.') ? $k : ($mainAlias . $k)] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->model
|
||||
->field($selectFields)
|
||||
->alias($alias)
|
||||
->where($where);
|
||||
|
||||
$visibleIds = AdminCommissionDistributionService::getVisibleAdminIdsForOperator(
|
||||
intval($this->auth->id),
|
||||
$this->auth->isSuperAdmin()
|
||||
);
|
||||
if ($visibleIds !== []) {
|
||||
$query->where($mainAlias . 'id', 'in', $visibleIds);
|
||||
}
|
||||
|
||||
$topGroup = $this->request ? ($this->request->get('top_group') ?? $this->request->post('top_group')) : null;
|
||||
if ($topGroup === '1' || $topGroup === 1 || $topGroup === true) {
|
||||
$query = $query
|
||||
->join('admin_group_access aga', $mainAlias . 'id = aga.uid')
|
||||
->join('admin_group ag', 'aga.group_id = ag.id')
|
||||
->where('ag.pid', 0)
|
||||
->distinct(true);
|
||||
}
|
||||
|
||||
$res = $query
|
||||
->order($qualifiedOrder ?: $order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'options' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -624,7 +588,7 @@ class Admin extends Backend
|
||||
}
|
||||
|
||||
$rows = $this->getAdminsForSelect($request);
|
||||
if ($this->assembleTree) {
|
||||
if ($this->shouldFormatSelectTree($request)) {
|
||||
$treeData = $this->tree->assembleChild($rows, 'pid', 'id');
|
||||
$rows = $this->tree->assembleTree($this->tree->getTreeArray($treeData, 'username'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user