Commit 2d1d10ae by yuananting

feat:题型排序,树更新

parent e75fa81d
......@@ -2,7 +2,7 @@
* @Author: yuananting
* @Date: 2021-03-27 16:15:13
* @LastEditors: yuananting
* @LastEditTime: 2021-04-14 17:45:41
* @LastEditTime: 2021-04-15 12:07:20
* @Description: 助学工具-新建/复制/编辑试卷
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -160,7 +160,7 @@ class OperatePaper extends Component {
);
};
setFormData = (list) => {
setFormData = (list, sorter) => {
const { formData } = this.state;
const _selectQuestionList = [...list];
......@@ -206,9 +206,33 @@ class OperatePaper extends Component {
return prev + Number(cur.score) || 0;
}, 0);
const sortedTableData = [
...singleQuestion,
...multiQuestion,
...indefiniteQuestion,
...judgeQuestion,
...gapQuestion,
];
let currentQuestionList = [];
switch (sorter) {
case "ascend":
currentQuestionList = sortedTableData;
break;
case "descend":
currentQuestionList = sortedTableData.reverse();
break;
case "default":
currentQuestionList = _selectQuestionList.sort((a, b) => b.updateTime - a.updateTime);
break;
default:
currentQuestionList = _selectQuestionList;
break;
}
const passScore = Math.round(totalScore * formData.passRate * 0.01);
this.setState({
selectQuestionList: _selectQuestionList,
selectQuestionList: currentQuestionList,
formData: {
...formData,
singleChoiceCnt: singleQuestion.length,
......@@ -234,8 +258,9 @@ class OperatePaper extends Component {
<SelectQuestionModal
getSelectedQuestion={this.state.selectQuestionList}
setSelectedQuestion={(list) => {
this.setFormData(list.sort((a, b) => b.updateTime - a.updateTime));
this.setState({ selectQuestionModal: null });
this.setState({ selectQuestionModal: null }, () => {
this.setFormData(list.sort((a, b) => b.updateTime - a.updateTime));
});
}}
close={() => {
this.setState({
......@@ -310,7 +335,11 @@ class OperatePaper extends Component {
const { selectQuestionList, formData, currentOperate } = this.state;
const categoryId = getParameterByName("categoryId");
let questionList = [];
if (!formData.passRate || !formData.paperName || this.checkExist(formData.paperName)) {
if (
!formData.passRate ||
!formData.paperName ||
this.checkExist(formData.paperName)
) {
return;
}
if (selectQuestionList.length === 0) {
......@@ -380,7 +409,6 @@ class OperatePaper extends Component {
categoryId,
selectQuestionList.length
);
Bus.trigger("queryCategoryTree", "remain");
}
})
.catch((e) => {
......@@ -392,7 +420,6 @@ class OperatePaper extends Component {
categoryId,
selectQuestionList.length
);
Bus.trigger("queryCategoryTree", "remain");
});
}
}
......@@ -436,6 +463,14 @@ class OperatePaper extends Component {
});
};
// 题型排序
sortByQuestionType = (pagination, filters, sorter) => {
const { columnKey, order } = sorter;
if (columnKey === "questionType") {
this.setFormData(this.state.selectQuestionList, order || "default");
}
};
// 表头设置
parseColumns = () => {
const { selectQuestionList } = this.state;
......@@ -443,6 +478,7 @@ class OperatePaper extends Component {
{
title: "序号",
dataIndex: "index",
key: "index",
width: "10%",
render: (val, record, index) => {
return <span>{index + 1}</span>;
......@@ -451,7 +487,10 @@ class OperatePaper extends Component {
{
title: "题型",
dataIndex: "questionType",
key: "questionType",
width: "16%",
sorter: true,
showSorterTooltip: false,
filters: [
{
text: "单选题",
......@@ -481,6 +520,7 @@ class OperatePaper extends Component {
{
title: "题目",
dataIndex: "questionStem",
key: "questionStem",
ellipsis: {
showTitle: false,
},
......@@ -516,6 +556,7 @@ class OperatePaper extends Component {
</Tooltip>
),
dataIndex: "score",
key: "score",
width: "12%",
render: (val, record, index) => {
return (
......@@ -542,6 +583,7 @@ class OperatePaper extends Component {
},
{
dataIndex: "portionScore",
key: "portionScore",
width: "18%",
render: (val, record, index) => {
return (
......@@ -580,6 +622,7 @@ class OperatePaper extends Component {
{
title: "操作",
dataIndex: "operate",
key: "operate",
width: "16%",
render: (val, record, index) => {
return (
......@@ -755,6 +798,7 @@ class OperatePaper extends Component {
dataSource={selectQuestionList}
bordered
pagination={false}
onChange={this.sortByQuestionType}
/>
</ConfigProvider>
</Form>
......
......@@ -2,7 +2,7 @@
* @Author: yuananting
* @Date: 2021-02-25 11:23:47
* @LastEditors: yuananting
* @LastEditTime: 2021-04-10 15:37:25
* @LastEditTime: 2021-04-15 11:04:03
* @Description: 助学工具-题库-试卷列表数据
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -88,6 +88,7 @@ class PaperList extends Component {
// 查询试卷列表
queryPaperPageList = async () => {
const res = await AidToolService.queryPaperPageList(this.state.query);
Bus.trigger("queryCategoryTree", "remain");
const { records = [], total = 0 } = res.result;
this.setState({ dataSource: records, total, loading: false });
};
......@@ -160,7 +161,6 @@ class PaperList extends Component {
}
this.setState({ query: _query }, () => {
this.queryPaperPageList();
Bus.trigger("queryCategoryTree", "remain");
});
}
});
......
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