From e94ebd3fe6ee4268aa8a9f4b8db3c7f935f458d6 Mon Sep 17 00:00:00 2001
From: zhenhui <1276357500@qq.com>
Date: Tue, 10 Mar 2026 09:59:24 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A1=B5=E9=9D=A2=E6=A0=B7?=
=?UTF-8?q?=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
saiadmin-artd/index.html | 2 +-
saiadmin-artd/src/config/index.ts | 2 +-
saiadmin-artd/src/locales/langs/en.json | 4 ++--
saiadmin-artd/src/locales/langs/zh.json | 4 ++--
saiadmin-artd/src/views/system/user/index.vue | 8 +++++++-
.../app/logic/system/SystemDeptLogic.php | 5 ++++-
.../app/logic/system/SystemUserLogic.php | 16 ++++++++++++----
.../saiadmin/app/model/system/SystemDept.php | 11 +++++++----
8 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/saiadmin-artd/index.html b/saiadmin-artd/index.html
index e9f36a9..b7afdfc 100644
--- a/saiadmin-artd/index.html
+++ b/saiadmin-artd/index.html
@@ -1,7 +1,7 @@
- SaiAdmin
+ Dafuweng-Dice
row.depts?.name ?? ''
+ },
{ prop: 'status', label: '状态', width: 80, saiType: 'dict', saiDict: 'data_status' },
{ prop: 'dashboard', label: '首页', width: 100, saiType: 'dict', saiDict: 'dashboard' },
{ prop: 'login_time', label: '上次登录', width: 170, sortable: true },
diff --git a/server/plugin/saiadmin/app/logic/system/SystemDeptLogic.php b/server/plugin/saiadmin/app/logic/system/SystemDeptLogic.php
index 933fa3a..7a235f3 100644
--- a/server/plugin/saiadmin/app/logic/system/SystemDeptLogic.php
+++ b/server/plugin/saiadmin/app/logic/system/SystemDeptLogic.php
@@ -117,7 +117,10 @@ class SystemDeptLogic extends BaseLogic
public function accessDept(array $where = []): array
{
$query = $this->search($where);
- $query->auth($this->adminInfo['deptList']);
+ // 超级管理员(id=1)可查看全部部门,普通管理员按部门权限过滤
+ if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
+ $query->auth($this->adminInfo['deptList'] ?? []);
+ }
$query->field('id, id as value, name as label, parent_id');
$query->order('sort', 'desc');
$data = $this->getAll($query);
diff --git a/server/plugin/saiadmin/app/logic/system/SystemUserLogic.php b/server/plugin/saiadmin/app/logic/system/SystemUserLogic.php
index 7188082..f39ddd2 100644
--- a/server/plugin/saiadmin/app/logic/system/SystemUserLogic.php
+++ b/server/plugin/saiadmin/app/logic/system/SystemUserLogic.php
@@ -40,7 +40,10 @@ class SystemUserLogic extends BaseLogic
{
$query = $this->search($where);
$query->with(['depts']);
- $query->auth($this->adminInfo['deptList']);
+ // 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤
+ if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
+ $query->auth($this->adminInfo['deptList'] ?? []);
+ }
return $this->getList($query);
}
@@ -132,9 +135,11 @@ class SystemUserLogic extends BaseLogic
return $this->transaction(function () use ($data, $id) {
$role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
- // 仅可修改当前部门和子部门的用户
+ // 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户
$query = $this->model->where('id', $id);
- $query->auth($this->adminInfo['deptList']);
+ if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
+ $query->auth($this->adminInfo['deptList'] ?? []);
+ }
$user = $query->findOrEmpty();
if ($user->isEmpty()) {
throw new ApiException('没有权限操作该数据');
@@ -182,7 +187,10 @@ class SystemUserLogic extends BaseLogic
throw new ApiException('超级管理员禁止删除');
}
$query = $this->model->where('id', $ids);
- $query->auth($this->adminInfo['deptList']);
+ // 超级管理员可删除任意用户,普通管理员仅可删除当前部门和子部门的用户
+ if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
+ $query->auth($this->adminInfo['deptList'] ?? []);
+ }
$user = $query->findOrEmpty();
if ($user->isEmpty()) {
throw new ApiException('没有权限操作该数据');
diff --git a/server/plugin/saiadmin/app/model/system/SystemDept.php b/server/plugin/saiadmin/app/model/system/SystemDept.php
index 99fc923..f071d57 100644
--- a/server/plugin/saiadmin/app/model/system/SystemDept.php
+++ b/server/plugin/saiadmin/app/model/system/SystemDept.php
@@ -42,11 +42,14 @@ class SystemDept extends BaseModel
*/
public function scopeAuth($query, $value)
{
- if (!empty($value)) {
+ if (!empty($value) && isset($value['id'])) {
$deptIds = [$value['id']];
- $deptLevel = $value['level'] . $value['id'] . ',';
- $ids = static::whereLike('level', $deptLevel . '%')->column('id');
- $deptIds = array_merge($deptIds, $ids);
+ $level = $value['level'] ?? '';
+ if ($level !== '' && $level !== null) {
+ $deptLevel = $level . $value['id'] . ',';
+ $ids = static::whereLike('level', $deptLevel . '%')->column('id');
+ $deptIds = array_merge($deptIds, $ids);
+ }
$query->whereIn('id', $deptIds);
}
}