mirror of
https://github.com/PlayEdu/backend
synced 2025-06-29 03:23:12 +08:00
数据结构重构优化
This commit is contained in:
parent
cf7feffe27
commit
8c52461558
@ -51,7 +51,7 @@ const DepartmentPage = () => {
|
||||
const getData = () => {
|
||||
setLoading(true);
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
const departments: DepartmentsBoxModel = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setTreeData(new_arr);
|
||||
@ -61,7 +61,7 @@ const DepartmentPage = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const checkArr = (departments: DepartmentsBoxModel, id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
|
@ -50,7 +50,7 @@ const ResourceCategoryPage = () => {
|
||||
const getData = () => {
|
||||
setLoading(true);
|
||||
resourceCategory.resourceCategoryList().then((res: any) => {
|
||||
const categories = res.data.categories;
|
||||
const categories: CategoriesBoxModel = res.data.categories;
|
||||
if (JSON.stringify(categories) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(categories, 0);
|
||||
setTreeData(new_arr);
|
||||
@ -59,7 +59,7 @@ const ResourceCategoryPage = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const checkArr = (categories: any[], id: number) => {
|
||||
const checkArr = (categories: CategoriesBoxModel, id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < categories[id].length; i++) {
|
||||
if (!categories[categories[id][i].id]) {
|
||||
|
26
src/playedu.d.ts
vendored
26
src/playedu.d.ts
vendored
@ -47,6 +47,18 @@ declare global {
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface CategoriesBoxModel {
|
||||
[key: number]: CategoriesItemModel[];
|
||||
}
|
||||
|
||||
interface CategoriesItemModel {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_chain: string;
|
||||
parent_id: number;
|
||||
sort: number;
|
||||
}
|
||||
|
||||
interface CategoriesModel {
|
||||
[key: number]: string;
|
||||
}
|
||||
@ -62,6 +74,20 @@ declare global {
|
||||
interface CategoryIdsModel {
|
||||
[key: number]: number[];
|
||||
}
|
||||
|
||||
interface DepartmentsBoxModel {
|
||||
[key: number]: DepartmentsItemModel[];
|
||||
}
|
||||
|
||||
interface DepartmentsItemModel {
|
||||
created_at: string;
|
||||
id: number;
|
||||
name: string;
|
||||
parent_chain: string;
|
||||
parent_id: number;
|
||||
sort: number;
|
||||
updated_at: string;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user