Explorar el Código

提交学习管理员的权限管理模块

zlwu hace 1 año
padre
commit
dcecdbd6aa

+ 12 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/controller/XgStudentManagerSourceController.java

@@ -114,4 +114,16 @@ public class XgStudentManagerSourceController extends BaseController {
         xgStudentManagerSourceService.grantDeptAuth(managerId, authSourceIds);
         return R.ok();
     }
+
+    /**
+     * 获取指定管理员的授权资源名称列表
+     *
+     * @param managerId 管理员ID
+     * @return 授权资源名称数组
+     */
+    @SaCheckPermission("xgStudentManagerSource:studentManagerSource:query")
+    @GetMapping("/authSourceNames")
+    public R<List<String>> getAuthSourceNames(@RequestParam Long managerId) {
+        return R.ok(xgStudentManagerSourceService.getAuthSourceNames(managerId));
+    }
 }

+ 1 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/mapper/XgStudentManagerSourceMapper.java

@@ -12,4 +12,5 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
  */
 public interface XgStudentManagerSourceMapper extends BaseMapperPlus<XgStudentManagerSource, XgStudentManagerSourceVo> {
 
+    // 预留自定义SQL方法接口
 }

+ 8 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/IXgStudentManagerSourceService.java

@@ -73,4 +73,12 @@ public interface IXgStudentManagerSourceService {
      * @param authSourceIds 资源ID列表
      */
     void grantDeptAuth(Long managerId, List<Long> authSourceIds);
+
+    /**
+     * 获取指定管理员的授权资源名称列表
+     *
+     * @param managerId 管理员ID
+     * @return 授权资源名称数组
+     */
+    List<String> getAuthSourceNames(Long managerId);
 }

+ 23 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgStudentManagerSourceServiceImpl.java

@@ -164,4 +164,27 @@ public class XgStudentManagerSourceServiceImpl implements IXgStudentManagerSourc
             baseMapper.insertBatch(insertList);
         }
     }
+
+    @Override
+    public List<String> getAuthSourceNames(Long managerId) {
+        // 1. 查询xg_student_manager_source表,manager_id=managerId, deleted=0,
+        // status=0,获取auth_source
+        List<Long> authSourceIds = baseMapper.selectList(
+                Wrappers.<XgStudentManagerSource>lambdaQuery()
+                        .eq(XgStudentManagerSource::getManagerId, managerId)
+                        .eq(XgStudentManagerSource::getDeleted, "0")
+                        .eq(XgStudentManagerSource::getStatus, "0"))
+                .stream().map(XgStudentManagerSource::getAuthSource)
+                .filter(id -> id != null)
+                .toList();
+        if (authSourceIds.isEmpty()) {
+            return java.util.Collections.emptyList();
+        }
+        // 2. 查询sys_dept表,dept_id in (authSourceIds), status=0, del_flag=0,获取dept_name
+        String inSql = authSourceIds.stream().map(String::valueOf).collect(java.util.stream.Collectors.joining(","));
+        String sql = "SELECT dept_name FROM sys_dept WHERE dept_id IN (" + inSql
+                + ") AND status = '0' AND del_flag = '0'";
+        List<String> deptNames = jdbcTemplate.queryForList(sql, String.class);
+        return deptNames;
+    }
 }

+ 1 - 47
web/src/router/index.ts

@@ -89,56 +89,10 @@ export const constantRoutes: RouteRecordRaw[] = [
       }
     ]
   },
-  {
-    path: '/xljk',
-    component: Layout,
-    hidden: true,
-    children: [
-      {
-        path: 'evaluation/detail/:id',
-        component: () => import('@/views/xljk/evaluation/detail.vue'),
-        name: 'XljkEvaluationDetail',
-        meta: { title: '心理健康测评详情', icon: 'form', activeMenu: '/xljk/evaluation' }
-      },
-      {
-        path: 'evaluation/add',
-        component: () => import('@/views/xljk/evaluation/add.vue'),
-        name: 'XljkEvaluationAdd',
-        meta: { title: '新增心理健康测评', icon: 'form', activeMenu: '/xljk/evaluation' }
-      },
-      {
-        path: 'evaluation/edit/:id',
-        component: () => import('@/views/xljk/evaluation/edit.vue'),
-        name: 'XljkEvaluationEdit',
-        meta: { title: '编辑心理健康测评', icon: 'form', activeMenu: '/xljk/evaluation' }
-      },
-      {
-        path: 'evaluation/fill/:id',
-        component: () => import('@/views/xljk/evaluation/fill.vue'),
-        name: 'XljkEvaluationFill',
-        meta: { title: '填写心理健康测评', icon: 'form', activeMenu: '/xljk/evaluation' }
-      }
-    ]
-  }
 ];
 
 // 动态路由,基于用户权限动态去加载
