Commit 56dac057 by yuananting

feat:分类查询

parent 8b5aea7c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-02-23 18:28:50 * @Date: 2021-02-23 18:28:50
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-03-15 15:14:10 * @LastEditTime: 2021-03-18 18:13:26
* @Description: 助学工具-题库-主页面分类管理 * @Description: 助学工具-题库-主页面分类管理
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -51,12 +51,24 @@ class QuestionCategoryManage extends Component { ...@@ -51,12 +51,24 @@ class QuestionCategoryManage extends Component {
}; };
QuestionBankService.queryCategoryTree(query).then((res) => { QuestionBankService.queryCategoryTree(query).then((res) => {
const { result = [] } = res; const { result = [] } = res;
const defaultNode = { id: "0", categoryName: "未分类", categoryCount: 0 }; let str = "未分类";
if (categoryName && str.indexOf(categoryName) < 0) {
this.setState({ treeData: this.renderTreeNodes(result, categoryName) });
this.setState({
expandedKeys: this.getFirstLevelKeys(result),
});
} else {
const defaultNode = {
id: "0",
categoryName: "未分类",
categoryCount: 0,
};
result.unshift(defaultNode); result.unshift(defaultNode);
this.setState({ treeData: this.renderTreeNodes(result, categoryName) }); this.setState({ treeData: this.renderTreeNodes(result, categoryName) });
this.setState({ this.setState({
expandedKeys: this.getFirstLevelKeys(result), expandedKeys: this.getFirstLevelKeys(result),
}); });
}
}); });
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-02-22 10:59:43 * @Date: 2021-02-22 10:59:43
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-03-18 09:33:50 * @LastEditTime: 2021-03-18 18:16:16
* @Description: 助学工具-题库-题库主页面侧边栏 * @Description: 助学工具-题库-题库主页面侧边栏
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -19,7 +19,9 @@ class QuestionBankSider extends Component { ...@@ -19,7 +19,9 @@ class QuestionBankSider extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
selectedKeys: getParameterByName("categoryId") ? [getParameterByName("categoryId")] : ["0"], selectedKeys: getParameterByName("categoryId")
? [getParameterByName("categoryId")]
: ["0"],
searchValue: null, searchValue: null,
NewEditQuestionBankCategory: null, //新增或编辑分类模态框 NewEditQuestionBankCategory: null, //新增或编辑分类模态框
ImportCourseCategory: null, // 引用课程分类模态框 ImportCourseCategory: null, // 引用课程分类模态框
...@@ -29,13 +31,19 @@ class QuestionBankSider extends Component { ...@@ -29,13 +31,19 @@ class QuestionBankSider extends Component {
componentDidMount() { componentDidMount() {
this.queryCategoryTree(); this.queryCategoryTree();
this.props.getSelectedCategoryId(getParameterByName("categoryId") ? [getParameterByName("categoryId")] : ["0"],) this.props.getSelectedCategoryId(
getParameterByName("categoryId")
? [getParameterByName("categoryId")]
: ["0"]
);
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
const { updatedCategoryId } = nextProps; const { updatedCategoryId } = nextProps;
if (this.props.updatedCategoryId !== updatedCategoryId) { if (this.props.updatedCategoryId !== updatedCategoryId) {
this.setState({ selectedKeys: [updatedCategoryId] }, () => this.queryCategoryTree()); this.setState({ selectedKeys: [updatedCategoryId] }, () =>
this.queryCategoryTree()
);
} }
return true; return true;
} }
...@@ -59,7 +67,7 @@ class QuestionBankSider extends Component { ...@@ -59,7 +67,7 @@ class QuestionBankSider extends Component {
/** 树状选中事件 */ /** 树状选中事件 */
onSelect = (selectedKeys) => { onSelect = (selectedKeys) => {
this.setState({ selectedKeys }); this.setState({ selectedKeys });
this.props.getSelectedCategoryId(selectedKeys) this.props.getSelectedCategoryId(selectedKeys);
}; };
// 查询分类树 // 查询分类树
...@@ -72,12 +80,29 @@ class QuestionBankSider extends Component { ...@@ -72,12 +80,29 @@ class QuestionBankSider extends Component {
}; };
QuestionBankService.queryQuestionCategoryTree(query).then((res) => { QuestionBankService.queryQuestionCategoryTree(query).then((res) => {
const { categoryList = [], noCategoryCnt = 0 } = res.result; const { categoryList = [], noCategoryCnt = 0 } = res.result;
const defaultNode = { id: "0", categoryName:"未分类", categoryCount: noCategoryCnt}
let str = "未分类";
if (categoryName && str.indexOf(categoryName) < 0) {
this.setState({
treeData: this.renderTreeNodes(categoryList, categoryName),
});
this.setState({
expandedKeys: this.getFirstLevelKeys(categoryList),
});
} else {
const defaultNode = {
id: "0",
categoryName: "未分类",
categoryCount: noCategoryCnt,
};
categoryList.unshift(defaultNode); categoryList.unshift(defaultNode);
this.setState({ treeData: this.renderTreeNodes(categoryList, categoryName) }); this.setState({
treeData: this.renderTreeNodes(categoryList, categoryName),
});
this.setState({ this.setState({
expandedKeys: this.getFirstLevelKeys(categoryList), expandedKeys: this.getFirstLevelKeys(categoryList),
}); });
}
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment