diff --git a/app/admin/controller/auth/Admin.php b/app/admin/controller/auth/Admin.php index 9850ccc..30177af 100644 --- a/app/admin/controller/auth/Admin.php +++ b/app/admin/controller/auth/Admin.php @@ -34,9 +34,31 @@ class Admin extends Backend protected string $dataLimitField = 'id'; + protected Tree $tree; + + protected array $initValue = []; + + protected string $keyword = ''; + + protected bool $assembleTree = false; + protected function initController(Request $request): ?Response { $this->model = new AdminModel(); + $this->tree = Tree::instance(); + + $isTree = $request->get('isTree') ?? $request->post('isTree') ?? false; + $initValue = $request->get('initValue') ?? $request->post('initValue') ?? []; + if (is_array($initValue)) { + $this->initValue = array_filter($initValue); + } elseif ($initValue !== null && $initValue !== '') { + $this->initValue = array_filter(explode(',', (string) $initValue)); + } else { + $this->initValue = []; + } + $this->keyword = (string) ($request->get('quickSearch') ?? $request->post('quickSearch') ?? ''); + $this->assembleTree = ($isTree === true || $isTree === '1' || $isTree === 1) && $this->initValue === []; + return null; } @@ -596,7 +618,50 @@ class Admin extends Backend public function select(Request $request): Response { - return parent::select($request); + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + + $rows = $this->getAdminsForSelect($request); + if ($this->assembleTree) { + $treeData = $this->tree->assembleChild($rows, 'pid', 'id'); + $rows = $this->tree->assembleTree($this->tree->getTreeArray($treeData, 'username')); + } + + return $this->success('', [ + 'options' => $rows, + ]); + } + + /** + * @return array> + */ + private function getAdminsForSelect(Request $request): array + { + list($where, $alias, $limit, $order) = $this->queryBuilder(); + $adminAlias = $alias[strtolower($this->model->getTable())] ?? 'admin'; + + $query = $this->model + ->withoutField('login_failure,password,salt') + ->alias($alias) + ->where($where); + + $visibleIds = AdminCommissionDistributionService::getVisibleAdminIdsForOperator( + intval($this->auth->id), + $this->auth->isSuperAdmin() + ); + if ($visibleIds !== []) { + $query->where($adminAlias . '.id', 'in', $visibleIds); + } + + $rows = $query->order($order)->select()->toArray(); + foreach ($rows as $k => $row) { + $parentId = intval($row['parent_admin_id'] ?? 0); + $rows[$k]['pid'] = $parentId > 0 ? $parentId : 0; + } + + return $rows; } private function checkGroupAuth(array $groups): ?Response diff --git a/web/src/views/backend/auth/admin/popupForm.vue b/web/src/views/backend/auth/admin/popupForm.vue index f777857..b989960 100644 --- a/web/src/views/backend/auth/admin/popupForm.vue +++ b/web/src/views/backend/auth/admin/popupForm.vue @@ -74,11 +74,13 @@ v-model="baTable.form.items!.parent_admin_id" type="remoteSelect" prop="parent_admin_id" + :key="'parent-' + (baTable.form.items!.channel_id ?? '') + '-' + baTable.form.items!.id" :input-attr="{ remoteUrl: '/admin/auth.Admin/index', field: 'username', pk: 'id', disabled: isTopLevelGroup, + pagination: false, params: parentSelectParams, placeholder: t('auth.admin.Parent admin placeholder'), }" @@ -217,7 +219,7 @@ const showShareRateField = computed(() => { }) const parentSelectParams = computed(() => { - const params: anyObj = { select: true, limit: 200 } + const params: anyObj = { isTree: true } const cid = baTable.form.items?.channel_id if (cid !== null && cid !== undefined && cid !== '') { params['search[0][field]'] = 'channel_id'