mirror of
https://github.com/PlayEdu/backend
synced 2025-06-28 13:04:40 +08:00
学员、线上课编辑优化
This commit is contained in:
parent
bd6eb030b3
commit
d817df35bf
@ -4,7 +4,6 @@ import styles from "./create.module.less";
|
||||
import { course, department } from "../../api/index";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { UploadImageButton, BackBartment } from "../../compenents";
|
||||
const { SHOW_CHILD } = Cascader;
|
||||
|
||||
interface Option {
|
||||
value: string | number;
|
||||
@ -155,30 +154,20 @@ export const CourseCreatePage: React.FC = () => {
|
||||
<Form.Item label="显示课程" name="isShow" valuePropName="checked">
|
||||
<Switch onChange={onChange} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员部门"
|
||||
name="dep_ids"
|
||||
rules={[{ required: true, message: "请选择学员部门!" }]}
|
||||
>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
showCheckedStrategy={SHOW_CHILD}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="资源分类"
|
||||
name="category_ids"
|
||||
rules={[{ required: true, message: "请选择资源分类!" }]}
|
||||
>
|
||||
<Form.Item label="资源分类" name="category_ids">
|
||||
<Cascader
|
||||
options={categories}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择资源分类"
|
||||
showCheckedStrategy={SHOW_CHILD}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
||||
|
@ -21,21 +21,17 @@ export const CourseUpdatePage: React.FC = () => {
|
||||
const [thumb, setThumb] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
getCategory();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getDetail();
|
||||
}, [params.cid]);
|
||||
|
||||
const getParams = () => {
|
||||
const getParams = (cats: any) => {
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
getDetail(departments, cats);
|
||||
});
|
||||
};
|
||||
|
||||
@ -47,6 +43,7 @@ export const CourseUpdatePage: React.FC = () => {
|
||||
setCategories(new_arr);
|
||||
}
|
||||
form.setFieldsValue({ isShow: 1 });
|
||||
getParams(categories);
|
||||
});
|
||||
};
|
||||
|
||||
@ -70,24 +67,71 @@ export const CourseUpdatePage: React.FC = () => {
|
||||
return arr;
|
||||
};
|
||||
|
||||
const getDetail = () => {
|
||||
const getDetail = (deps: any, cats: any) => {
|
||||
course.course(Number(params.cid)).then((res: any) => {
|
||||
let data = res.data.course;
|
||||
// let depIds=res.data.dep_ids;
|
||||
// for (let i = 0; i < depIds.length; i++) {
|
||||
// dep_ids.push(depIds[i]);
|
||||
// }
|
||||
let box = res.data.dep_ids;
|
||||
let depIds: any[] = [];
|
||||
if (box.length > 1) {
|
||||
for (let i = 0; i < box.length; i++) {
|
||||
let item = checkChild(deps, box[i]);
|
||||
let arr: any[] = [];
|
||||
if (item.parent_chain === "") {
|
||||
arr.push(box[i]);
|
||||
} else {
|
||||
let new_arr = item.parent_chain.split(",");
|
||||
new_arr.map((num: any) => {
|
||||
arr.push(Number(num));
|
||||
});
|
||||
arr.push(box[i]);
|
||||
}
|
||||
depIds.push(arr);
|
||||
}
|
||||
} else {
|
||||
depIds = res.data.dep_ids;
|
||||
}
|
||||
let box2 = res.data.category_ids;
|
||||
let categoryIds: any[] = [];
|
||||
if (box2.length > 1) {
|
||||
for (let i = 0; i < box2.length; i++) {
|
||||
let item = checkChild(cats, box2[i]);
|
||||
let arr: any[] = [];
|
||||
if (item.parent_chain === "") {
|
||||
arr.push(box2[i]);
|
||||
} else {
|
||||
let new_arr = item.parent_chain.split(",");
|
||||
new_arr.map((num: any) => {
|
||||
arr.push(Number(num));
|
||||
});
|
||||
arr.push(box2[i]);
|
||||
}
|
||||
categoryIds.push(arr);
|
||||
}
|
||||
} else {
|
||||
categoryIds = res.data.category_ids;
|
||||
}
|
||||
|
||||
form.setFieldsValue({
|
||||
title: data.title,
|
||||
thumb: data.thumb,
|
||||
isShow: data.is_show,
|
||||
dep_ids: res.data.dep_ids,
|
||||
category_ids: res.data.category_ids,
|
||||
dep_ids: depIds,
|
||||
category_ids: categoryIds,
|
||||
});
|
||||
setThumb(data.thumb);
|
||||
});
|
||||
};
|
||||
|
||||
const checkChild = (departments: any[], id: number) => {
|
||||
for (let key in departments) {
|
||||
for (let i = 0; i < departments[key].length; i++) {
|
||||
if (departments[key][i].id === id) {
|
||||
return departments[key][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
console.log("Success:", values);
|
||||
let id = Number(params.cid);
|
||||
@ -128,7 +172,6 @@ export const CourseUpdatePage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Row className="playedu-main-body">
|
||||
@ -181,24 +224,15 @@ export const CourseUpdatePage: React.FC = () => {
|
||||
<Form.Item label="显示课程" name="isShow" valuePropName="checked">
|
||||
<Switch onChange={onChange} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员部门"
|
||||
name="dep_ids"
|
||||
rules={[{ required: true, message: "请选择学员部门!" }]}
|
||||
>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="资源分类"
|
||||
name="category_ids"
|
||||
rules={[{ required: true, message: "请选择资源分类!" }]}
|
||||
>
|
||||
<Form.Item label="资源分类" name="category_ids">
|
||||
<Cascader
|
||||
options={categories}
|
||||
multiple
|
||||
|
@ -145,11 +145,7 @@ export const MemberCreatePage: React.FC = () => {
|
||||
>
|
||||
<Input placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员部门"
|
||||
name="dep_ids"
|
||||
rules={[{ required: true, message: "请选择学员部门!" }]}
|
||||
>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
|
@ -21,9 +21,6 @@ export const MemberUpdatePage: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
getDetail();
|
||||
}, [params.memberId]);
|
||||
|
||||
const getParams = () => {
|
||||
@ -33,24 +30,55 @@ export const MemberUpdatePage: React.FC = () => {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
getDetail(departments);
|
||||
});
|
||||
};
|
||||
|
||||
const getDetail = () => {
|
||||
const getDetail = (deps: any) => {
|
||||
user.user(Number(params.memberId)).then((res: any) => {
|
||||
let user = res.data.user;
|
||||
setAvatar(user.avatar);
|
||||
let box = res.data.dep_ids;
|
||||
let depIds: any[] = [];
|
||||
if (box.length > 1) {
|
||||
for (let i = 0; i < box.length; i++) {
|
||||
let item = checkChild(deps, box[i]);
|
||||
let arr: any[] = [];
|
||||
if (item.parent_chain === "") {
|
||||
arr.push(box[i]);
|
||||
} else {
|
||||
let new_arr = item.parent_chain.split(",");
|
||||
new_arr.map((num: any) => {
|
||||
arr.push(Number(num));
|
||||
});
|
||||
arr.push(box[i]);
|
||||
}
|
||||
depIds.push(arr);
|
||||
}
|
||||
} else {
|
||||
depIds = res.data.dep_ids;
|
||||
}
|
||||
form.setFieldsValue({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
avatar: user.avatar,
|
||||
idCard: user.id_card,
|
||||
dep_ids: res.data.dep_ids,
|
||||
dep_ids: depIds,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkChild = (departments: any[], id: number) => {
|
||||
for (let key in departments) {
|
||||
for (let i = 0; i < departments[key].length; i++) {
|
||||
if (departments[key][i].id === id) {
|
||||
return departments[key][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
@ -76,7 +104,11 @@ export const MemberUpdatePage: React.FC = () => {
|
||||
let id = Number(params.memberId);
|
||||
const arr = [];
|
||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
if (Array.isArray(values.dep_ids[i])) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
} else {
|
||||
arr.push(values.dep_ids[i]);
|
||||
}
|
||||
}
|
||||
user
|
||||
.updateUser(
|
||||
@ -170,11 +202,7 @@ export const MemberUpdatePage: React.FC = () => {
|
||||
>
|
||||
<Input placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员部门"
|
||||
name="dep_ids"
|
||||
rules={[{ required: true, message: "请选择学员部门!" }]}
|
||||
>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
|
@ -54,6 +54,7 @@ export const ResourceCategoryUpdatePage: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const checkArr = (categories: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < categories[id].length; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user