1.优化/admin/auth/admin中上级代理下拉框选项
This commit is contained in:
@@ -34,9 +34,31 @@ class Admin extends Backend
|
|||||||
|
|
||||||
protected string $dataLimitField = 'id';
|
protected string $dataLimitField = 'id';
|
||||||
|
|
||||||
|
protected Tree $tree;
|
||||||
|
|
||||||
|
protected array $initValue = [];
|
||||||
|
|
||||||
|
protected string $keyword = '';
|
||||||
|
|
||||||
|
protected bool $assembleTree = false;
|
||||||
|
|
||||||
protected function initController(Request $request): ?Response
|
protected function initController(Request $request): ?Response
|
||||||
{
|
{
|
||||||
$this->model = new AdminModel();
|
$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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +618,50 @@ class Admin extends Backend
|
|||||||
|
|
||||||
public function select(Request $request): Response
|
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<int, array<string, mixed>>
|
||||||
|
*/
|
||||||
|
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
|
private function checkGroupAuth(array $groups): ?Response
|
||||||
|
|||||||
@@ -74,11 +74,13 @@
|
|||||||
v-model="baTable.form.items!.parent_admin_id"
|
v-model="baTable.form.items!.parent_admin_id"
|
||||||
type="remoteSelect"
|
type="remoteSelect"
|
||||||
prop="parent_admin_id"
|
prop="parent_admin_id"
|
||||||
|
:key="'parent-' + (baTable.form.items!.channel_id ?? '') + '-' + baTable.form.items!.id"
|
||||||
:input-attr="{
|
:input-attr="{
|
||||||
remoteUrl: '/admin/auth.Admin/index',
|
remoteUrl: '/admin/auth.Admin/index',
|
||||||
field: 'username',
|
field: 'username',
|
||||||
pk: 'id',
|
pk: 'id',
|
||||||
disabled: isTopLevelGroup,
|
disabled: isTopLevelGroup,
|
||||||
|
pagination: false,
|
||||||
params: parentSelectParams,
|
params: parentSelectParams,
|
||||||
placeholder: t('auth.admin.Parent admin placeholder'),
|
placeholder: t('auth.admin.Parent admin placeholder'),
|
||||||
}"
|
}"
|
||||||
@@ -217,7 +219,7 @@ const showShareRateField = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const parentSelectParams = computed(() => {
|
const parentSelectParams = computed(() => {
|
||||||
const params: anyObj = { select: true, limit: 200 }
|
const params: anyObj = { isTree: true }
|
||||||
const cid = baTable.form.items?.channel_id
|
const cid = baTable.form.items?.channel_id
|
||||||
if (cid !== null && cid !== undefined && cid !== '') {
|
if (cid !== null && cid !== undefined && cid !== '') {
|
||||||
params['search[0][field]'] = 'channel_id'
|
params['search[0][field]'] = 'channel_id'
|
||||||
|
|||||||
Reference in New Issue
Block a user