feat: 增加二级分类及标签
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// import { Component } from 'react';
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useEffect, memo } from 'react'
|
||||
import QuestionList from '@components/question-list';
|
||||
import CategoryList from '@components/category-list';
|
||||
import ContributionList from './components/contribution-list';
|
||||
@@ -12,9 +12,8 @@ import './index.less';
|
||||
|
||||
const QuestionBank = () => {
|
||||
|
||||
|
||||
const [firstCategoryList, setFirstCategoryList] = useState([])
|
||||
const [questionList, setQuestionList] = useState(mockDataList)
|
||||
const [questionList, setQuestionList] = useState([])
|
||||
const [isShowSpin, setIsShowSpin] = useState(false)
|
||||
const [labelList, setLabelList] = useState<string[]>([]); // 选中的标签列表
|
||||
const [difficulty, setDiffculty] = useState(0); //困难度(全部)
|
||||
@@ -46,30 +45,13 @@ const QuestionBank = () => {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取大类下分类
|
||||
const getCategoryByPrimary = () => {
|
||||
req({
|
||||
method: 'post',
|
||||
url: apiName.queryCategoryByPrimary,
|
||||
data: { categoryType: 1, parentId: 1 }
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (primaryCategoryId) {
|
||||
getCategoryByPrimary()
|
||||
}
|
||||
}, [primaryCategoryId])
|
||||
|
||||
/**
|
||||
* 切换一级分类
|
||||
* @param {*} e
|
||||
*/
|
||||
const onChangeCategory = (e: string) => {
|
||||
const onChangeCategory = (item: Record<string, any>) => {
|
||||
setLabelList([])
|
||||
setPromaryCategoryId(e)
|
||||
setPromaryCategoryId(item.id)
|
||||
setPageIndex(1)
|
||||
};
|
||||
|
||||
@@ -82,11 +64,12 @@ const QuestionBank = () => {
|
||||
setLabelList(assembleIds)
|
||||
setPromaryCategoryId(primaryCategoryId)
|
||||
setPageIndex(1)
|
||||
// this.getInterviewSubjectList();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getPrimaryCategoryInfo()
|
||||
if (!primaryCategoryId) {
|
||||
getPrimaryCategoryInfo()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
@@ -99,6 +82,7 @@ const QuestionBank = () => {
|
||||
onChangeCategory={onChangeCategory}
|
||||
categoryList={firstCategoryList}
|
||||
onChangeLabel={onChangeLabel}
|
||||
primaryCategoryId={primaryCategoryId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -123,131 +107,4 @@ const QuestionBank = () => {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default QuestionBank
|
||||
// class QuestionBank extends Component {
|
||||
// constructor(props) {
|
||||
// super(props);
|
||||
// this.state = {
|
||||
// firstCategoryList: [],
|
||||
// questionList: [],
|
||||
// isShowSpin: false,
|
||||
// };
|
||||
// }
|
||||
// labelList = []; // 选中的标签列表
|
||||
// difficulty = 0; //困难度(全部)
|
||||
// total = 0; // 总条数
|
||||
// pageIndex = 1;
|
||||
// primaryCategoryId = ''; //第一个大类id
|
||||
|
||||
// componentDidMount() {
|
||||
// // this.getPrimaryCategoryInfo();
|
||||
// // console.log(this.props.route);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 获取题目列表
|
||||
// */
|
||||
// getInterviewSubjectList() {
|
||||
// let params = {
|
||||
// pageInfo: {
|
||||
// pageIndex: this.pageIndex,
|
||||
// pageSize: 10,
|
||||
// },
|
||||
// difficulty: this.difficulty,
|
||||
// primaryCategoryId: this.primaryCategoryId,
|
||||
// assembleIds: this.labelList,
|
||||
// };
|
||||
// req({
|
||||
// method: 'post',
|
||||
// data: params,
|
||||
// url: apiName.getInterviewSubjectList,
|
||||
// })
|
||||
// .then((res) => {
|
||||
// if (res.data && res.data?.pageList?.length > 0) {
|
||||
// this.total = res.data.pageInfo.total;
|
||||
// this.setState({
|
||||
// questionList: res.data.pageList,
|
||||
// isShowSpin: false,
|
||||
// });
|
||||
// } else {
|
||||
// this.total = 0;
|
||||
// this.setState({
|
||||
// questionList: [],
|
||||
// isShowSpin: false,
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// .catch((err) => console.log(err));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 切换一级分类
|
||||
// * @param {*} e
|
||||
// */
|
||||
// onChangeCategory = (e) => {
|
||||
// this.labelList = [];
|
||||
// this.primaryCategoryId = e;
|
||||
// this.pageIndex = 1;
|
||||
// this.getInterviewSubjectList();
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * 筛选列表数据
|
||||
// * @param {*} id
|
||||
// */
|
||||
// handleChangeSelect = (id) => {
|
||||
// this.difficulty = id;
|
||||
// this.pageIndex = 1;
|
||||
// this.getInterviewSubjectList();
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * 分页功能
|
||||
// * @param {*} pageIndex 当前页码
|
||||
// */
|
||||
// onChangePagination = (pageIndex) => {
|
||||
// this.pageIndex = pageIndex;
|
||||
// this.getInterviewSubjectList();
|
||||
// };
|
||||
|
||||
// render() {
|
||||
// const { firstCategoryList, questionList, isShowSpin } = this.state;
|
||||
// return (
|
||||
// <div className="question-bank-box">
|
||||
// <Spin spinning={isShowSpin}>
|
||||
// <div className="question-box">
|
||||
// <div className="category-list-box">
|
||||
// {firstCategoryList?.length > 0 && (
|
||||
// <CategoryList
|
||||
// onChangeCategory={this.onChangeCategory}
|
||||
// categoryList={firstCategoryList}
|
||||
// onChangeLabel={this.onChangeLabel}
|
||||
// />
|
||||
// )}
|
||||
// </div>
|
||||
// <div className="question-list-box">
|
||||
// <QuestionList
|
||||
// pageIndex={this.pageIndex}
|
||||
// total={this.total}
|
||||
// questionList={questionList}
|
||||
// handleChangeSelect={this.handleChangeSelect}
|
||||
// onChangePagination={this.onChangePagination}
|
||||
// difficulty={this.difficulty}
|
||||
// primaryCategoryId={this.primaryCategoryId}
|
||||
// labelList={this.labelList}
|
||||
// />
|
||||
// </div>
|
||||
// </div>
|
||||
// </Spin>
|
||||
// <div className="ranking-box">
|
||||
// <ContributionList />
|
||||
// <RankingList />
|
||||
// </div>
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
export default memo(QuestionBank)
|
||||
|
Reference in New Issue
Block a user