-export const dynamicRoutes: RouteRecordRaw[] = [
-  {
-    path: '/xljk',
-    component: Layout,
-    name: 'Xljk',
-    meta: { title: '学工管理', icon: 'education' },
-    children: [
-      {
-        path: 'evaluation',
-        component: () => import('@/views/xljk/evaluation/index.vue'),
-        name: 'XljkEvaluation',
-        meta: { title: '心理健康测评', icon: 'heart', permissions: ['xljk:evaluation:list'] }
-      }
-    ]
-  }
-];
+export const dynamicRoutes: RouteRecordRaw[] = [];
 
 /**
  * 创建路由

+ 60 - 8
web/src/views/studentMsg/authmsg/index.vue

@@ -63,7 +63,7 @@
                   <el-input v-model="customSearchForm.phone" placeholder="请输入手机号码" clearable @keyup.enter="handleSearch('custom')" />
                 </el-form-item>
                 <el-form-item>
-                  <el-button type="primary" icon="Search" @click="handleSearch('custom')">搜索</el-button>
+                  <el-button type="primary" icon="Search" @click="fetchCustomAdminsWithScope('custom')">搜索</el-button>
                   <el-button icon="Refresh" @click="handleReset('custom')">重置</el-button>
                 </el-form-item>
               </el-form>
@@ -85,7 +85,23 @@
                   {{ scope.row.gender == 0 ? '男' : '女' }}
                 </template>
               </el-table-column>
-              <el-table-column prop="scope" label="管理范围" align="center" />
+              <el-table-column prop="scope" label="管理范围" align="center">
+                <template #default="scope">
+                  <el-tooltip
+                    v-if="scope.row.authSourceNames && scope.row.authSourceNames.length > 2"
+                    :content="scope.row.authSourceNames.join(',')"
+                    placement="top"
+                  >
+                    <span>
+                      {{ scope.row.authSourceNames.slice(0, 2).join(',')
+                      }}{{ scope.row.authSourceNames.length > 2 ? ' 等' + scope.row.authSourceNames.length + '个' : '' }}
+                    </span>
+                  </el-tooltip>
+                  <span v-else>
+                    {{ scope.row.authSourceNames?.join(',') || '-' }}
+                  </span>
+                </template>
+              </el-table-column>
               <el-table-column prop="remark" label="备注" align="center" />
               <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
                 <template #default="scope">
@@ -163,12 +179,13 @@
 </template>
 
 <script setup lang="ts">
-import { ref, reactive, onMounted } from 'vue';
+import { ref, reactive, onMounted, watch } from 'vue';
 import AdminDialog from './components/AdminDialog.vue';
 import ScopeDialog from './components/ScopeDialog.vue';
 import { ElMessage, ElMessageBox } from 'element-plus';
 import { listStudentManager, delStudentManager, listActiveClassTeachers } from '@/api/xgStudentManager/studentManager';
 import type { StudentManagerQuery } from '@/api/xgStudentManager/studentManager/types';
+import service from '@/utils/request';
 
 // 暴露组件以修复导出问题
 defineExpose({});
@@ -221,7 +238,6 @@ async function fetchAdmins(type: string) {
         ...searchForm,
         managerType
       });
-
       // 更新对应类型的管理员数据
       if (type === 'school') {
         schoolAdmins.value = res.rows || [];
@@ -256,9 +272,34 @@ function getSearchForm(type: string) {
   }
 }
 
+// 获取自定义管理员及其管理范围
+async function fetchCustomAdminsWithScope() {
+  await fetchAdmins('custom');
+  // 遍历 customAdmins,异步获取每个管理员的authSource
+  for (const admin of customAdmins.value) {
+    try {
+      const res = await service({
+        url: '/xgStudentManagerSource/studentManagerSource//authSourceNames',
+        method: 'get',
+        params: { managerId: admin.id }
+      });
+      admin.authSourceNames = res?.data || [];
+    } catch (e) {
+      admin.authSourceNames = [];
+    }
+  }
+}
+
+// 监听tab切换,切到custom时自动加载管理范围
+watch(activeTab, (val) => {
+  if (val === 'custom') {
+    fetchCustomAdminsWithScope();
+  }
+});
+
 onMounted(() => {
   fetchAdmins('school');
-  fetchAdmins('custom');
+  fetchCustomAdminsWithScope();
   fetchAdmins('teacher');
 });
 
@@ -321,7 +362,11 @@ function onScope(type: string, admin: any) {
 function onDialogSubmit(admin: any) {
   // 表单已在对话框组件内处理API调用
   // 刷新列表数据
-  fetchAdmins(activeTab.value);
+  if (activeTab.value === 'custom') {
+    fetchCustomAdminsWithScope();
+  } else {
+    fetchAdmins(activeTab.value);
+  }
   dialogVisible.value = false;
 }
 
@@ -331,6 +376,7 @@ async function onScopeSubmit(scope: any) {
     // 成功后刷新数据并提示
     ElMessage.success('管理范围分配成功');
     fetchAdmins(scopeType.value);
+    fetchCustomAdminsWithScope();
     scopeDialogVisible.value = false;
   } catch (error) {
     ElMessage.error('管理范围分配失败');
@@ -353,7 +399,9 @@ function getListByType(type: string) {
 
 // 过滤
 function filteredAdmins(type: string) {
-  console.log(getListByType(type).value);
+  if (type === 'custom') {
+    return customAdmins.value;
+  }
   return getListByType(type).value;
 }
 
@@ -376,7 +424,11 @@ function handleReset(type: string) {
       teacherSearchForm.phone = '';
       break;
   }
-  fetchAdmins(type);
+  if (type === 'custom') {
+    fetchCustomAdminsWithScope();
+  } else {
+    fetchAdmins(type);
+  }
 }
 </script>