提交 248c88a7 作者: ZhangLingKun

功能:课程问题修复

上级 4f04636a
...@@ -20,17 +20,21 @@ export type queryCurriculumInfoListType = InterListFunction< ...@@ -20,17 +20,21 @@ export type queryCurriculumInfoListType = InterListFunction<
supplierName: string; supplierName: string;
surfaceUrl: null; surfaceUrl: null;
videoUrl: string; videoUrl: string;
categoriesId: number;
directoryName: null;
categoriesName: null;
} }
>; >;
// V1.0.1新增课程 // V1.0.1新增课程
export type addCurriculumType = InterFunction< export type addCurriculumType = InterFunction<
{ {
categoriesId?: number;
categoriesName?: string;
curriculumDesc?: string; curriculumDesc?: string;
curriculumName?: string; curriculumName?: string;
detailContent?: string; detailContent?: string;
directoryName?: string;
flightSkills?: number; flightSkills?: number;
flightSkillsName1?: string;
flightSkillsName2?: string;
free?: number; free?: number;
id?: number | null; id?: number | null;
price?: number; price?: number;
...@@ -79,16 +83,16 @@ export type queryCategoryInfoByType = InterFunction< ...@@ -79,16 +83,16 @@ export type queryCategoryInfoByType = InterFunction<
/** /**
* 类型:1:作业服务 2:设备 3:培训 4:产品商城 * 类型:1:作业服务 2:设备 3:培训 4:产品商城
*/ */
type: number type: number;
}, },
{ {
directoryId: number directoryId: number;
name: string name: string;
categoriesInfoListDTO: Array<{ categoriesInfoListDTO: Array<{
id: number id: number;
directoryId: number directoryId: number;
name: string name: string;
icon: string icon: string;
}> }>;
}[] }[]
> >;
import axios from '~/api/request'; import axios from '~/api/request';
import { import {
addCurriculumType, addCurriculumType,
queryCategoryInfoByType,
queryCurriculumInfoListType, queryCurriculumInfoListType,
removeCurriculumType, removeCurriculumType,
treeCurriculumSkillType, treeCurriculumSkillType,
...@@ -23,4 +24,8 @@ export class MallManageAPI { ...@@ -23,4 +24,8 @@ export class MallManageAPI {
// V1.0.1删除课程 // V1.0.1删除课程
static removeCurriculum: removeCurriculumType = (params) => static removeCurriculum: removeCurriculumType = (params) =>
axios.get('/release/curriculum/removeCurriculum', { 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) => { ...@@ -65,6 +65,7 @@ const AddEditModal: React.FC<propType> = (props) => {
const res = await MallManageAPI[data?.id ? 'updateCurriculum' : 'addCurriculum']({ const res = await MallManageAPI[data?.id ? 'updateCurriculum' : 'addCurriculum']({
...values, ...values,
flightSkills: Number((values?.flightSkills as unknown as number[])?.at(-1)), 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, id: data?.id ? data?.id : null,
}); });
if (res && res.code === '200') { if (res && res.code === '200') {
...@@ -74,38 +75,40 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -74,38 +75,40 @@ const AddEditModal: React.FC<propType> = (props) => {
}; };
// 获取课程类型 // 获取课程类型
const getCurriculumSkillList = async () => { const getCurriculumSkillList = async () => {
const res = await MallManageAPI.treeCurriculumSkill({}); const res = await MallManageAPI.queryCategoryInfoByType({
type: 3,
});
if (res && res.code === '200') { if (res && res.code === '200') {
setCurriculumSkillList( const arr = res.result
res.result?.map((i) => ({ ?.filter((i) => i.categoriesInfoListDTO)
label: i.skillsName, .map((i) => ({
value: i.id, label: i.name,
children: i.flightSkills?.map((j) => ({ label: j.skillsName, value: j.id })), value: i.directoryId,
})), children: i.categoriesInfoListDTO?.map((j) => ({ label: j.name, value: j.id })),
); }));
// console.log(res); setCurriculumSkillList(arr);
} // 回显数据
}; // 回显数据
// componentDidMount // 回显数据
useEffect(() => {
if (!open) return;
// 获取课程类型
getCurriculumSkillList().then(() => {
// 加载出数据再操作 // 加载出数据再操作
if (!data) return; if (!data) return;
// console.log(data);
// 反向找数据回显 // 反向找数据回显
const flightSkillsName1 = curriculumSkillList.find( const flightSkillsName1 = arr?.find((i) =>
(i) => i.label === data?.flightSkillsName1, i.children?.find((j) => j.value === data?.categoriesId),
);
const flightSkillsName2 = flightSkillsName1?.children?.find(
(i) => i.label === data?.flightSkillsName2,
); );
// 回显数据 // 回显数据
form.setFieldsValue({ form.setFieldsValue({
...data, ...data,
flightSkills: [flightSkillsName1?.value, flightSkillsName2?.value], flightSkills: [flightSkillsName1?.value, data?.categoriesId],
}); });
}); }
};
// componentDidMount
useEffect(() => {
if (!open) return;
// 获取课程类型
getCurriculumSkillList().then();
}, [open]); }, [open]);
return ( return (
<Modal <Modal
......
...@@ -17,6 +17,17 @@ let query: ReqType = {}; ...@@ -17,6 +17,17 @@ let query: ReqType = {};
const CourseManageView = () => { const CourseManageView = () => {
const { confirm } = Modal; const { confirm } = Modal;
// 课程类型列表
const [curriculumSkillList, setCurriculumSkillList] = useState<
{
value: number;
label: string;
children?: Array<{
value: number;
label: string;
}>;
}[]
>([]);
// 是否打开变更弹窗 // 是否打开变更弹窗
const [isAddEditVisModal, setIsAddEditVisModal] = useState<boolean>(false); const [isAddEditVisModal, setIsAddEditVisModal] = useState<boolean>(false);
// 表格分页配置 // 表格分页配置
...@@ -78,6 +89,23 @@ const CourseManageView = () => { ...@@ -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]> = [ const columns: ColumnsType<TableType[0]> = [
{ {
...@@ -88,10 +116,15 @@ const CourseManageView = () => { ...@@ -88,10 +116,15 @@ const CourseManageView = () => {
}, },
{ {
title: '课程类型', title: '课程类型',
dataIndex: 'flightSkillsName1', dataIndex: 'categoriesId',
align: 'center', align: 'center',
width: '150px', 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: '课程类型', title: '课程类型',
...@@ -143,6 +176,7 @@ const CourseManageView = () => { ...@@ -143,6 +176,7 @@ const CourseManageView = () => {
useEffect(() => { useEffect(() => {
query = {}; query = {};
(async () => { (async () => {
await getCurriculumSkillList();
await getTableList(); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论