提交 248c88a7 作者: ZhangLingKun

功能:课程问题修复

上级 4f04636a
......@@ -20,17 +20,21 @@ export type queryCurriculumInfoListType = InterListFunction<
supplierName: string;
surfaceUrl: null;
videoUrl: string;
categoriesId: number;
directoryName: null;
categoriesName: null;
}
>;
// V1.0.1新增课程
export type addCurriculumType = InterFunction<
{
categoriesId?: number;
categoriesName?: string;
curriculumDesc?: string;
curriculumName?: string;
detailContent?: string;
directoryName?: string;
flightSkills?: number;
flightSkillsName1?: string;
flightSkillsName2?: string;
free?: number;
id?: number | null;
price?: number;
......@@ -79,16 +83,16 @@ export type queryCategoryInfoByType = InterFunction<
/**
* 类型:1:作业服务 2:设备 3:培训 4:产品商城
*/
type: number
type: number;
},
{
directoryId: number
name: string
directoryId: number;
name: string;
categoriesInfoListDTO: Array<{
id: number
directoryId: number
name: string
icon: string
}>
id: number;
directoryId: number;
name: string;
icon: string;
}>;
}[]
>
>;
import axios from '~/api/request';
import {
addCurriculumType,
queryCategoryInfoByType,
queryCurriculumInfoListType,
removeCurriculumType,
treeCurriculumSkillType,
......@@ -23,4 +24,8 @@ export class MallManageAPI {
// V1.0.1删除课程
static removeCurriculum: removeCurriculumType = (params) =>
axios.get('/release/curriculum/removeCurriculum', { params });
// 根据类型获取各个目录及分类信息
static queryCategoryInfoByType: queryCategoryInfoByType = (params) =>
axios.get('/pms/classify/queryCategoryInfoByType', { params });
}
......@@ -65,6 +65,7 @@ const AddEditModal: React.FC<propType> = (props) => {
const res = await MallManageAPI[data?.id ? 'updateCurriculum' : 'addCurriculum']({
...values,
flightSkills: Number((values?.flightSkills as unknown as number[])?.at(-1)),
categoriesId: Number((values?.flightSkills as unknown as number[])?.at(-1)),
id: data?.id ? data?.id : null,
});
if (res && res.code === '200') {
......@@ -74,38 +75,40 @@ const AddEditModal: React.FC<propType> = (props) => {
};
// 获取课程类型
const getCurriculumSkillList = async () => {
const res = await MallManageAPI.treeCurriculumSkill({});
const res = await MallManageAPI.queryCategoryInfoByType({
type: 3,
});
if (res && res.code === '200') {
setCurriculumSkillList(
res.result?.map((i) => ({
label: i.skillsName,
value: i.id,
children: i.flightSkills?.map((j) => ({ label: j.skillsName, value: j.id })),
})),
);
// console.log(res);
}
};
// componentDidMount
useEffect(() => {
if (!open) return;
// 获取课程类型
getCurriculumSkillList().then(() => {
const arr = res.result
?.filter((i) => i.categoriesInfoListDTO)
.map((i) => ({
label: i.name,
value: i.directoryId,
children: i.categoriesInfoListDTO?.map((j) => ({ label: j.name, value: j.id })),
}));
setCurriculumSkillList(arr);
// 回显数据
// 回显数据
// 回显数据
// 加载出数据再操作
if (!data) return;
// console.log(data);
// 反向找数据回显
const flightSkillsName1 = curriculumSkillList.find(
(i) => i.label === data?.flightSkillsName1,
);
const flightSkillsName2 = flightSkillsName1?.children?.find(
(i) => i.label === data?.flightSkillsName2,
const flightSkillsName1 = arr?.find((i) =>
i.children?.find((j) => j.value === data?.categoriesId),
);
// 回显数据
form.setFieldsValue({
...data,
flightSkills: [flightSkillsName1?.value, flightSkillsName2?.value],
flightSkills: [flightSkillsName1?.value, data?.categoriesId],
});
});
}
};
// componentDidMount
useEffect(() => {
if (!open) return;
// 获取课程类型
getCurriculumSkillList().then();
}, [open]);
return (
<Modal
......
......@@ -17,6 +17,17 @@ let query: ReqType = {};
const CourseManageView = () => {
const { confirm } = Modal;
// 课程类型列表
const [curriculumSkillList, setCurriculumSkillList] = useState<
{
value: number;
label: string;
children?: Array<{
value: number;
label: string;
}>;
}[]
>([]);
// 是否打开变更弹窗
const [isAddEditVisModal, setIsAddEditVisModal] = useState<boolean>(false);
// 表格分页配置
......@@ -78,6 +89,23 @@ const CourseManageView = () => {
},
});
};
// 获取课程类型
const getCurriculumSkillList = async () => {
const res = await MallManageAPI.queryCategoryInfoByType({
type: 3,
});
if (res && res.code === '200') {
setCurriculumSkillList(
res.result
?.filter((i) => i.categoriesInfoListDTO)
.map((i) => ({
label: i.name,
value: i.directoryId,
children: i.categoriesInfoListDTO?.map((j) => ({ label: j.name, value: j.id })),
})),
);
}
};
// 表格结构
const columns: ColumnsType<TableType[0]> = [
{
......@@ -88,10 +116,15 @@ const CourseManageView = () => {
},
{
title: '课程类型',
dataIndex: 'flightSkillsName1',
dataIndex: 'categoriesId',
align: 'center',
width: '150px',
render: (text, record) => `${text}/${record.flightSkillsName2}`,
render: (text) => {
// 反向找数据回显
const item = curriculumSkillList.find((i) => i.children?.find((j) => j.value === text));
const childrenItem = item?.children?.find((i) => i.value === text);
return `${item?.label}/${childrenItem?.label}`;
},
},
{
title: '课程类型',
......@@ -143,6 +176,7 @@ const CourseManageView = () => {
useEffect(() => {
query = {};
(async () => {
await getCurriculumSkillList();
await getTableList();
})();
}, []);
......
// 通过子节点找到整个树
export const getTreeIds = (
tree: any[],
nodeId: number,
config?: { children: string; id: string },
) => {
const { children = 'children', id = 'id' } = config || {};
// 先拍平数组
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const toFlatArray = (treeArr: any[], parentId?: any) => {
return treeArr.reduce((t, _) => {
const child = _[children];
return [
...t,
parentId ? { ..._, parentId } : _,
...(child && child.length ? toFlatArray(child, _[id]) : []),
];
}, []);
};
// 找到所有的id
const getIds = (flatArray: any[]) => {
let ids = [nodeId];
let child = flatArray.find((_) => _[id] === nodeId);
while (child && child.parentId) {
ids = [child.parentId, ...ids];
// eslint-disable-next-line no-loop-func
child = flatArray.find((_) => _[id] === child.parentId);
}
return ids;
};
// 返回找到的数据
return getIds(toFlatArray(tree));
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论