refactor: align document type page with root groups
This commit is contained in:
@@ -1032,11 +1032,15 @@ function buildFallbackRoutes(roleKey: string): {
|
||||
};
|
||||
}
|
||||
|
||||
function isLegacyRuleSetsMenu(path: string | undefined): boolean {
|
||||
return path === '/rules/sets';
|
||||
}
|
||||
|
||||
function normalizeMenuStructure(menuItems: MenuItem[]): MenuItem[] {
|
||||
const clonedMenuItems = menuItems.map(item => ({
|
||||
...item,
|
||||
children: item.children ? normalizeMenuStructure(item.children) : undefined,
|
||||
}));
|
||||
})).filter(item => !isLegacyRuleSetsMenu(item.path));
|
||||
|
||||
const collectDescendantPaths = (items: MenuItem[] | undefined): string[] => {
|
||||
if (!items || items.length === 0) {
|
||||
|
||||
@@ -16,6 +16,36 @@ export interface DocumentType {
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface DocumentTypeRoot {
|
||||
id: number;
|
||||
name: string;
|
||||
code: string;
|
||||
description: string | null;
|
||||
entryModuleId: number | null;
|
||||
entryModuleName?: string | null;
|
||||
isEnabled: boolean;
|
||||
childGroupCount: number;
|
||||
ruleSetCount: number;
|
||||
ruleSetIds: number[];
|
||||
}
|
||||
|
||||
export interface DocumentTypeRootCreateDTO {
|
||||
code: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
entryModuleId?: number | null;
|
||||
isEnabled?: boolean;
|
||||
sortOrder?: number;
|
||||
}
|
||||
|
||||
export interface DocumentTypeRootUpdateDTO {
|
||||
name?: string;
|
||||
description?: string;
|
||||
entryModuleId?: number | null;
|
||||
isEnabled?: boolean;
|
||||
sortOrder?: number;
|
||||
}
|
||||
|
||||
export interface DocumentTypeCreateDTO {
|
||||
code: string;
|
||||
name: string;
|
||||
@@ -273,3 +303,123 @@ export async function getRuleSets(
|
||||
return { error: error instanceof Error ? error.message : "获取规则集失败" };
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDocumentTypeRoots(
|
||||
searchParams: { entry_module_id?: number } = {},
|
||||
token?: string,
|
||||
): Promise<{ data?: { types: DocumentTypeRoot[]; total: number }; error?: string; status?: number }> {
|
||||
try {
|
||||
const params: Record<string, number> = {};
|
||||
if (searchParams.entry_module_id) params.entry_module_id = searchParams.entry_module_id;
|
||||
const response = await axios.get(`${API_BASE_URL}/api/v3/document-type-roots`, {
|
||||
params,
|
||||
headers: authHeaders(token),
|
||||
});
|
||||
const items = extractData<any[]>(response) || [];
|
||||
const types: DocumentTypeRoot[] = items.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
code: item.code,
|
||||
description: item.description || null,
|
||||
entryModuleId: item.entryModuleId || null,
|
||||
entryModuleName: item.entryModuleName || null,
|
||||
isEnabled: item.isEnabled !== false,
|
||||
childGroupCount: Number(item.childGroupCount || 0),
|
||||
ruleSetCount: Number(item.ruleSetCount || 0),
|
||||
ruleSetIds: item.ruleSetIds || [],
|
||||
}));
|
||||
return { data: { types, total: types.length } };
|
||||
} catch (error) {
|
||||
return { error: error instanceof Error ? error.message : "获取一级文档类型失败", status: 500 };
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDocumentTypeRoot(
|
||||
id: number,
|
||||
token?: string,
|
||||
): Promise<{ data?: DocumentTypeRoot; error?: string; status?: number }> {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/api/v3/document-type-roots/${id}`, {
|
||||
headers: authHeaders(token),
|
||||
});
|
||||
const item = extractData<any>(response);
|
||||
if (!item) return { error: "一级文档类型不存在", status: 404 };
|
||||
return {
|
||||
data: {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
code: item.code,
|
||||
description: item.description || null,
|
||||
entryModuleId: item.entryModuleId || null,
|
||||
entryModuleName: item.entryModuleName || null,
|
||||
isEnabled: item.isEnabled !== false,
|
||||
childGroupCount: Number(item.childGroupCount || 0),
|
||||
ruleSetCount: Number(item.ruleSetCount || 0),
|
||||
ruleSetIds: item.ruleSetIds || [],
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
return { error: error instanceof Error ? error.message : "获取一级文档类型失败", status: 500 };
|
||||
}
|
||||
}
|
||||
|
||||
export async function createDocumentTypeRoot(
|
||||
dto: DocumentTypeRootCreateDTO,
|
||||
token?: string,
|
||||
): Promise<{ data?: DocumentTypeRoot; error?: string; status?: number }> {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/api/v3/document-type-roots`, dto, {
|
||||
headers: { ...authHeaders(token), "Content-Type": "application/json" },
|
||||
});
|
||||
const item = extractData<any>(response);
|
||||
if (!item) return { error: "创建失败", status: 500 };
|
||||
return {
|
||||
data: {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
code: item.code,
|
||||
description: item.description || null,
|
||||
entryModuleId: item.entryModuleId || null,
|
||||
entryModuleName: item.entryModuleName || null,
|
||||
isEnabled: item.isEnabled !== false,
|
||||
childGroupCount: Number(item.childGroupCount || 0),
|
||||
ruleSetCount: Number(item.ruleSetCount || 0),
|
||||
ruleSetIds: item.ruleSetIds || [],
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
const msg = (error as any)?.response?.data?.message || (error instanceof Error ? error.message : "创建失败");
|
||||
return { error: msg, status: (error as any)?.response?.status || 500 };
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateDocumentTypeRoot(
|
||||
id: number,
|
||||
dto: DocumentTypeRootUpdateDTO,
|
||||
token?: string,
|
||||
): Promise<{ data?: DocumentTypeRoot; error?: string; status?: number }> {
|
||||
try {
|
||||
const response = await axios.put(`${API_BASE_URL}/api/v3/document-type-roots/${id}`, dto, {
|
||||
headers: { ...authHeaders(token), "Content-Type": "application/json" },
|
||||
});
|
||||
const item = extractData<any>(response);
|
||||
if (!item) return { error: "更新失败", status: 500 };
|
||||
return {
|
||||
data: {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
code: item.code,
|
||||
description: item.description || null,
|
||||
entryModuleId: item.entryModuleId || null,
|
||||
entryModuleName: item.entryModuleName || null,
|
||||
isEnabled: item.isEnabled !== false,
|
||||
childGroupCount: Number(item.childGroupCount || 0),
|
||||
ruleSetCount: Number(item.ruleSetCount || 0),
|
||||
ruleSetIds: item.ruleSetIds || [],
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
const msg = (error as any)?.response?.data?.message || (error instanceof Error ? error.message : "更新失败");
|
||||
return { error: msg, status: (error as any)?.response?.status || 500 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user