Просмотр исходного кода

✨ feat(departments): 部门管理功能优化

- 新增部门负责人字段及选择功能
- 添加负责人列显示部门负责人姓名
- 使用UserSelect组件替代原输入框选择负责人

♻️ refactor(role): 优化角色选择器查询

- 为角色列表查询添加排序参数,按ID升序排列
yourname 8 месяцев назад
Родитель
Сommit
c3fc95f88b
2 измененных файлов с 26 добавлено и 2 удалено
  1. 2 0
      src/client/admin/components/RoleSelect.tsx
  2. 24 2
      src/client/admin/pages/Departments.tsx

+ 2 - 0
src/client/admin/components/RoleSelect.tsx

@@ -35,6 +35,8 @@ export const RoleSelect: React.FC<RoleSelectProps> = ({
         query: {
           page: 1,
           pageSize: 100, // 获取所有角色用于选择
+          sortBy: 'id',
+          sortOrder: 'ASC',
         }
       });
       if (res.status !== 200) {

+ 24 - 2
src/client/admin/pages/Departments.tsx

@@ -2,8 +2,9 @@ import React, { useState } from 'react';
 import { Table, Button, Modal, Form, Input, Switch, message, Space, Popconfirm } from 'antd';
 import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
 import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
-import { departmentsClient } from '@/client/api';
+import { departmentsClient, userClient } from '@/client/api';
 import LazyDepartmentTreeSelect from '@/client/admin/components/LazyDepartmentTreeSelect';
+import UserSelect from '@/client/admin/components/UserSelect';
 
 const Departments: React.FC = () => {
   const [form] = Form.useForm();
@@ -21,6 +22,16 @@ const Departments: React.FC = () => {
     }
   });
 
+  // 查询用户列表
+  const { data: usersData } = useQuery({
+    queryKey: ['users-for-departments'],
+    queryFn: async () => {
+      const response = await userClient.$get({ query: { page: 1, pageSize: 1000 } });
+      if (response.status !== 200) throw new Error('获取用户列表失败');
+      return response.json();
+    }
+  });
+
   // 创建部门
   const createMutation = useMutation({
     mutationFn: async (data: any) => {
@@ -97,6 +108,17 @@ const Departments: React.FC = () => {
         return parent?.name || '-';
       },
     },
+    {
+      title: '负责人',
+      dataIndex: 'managerId',
+      key: 'managerId',
+      width: 120,
+      render: (managerId: number) => {
+        if (!managerId) return '-';
+        const manager = usersData?.data.find((u: any) => u.id === managerId);
+        return manager?.name || manager?.username || '-';
+      },
+    },
     {
       title: '排序',
       dataIndex: 'sortOrder',
@@ -248,7 +270,7 @@ const Departments: React.FC = () => {
             label="负责人"
             name="managerId"
           >
-            <Input placeholder="请输入负责人ID" type="number" />
+            <UserSelect placeholder="请选择负责人" />
           </Form.Item>
 
           <Form.Item