mirror of
https://github.com/PlayEdu/backend
synced 2025-12-23 08:42:23 +08:00
线上课选择部门显示数量
This commit is contained in:
@@ -85,8 +85,9 @@ export const CourseCreate: React.FC<PropInterface> = ({
|
|||||||
const getParams = () => {
|
const getParams = () => {
|
||||||
department.departmentList().then((res: any) => {
|
department.departmentList().then((res: any) => {
|
||||||
const departments = res.data.departments;
|
const departments = res.data.departments;
|
||||||
|
const departCount = res.data.dep_user_count;
|
||||||
if (JSON.stringify(departments) !== "{}") {
|
if (JSON.stringify(departments) !== "{}") {
|
||||||
const new_arr: Option[] = checkArr(departments, 0);
|
const new_arr: any = checkArr(departments, 0, departCount);
|
||||||
setDepartments(new_arr);
|
setDepartments(new_arr);
|
||||||
}
|
}
|
||||||
let type = "open";
|
let type = "open";
|
||||||
@@ -134,7 +135,7 @@ export const CourseCreate: React.FC<PropInterface> = ({
|
|||||||
course.createCourse().then((res: any) => {
|
course.createCourse().then((res: any) => {
|
||||||
const categories = res.data.categories;
|
const categories = res.data.categories;
|
||||||
if (JSON.stringify(categories) !== "{}") {
|
if (JSON.stringify(categories) !== "{}") {
|
||||||
const new_arr: Option[] = checkArr(categories, 0);
|
const new_arr: any = checkArr(categories, 0, null);
|
||||||
setCategories(new_arr);
|
setCategories(new_arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,18 +164,39 @@ export const CourseCreate: React.FC<PropInterface> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkArr = (departments: any[], id: number) => {
|
const getNewTitle = (title: any, id: number, counts: any) => {
|
||||||
|
if (counts) {
|
||||||
|
let value = counts[id] || 0;
|
||||||
|
return title + "(" + value + ")";
|
||||||
|
} else {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkArr = (departments: any[], id: number, counts: any) => {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (let i = 0; i < departments[id].length; i++) {
|
for (let i = 0; i < departments[id].length; i++) {
|
||||||
if (!departments[departments[id][i].id]) {
|
if (!departments[departments[id][i].id]) {
|
||||||
arr.push({
|
arr.push({
|
||||||
title: departments[id][i].name,
|
title: getNewTitle(
|
||||||
|
departments[id][i].name,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
),
|
||||||
value: departments[id][i].id,
|
value: departments[id][i].id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
const new_arr: any = checkArr(
|
||||||
|
departments,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
);
|
||||||
arr.push({
|
arr.push({
|
||||||
title: departments[id][i].name,
|
title: getNewTitle(
|
||||||
|
departments[id][i].name,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
),
|
||||||
value: departments[id][i].id,
|
value: departments[id][i].id,
|
||||||
children: new_arr,
|
children: new_arr,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export const CourseUpdate: React.FC<PropInterface> = ({
|
|||||||
course.createCourse().then((res: any) => {
|
course.createCourse().then((res: any) => {
|
||||||
const categories = res.data.categories;
|
const categories = res.data.categories;
|
||||||
if (JSON.stringify(categories) !== "{}") {
|
if (JSON.stringify(categories) !== "{}") {
|
||||||
const new_arr: Option[] = checkArr(categories, 0);
|
const new_arr: any = checkArr(categories, 0, null);
|
||||||
setCategories(new_arr);
|
setCategories(new_arr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -74,8 +74,9 @@ export const CourseUpdate: React.FC<PropInterface> = ({
|
|||||||
const getParams = () => {
|
const getParams = () => {
|
||||||
department.departmentList().then((res: any) => {
|
department.departmentList().then((res: any) => {
|
||||||
const departments = res.data.departments;
|
const departments = res.data.departments;
|
||||||
|
const departCount = res.data.dep_user_count;
|
||||||
if (JSON.stringify(departments) !== "{}") {
|
if (JSON.stringify(departments) !== "{}") {
|
||||||
const new_arr: Option[] = checkArr(departments, 0);
|
const new_arr: any = checkArr(departments, 0, departCount);
|
||||||
setDepartments(new_arr);
|
setDepartments(new_arr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -101,18 +102,39 @@ export const CourseUpdate: React.FC<PropInterface> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkArr = (departments: any[], id: number) => {
|
const getNewTitle = (title: any, id: number, counts: any) => {
|
||||||
|
if (counts) {
|
||||||
|
let value = counts[id] || 0;
|
||||||
|
return title + "(" + value + ")";
|
||||||
|
} else {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkArr = (departments: any[], id: number, counts: any) => {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (let i = 0; i < departments[id].length; i++) {
|
for (let i = 0; i < departments[id].length; i++) {
|
||||||
if (!departments[departments[id][i].id]) {
|
if (!departments[departments[id][i].id]) {
|
||||||
arr.push({
|
arr.push({
|
||||||
title: departments[id][i].name,
|
title: getNewTitle(
|
||||||
|
departments[id][i].name,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
),
|
||||||
value: departments[id][i].id,
|
value: departments[id][i].id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
const new_arr: any = checkArr(
|
||||||
|
departments,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
);
|
||||||
arr.push({
|
arr.push({
|
||||||
title: departments[id][i].name,
|
title: getNewTitle(
|
||||||
|
departments[id][i].name,
|
||||||
|
departments[id][i].id,
|
||||||
|
counts
|
||||||
|
),
|
||||||
value: departments[id][i].id,
|
value: departments[id][i].id,
|
||||||
children: new_arr,
|
children: new_arr,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user