1. 登录返回总公司,分公司,部门信息。

2. 修改角色权限管理的分配用户的数据渲染和接口。
3. 交叉评查任务的创建的组织架构组件的重构。
This commit is contained in:
2026-01-21 10:04:04 +08:00
parent 9951f16e50
commit b97d0e1a0b
12 changed files with 1348 additions and 14006 deletions
+5 -1
View File
@@ -50,7 +50,11 @@ export interface UserInfo {
area?: string; // 用户所属地区
id?: string | number; // 临时的用户id
user_id?: string | number;
user_role?: string
user_role?: string;
// 🔑 组织信息字段(可能为null)
tenant_name?: string | null;
dep_name?: string | null;
dep_short_name?: string | null;
}
/**
+4
View File
@@ -47,6 +47,10 @@ export interface LoginResponse {
user_role: string;
sub: string;
area?: string; // 🔑 用户所属地区
// 🔑 组织信息字段(可能为null)
tenant_name?: string | null;
dep_name?: string | null;
dep_short_name?: string | null;
};
};
error?: string;
+89 -1
View File
@@ -111,7 +111,16 @@ export interface RoleRoutePermission {
}
/**
* 用户信息
* 用户角色信息(用于用户列表中的角色显示)
*/
export interface UserRoleInfo {
role_id: number;
role_key: string;
role_name: string;
}
/**
* 用户信息(v3.4: 增加角色信息)
*/
export interface UserInfo {
id: number;
@@ -123,6 +132,10 @@ export interface UserInfo {
ou_name: string; // 部门名称,用于组织显示(部门级别)
status: number;
is_leader: boolean;
// v3.4: 用户角色信息(从 /api/v3/rbac/users 返回)
roles?: UserRoleInfo[];
tenant_name?: string; // 租户名称(多租户场景)
dep_name?: string; // 部门名称(多租户场景)
}
/**
@@ -664,6 +677,7 @@ export async function getRoleUsers(
/**
* 获取所有用户列表
* @param params 查询参数
* @deprecated 请使用 getUsersWithRoles 替代
*/
export async function getAllUsers(params?: {
page?: number;
@@ -726,6 +740,80 @@ export async function getAllUsers(params?: {
}
}
/**
* v3.4: 获取用户列表(含角色信息)
* 使用统一的 /api/v3/rbac/users 接口,一次性获取用户和角色信息
* @param params 查询参数
*/
export async function getUsersWithRoles(params?: {
page?: number;
page_size?: number;
area?: string;
nick_name?: string;
}): Promise<{
total: number;
page: number;
page_size: number;
items: UserInfo[];
}> {
try {
const queryParams: Record<string, any> = {};
if (params?.page) queryParams.page = params.page;
if (params?.page_size) queryParams.page_size = params.page_size;
if (params?.area) queryParams.area = params.area;
if (params?.nick_name) queryParams.nick_name = params.nick_name;
const response = await get<any>('/api/v3/rbac/users', queryParams);
if (response.error) {
throw new Error(response.error);
}
// 后端响应格式: { code: 200, message: "success", data: { total, page, page_size, items: [...] } }
let data: any;
if (response.data?.data) {
data = response.data.data;
} else if (response.data?.code === 200 && response.data) {
data = response.data;
} else {
data = response.data;
}
// console.log('获取的用户列表', data )
const items: UserInfo[] = (data.items || []).map((user: any) => ({
id: user.id,
username: user.username,
nick_name: user.nick_name,
phone_number: user.phone_number || '',
email: user.email || '',
area: user.area || '',
ou_name: user.ou_name,
ou_id: user.ou_id,
status: user.status || 0,
is_leader: user.is_leader || false,
roles: user.roles || [],
dep_name: user.dep_name,
tenant_name: user.tenant_name
}));
return {
total: data.total || 0,
page: data.page || 1,
page_size: data.page_size || 50,
items
};
} catch (error) {
console.error('❌ [getUsersWithRoles] 获取用户列表失败:', error);
return {
total: 0,
page: 1,
page_size: 50,
items: []
};
}
}
/**
* 为用户分配角色
* @param userId 用户ID
+215 -56
View File
@@ -2,18 +2,35 @@ import { get } from '../axios-client';
import { API_BASE_URL } from '../../config/api-config';
import axios from 'axios';
// 用户信息接口
// 组织路径信息(懒加载接口返回)
export interface OrganizationPath {
tenant_name: string;
dep_name: string;
dep_short_name: string;
ou_name: string;
}
// 用户信息接口(新版,匹配 /api/v2/users 响应)
export interface UserInfo {
id: number;
username: string;
nick_name: string;
area: string;
ou_id: string;
ou_name: string;
is_leader: boolean;
status: number;
// 以下字段在搜索接口中有值,在懒加载接口中为 null
tenant_name: string | null;
dep_name: string | null;
dep_short_name: string | null;
email?: string;
phone_number?: string;
// 懒加载接口返回的组织路径信息
organization_path?: OrganizationPath | null;
}
// 组织节点接口
// 组织节点接口(新版,匹配 /api/v2/users/organizations/tree 响应)
export interface OrganizationNode {
ou_id: string;
ou_name: string;
@@ -46,55 +63,125 @@ export interface ApiResponse<T> {
}
/**
* 获取组织架构树
* 获取组织架构树(新版接口,支持按需加载)
* @param includeUsers 是否包含用户信息
* @param rootUuid 指定根节点UUID,不传则查询所有根节点
* @param jwtToken JWT Token
* @returns 组织架构树
*/
export async function getOrganizationTree(includeUsers: boolean = true, jwtToken?: string): Promise<ApiResponse<OrganizationResponse>> {
export async function getOrganizationTree(
includeUsers: boolean = false,
jwtToken?: string,
rootUuid?: string
): Promise<ApiResponse<OrganizationResponse>> {
try {
console.log('开始调用获取组织架构API');
// console.log('[getOrganizationTree] 开始调用获取组织架构API:', { includeUsers, rootUuid });
let responseData: OrganizationResponse;
if (jwtToken) {
// 如果提供了JWT Token,则使用axios并携带Authorization头
const url = `${API_BASE_URL}/api/v2/users/organizations?include_users=${includeUsers}`;
const response = await axios.get(url, {
headers: {
'Authorization': `Bearer ${jwtToken}`,
'Content-Type': 'application/json'
}
});
responseData = response.data;
}
else {
// 否则,使用原有的get方法
const response = await get<OrganizationResponse>(
`/admin/users/organizations?include_users=${includeUsers}`
);
if (response.error || !response.data) {
console.error('获取组织架构失败 (get):', response.error);
return {
success: false,
error: response.error || '获取组织架构数据失败'
};
}
responseData = response.data;
const params: string[] = [];
params.push(`include_users=${includeUsers}`);
if (rootUuid) {
params.push(`root_uuid=${rootUuid}`);
}
console.log('组织架构API响应:', responseData);
const url = `${API_BASE_URL}/api/v2/users/organizations/tree?${params.join('&')}`;
const headers: Record<string, string> = {
'Content-Type': 'application/json'
};
if (jwtToken) {
headers['Authorization'] = `Bearer ${jwtToken}`;
}
const response = await axios.get<OrganizationResponse>(url, { headers });
const responseData = response.data;
// console.log('[getOrganizationTree] API响应:', responseData);
return {
success: true,
data: responseData
};
} catch (error) {
console.error('获取组织架构失败:', error);
console.error('[getOrganizationTree] 获取组织架构失败:', error);
let errorMessage = '获取组织架构失败';
if (axios.isAxiosError(error)) {
if (error.response?.data?.detail) {
errorMessage = error.response.data.detail;
} else if (error.response?.data?.message) {
errorMessage = error.response.data.message;
}
} else if (error instanceof Error) {
errorMessage = error.message;
}
return {
success: false,
error: error instanceof Error ? error.message : '获取组织架构失败'
error: errorMessage
};
}
}
/**
* 搜索用户(新版接口)
* @param search 搜索关键词(模糊匹配姓名和工号)
* @param page 页码
* @param pageSize 每页数量
* @param jwtToken JWT Token
* @returns 用户列表
*/
export async function searchUsers(
search: string,
page: number = 1,
pageSize: number = 20,
jwtToken?: string
): Promise<ApiResponse<{
users: UserInfo[];
total: number;
}>> {
try {
// console.log('[searchUsers] 搜索用户:', { search, page, pageSize });
const params: string[] = [];
if (search) params.push(`search=${encodeURIComponent(search)}`);
params.push(`page=${page}`);
params.push(`page_size=${pageSize}`);
const url = `${API_BASE_URL}/api/v2/users?${params.join('&')}`;
const headers: Record<string, string> = {
'Content-Type': 'application/json'
};
if (jwtToken) {
headers['Authorization'] = `Bearer ${jwtToken}`;
}
const response = await axios.get<{ users: UserInfo[]; total: number }>(url, { headers });
const responseData = response.data;
// console.log('[searchUsers] 搜索结果:', { total: responseData.total, count: responseData.users?.length });
return {
success: true,
data: responseData
};
} catch (error) {
console.error('[searchUsers] 搜索用户失败:', error);
let errorMessage = '搜索用户失败';
if (axios.isAxiosError(error)) {
if (error.response?.data?.detail) {
errorMessage = error.response.data.detail;
} else if (error.response?.data?.message) {
errorMessage = error.response.data.message;
}
} else if (error instanceof Error) {
errorMessage = error.message;
}
return {
success: false,
error: errorMessage
};
}
}
@@ -113,7 +200,7 @@ export async function getUserList(params: {
search?: string;
} = {}): Promise<ApiResponse<UserListResponse>> {
try {
console.log('开始调用获取用户列表API,参数:', params);
// console.log('开始调用获取用户列表API,参数:', params);
const queryParams = new URLSearchParams();
if (params.page) queryParams.append('page', params.page.toString());
@@ -127,7 +214,7 @@ export async function getUserList(params: {
`/admin/users/users?${queryParams.toString()}`
);
console.log('用户列表API响应:', response);
// console.log('用户列表API响应:', response);
if (response.error) {
console.error('获取用户列表失败:', response.error);
@@ -150,43 +237,115 @@ export async function getUserList(params: {
}
}
/**
* 在组织架构树中查找指定节点并提取其用户
* @param organizations 组织架构数据
* @param targetOuId 目标节点的 ou_id
* @returns 目标节点的用户列表转换为树节点
*/
export function extractUsersFromNode(organizations: OrganizationNode[], targetOuId: string): TreeNodeItem[] {
// 递归查找目标节点
function findNode(nodes: OrganizationNode[]): OrganizationNode | null {
for (const node of nodes) {
if (node.ou_id === targetOuId) {
return node;
}
if (node.children && node.children.length > 0) {
const found = findNode(node.children);
if (found) return found;
}
}
return null;
}
const targetNode = findNode(organizations);
if (!targetNode) {
console.warn('[extractUsersFromNode] 未找到目标节点:', targetOuId);
return [];
}
// 将该节点的用户转换为树节点
if (targetNode.users && targetNode.users.length > 0) {
return targetNode.users.map(user => convertUserToTreeNode(user));
}
return [];
}
/**
* 将组织架构数据转换为前端树形选择器格式
* @param organizations 组织架构数据
* @returns 前端树形选择器格式的数据
*/
export function convertToTreeData(organizations: OrganizationNode[]): Array<{
label: string;
value: string;
children?: Array<{
label: string;
value: string;
isUser?: boolean;
userInfo?: UserInfo;
}>;
}> {
export function convertToTreeData(organizations: OrganizationNode[]): TreeNodeItem[] {
return organizations.map(org => {
// 递归处理子组织
const subOrganizations = org.children && org.children.length > 0 ? convertToTreeData(org.children) : [];
// 添加该组织下的用户
const userChildren = (org.users && org.users.length > 0)
? org.users.map(user => ({
label: user.nick_name,
value: `user_${user.id}`,
isUser: true,
userInfo: user
}))
? org.users.map(user => convertUserToTreeNode(user))
: [];
// 合并子组织和用户
const children = [...subOrganizations, ...userChildren];
// 判断是否已加载:
// 1. 如果有子组织,说明数据已经完整(初始加载会返回完整的3层结构)
// 2. 如果没有子组织但有用户,说明是叶子节点且用户已加载
// 3. 如果既没有子组织也没有用户,说明是叶子节点但用户未加载(需要懒加载)
const hasSubOrgs = org.children && org.children.length > 0;
const hasUsers = org.users && org.users.length > 0;
// hasChildren 为 true 的情况:
// - 有子组织(可以展开查看下级)
// - 没有用户且没有子组织(可能需要懒加载用户)
const canExpand = hasSubOrgs || (!hasSubOrgs && !hasUsers);
return {
label: org.ou_name,
value: org.ou_id,
isUser: false,
hasChildren: canExpand,
isLoaded: hasSubOrgs || hasUsers, // 有子组织或用户的节点视为已加载
children: children.length > 0 ? children : undefined
};
});
}
/**
* 将用户信息转换为树节点格式
* @param user 用户信息
* @returns 树节点
*/
export function convertUserToTreeNode(user: UserInfo): TreeNodeItem {
return {
label: user.nick_name,
value: `user_${user.id}`,
isUser: true,
hasChildren: false,
userInfo: user
};
}
/**
* 将搜索结果转换为树节点列表
* @param users 用户列表
* @returns 树节点列表
*/
export function convertSearchResultsToTreeNodes(users: UserInfo[]): TreeNodeItem[] {
return users.map(user => convertUserToTreeNode(user));
}
// 树节点类型(用于 MultiCascader 组件)
export interface TreeNodeItem {
label: string;
value: string;
isUser: boolean;
hasChildren: boolean;
userInfo?: UserInfo;
children?: TreeNodeItem[];
}
/**
* 获取扁平化组织列表
* @param includeUsers 是否包含用户信息
@@ -194,13 +353,13 @@ export function convertToTreeData(organizations: OrganizationNode[]): Array<{
*/
export async function getFlatOrganizations(includeUsers: boolean = true): Promise<ApiResponse<OrganizationResponse>> {
try {
console.log('开始调用获取扁平化组织列表API');
// console.log('开始调用获取扁平化组织列表API');
const response = await get<OrganizationResponse>(
`/admin/users/organizations/flat?include_users=${includeUsers}`
);
console.log('扁平化组织列表API响应:', response);
// console.log('扁平化组织列表API响应:', response);
if (response.error) {
console.error('获取扁平化组织列表失败:', response.error);