Commit de92f985 by yuananting

feat:编辑预览接口联调

parent 8bde2114
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-03-03 15:13:12 * @Date: 2021-03-03 15:13:12
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-04-01 15:36:48 * @LastEditTime: 2021-04-02 14:12:49
* @Description: 助学工具接口 * @Description: 助学工具接口
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -72,3 +72,7 @@ export function queryPaperDetail(params: object) { ...@@ -72,3 +72,7 @@ export function queryPaperDetail(params: object) {
export function viewPaper(params: object) { export function viewPaper(params: object) {
return Service.Hades("public/hades/viewPaper", params); return Service.Hades("public/hades/viewPaper", params);
} }
export function editPaper(params: object) {
return Service.Hades("public/hades/editPaper", params);
}
\ No newline at end of file
...@@ -2,11 +2,29 @@ ...@@ -2,11 +2,29 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-03-11 11:34:37 * @Date: 2021-03-11 11:34:37
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-04-01 20:09:12 * @LastEditTime: 2021-04-02 14:14:06
* @Description: 助学工具接口 * @Description: 助学工具接口
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
import { queryCategoryTree, addCategory, delCategory, editCategory, editCategoryTree, addQuestion, queryQuestionPageList, deleteQuestion, queryQuestionDetails, editQuestion, batchImport, createPaper, queryPaperPageList, deletePaper, queryPaperDetail, viewPaper } from '@/data-source/aidTool/request-apis'; import {
queryCategoryTree,
addCategory,
delCategory,
editCategory,
editCategoryTree,
addQuestion,
queryQuestionPageList,
deleteQuestion,
queryQuestionDetails,
editQuestion,
batchImport,
createPaper,
queryPaperPageList,
deletePaper,
queryPaperDetail,
viewPaper,
editPaper
} from '@/data-source/aidTool/request-apis';
export default class AidToolService { export default class AidToolService {
// 获取题目分类树 // 获取题目分类树
static queryCategoryTree(params: any) { static queryCategoryTree(params: any) {
...@@ -87,4 +105,9 @@ export default class AidToolService { ...@@ -87,4 +105,9 @@ export default class AidToolService {
static viewPaper(params: any) { static viewPaper(params: any) {
return viewPaper(params); return viewPaper(params);
} }
// 编辑试卷
static editPaper(params: any) {
return editPaper(params);
}
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-03-27 16:15:13 * @Date: 2021-03-27 16:15:13
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-04-02 10:51:10 * @LastEditTime: 2021-04-02 17:23:23
* @Description: 助学工具-新建试卷 * @Description: 助学工具-新建试卷
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -45,6 +45,11 @@ class NewExaminationPaper extends Component { ...@@ -45,6 +45,11 @@ class NewExaminationPaper extends Component {
judgeCnt: 0, // 判断题数量 judgeCnt: 0, // 判断题数量
gapFillingCnt: 0, // 填空题数量 gapFillingCnt: 0, // 填空题数量
indefiniteChoiceCnt: 0, // 不定项选择题数量 indefiniteChoiceCnt: 0, // 不定项选择题数量
singleChoiceScore: 0, // 单选题目总分
multiChoiceScore: 0, // 多选题目总分
judgeScore: 0, // 判断题目总分
gapFillingScore: 0, // 填空题目总分
indefiniteChoiceScore: 0, //不定项选择总分
paperName: null, // 试卷名称 paperName: null, // 试卷名称
passRate: 60, // 及格线 passRate: 60, // 及格线
passScore: 0, // 及格分 passScore: 0, // 及格分
...@@ -65,6 +70,8 @@ class NewExaminationPaper extends Component { ...@@ -65,6 +70,8 @@ class NewExaminationPaper extends Component {
// 编辑 // 编辑
this.setState({ currentOperate: "edit" }); this.setState({ currentOperate: "edit" });
this.queryPaperDetail(); this.queryPaperDetail();
} else {
this.setState({ currentOperate: "new" });
} }
} }
...@@ -72,16 +79,24 @@ class NewExaminationPaper extends Component { ...@@ -72,16 +79,24 @@ class NewExaminationPaper extends Component {
queryPaperDetail = () => { queryPaperDetail = () => {
let query = { let query = {
categoryId: getParameterByName("categoryId"), categoryId: getParameterByName("categoryId"),
paperId:getParameterByName("paperId"), paperId: getParameterByName("paperId"),
source: 0, source: 0,
userId: User.getStoreUserId(), userId: User.getStoreUserId(),
tenantId: User.getStoreId(), tenantId: User.getStoreId(),
}; };
AidToolService.queryPaperDetail(query).then((res) => { AidToolService.queryPaperDetail(query).then((res) => {
const { result } = res; const { result } = res;
this.setState({ selectQuestionList: result.questionList, formData: result, },() => { const { paperName, passRate } = result;
this.setFormData([]) this.setState(
}) { selectQuestionList: result.questionList, formData: result },
() => {
this.formRef.current.setFieldsValue({
paperName,
passRate,
});
this.setFormData([]);
}
);
}); });
}; };
...@@ -103,35 +118,66 @@ class NewExaminationPaper extends Component { ...@@ -103,35 +118,66 @@ class NewExaminationPaper extends Component {
setFormData = (list) => { setFormData = (list) => {
const { formData, selectQuestionList } = this.state; const { formData, selectQuestionList } = this.state;
const _selectQuestionList = [...selectQuestionList, ...list]; const _selectQuestionList = [...new Set([...selectQuestionList, ...list])];
const totalScore = _selectQuestionList.reduce((prev, cur) => { console.log(_selectQuestionList)
return prev + Number(cur.score) || 0;
}, 0); // 各类型题目汇总
const passScore = Math.round(totalScore * formData.passRate * 0.01); const singleQuestion = _.filter(
this.setState({
selectQuestionList: _selectQuestionList,
formData: {
...formData,
singleChoiceCnt: _.filter(
_selectQuestionList, _selectQuestionList,
(item) => item.questionType === "SINGLE_CHOICE" (item) => item.questionType === "SINGLE_CHOICE"
).length, );
multiChoiceCnt: _.filter( const multiQuestion = _.filter(
_selectQuestionList, _selectQuestionList,
(item) => item.questionType === "MULTI_CHOICE" (item) => item.questionType === "MULTI_CHOICE"
).length, );
judgeCnt: _.filter( const judgeQuestion = _.filter(
_selectQuestionList, _selectQuestionList,
(item) => item.questionType === "JUDGE" (item) => item.questionType === "JUDGE"
).length, );
gapFillingCnt: _.filter( const gapQuestion = _.filter(
_selectQuestionList, _selectQuestionList,
(item) => item.questionType === "GAP_FILLING" (item) => item.questionType === "GAP_FILLING"
).length, );
indefiniteChoiceCnt: _.filter( const indefiniteQuestion = _.filter(
_selectQuestionList, _selectQuestionList,
(item) => item.questionType === "INDEFINITE_CHOICE" (item) => item.questionType === "INDEFINITE_CHOICE"
).length, );
// 各类型题目总分值
const singleChoiceScore = singleQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const multiChoiceScore = multiQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const judgeScore = judgeQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const gapFillingScore = gapQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const indefiniteChoiceScore = indefiniteQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const totalScore = _selectQuestionList.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const passScore = Math.round(totalScore * formData.passRate * 0.01);
this.setState({
selectQuestionList: _selectQuestionList,
formData: {
...formData,
singleChoiceCnt: singleQuestion.length,
multiChoiceCnt: multiQuestion.length,
judgeCnt: judgeQuestion.length,
gapFillingCnt: gapQuestion.length,
indefiniteChoiceCnt: indefiniteQuestion.length,
singleChoiceScore,
multiChoiceScore,
judgeScore,
gapFillingScore,
indefiniteChoiceScore,
passScore, passScore,
questionCnt: _selectQuestionList.length, questionCnt: _selectQuestionList.length,
totalScore, totalScore,
...@@ -143,6 +189,7 @@ class NewExaminationPaper extends Component { ...@@ -143,6 +189,7 @@ class NewExaminationPaper extends Component {
chooseQuestion = () => { chooseQuestion = () => {
const m = ( const m = (
<SelectQuestionModal <SelectQuestionModal
getSelectedQuestion={this.state.selectQuestionList}
setSelectedQuestion={(list) => { setSelectedQuestion={(list) => {
this.setFormData(list); this.setFormData(list);
this.setState({ selectQuestionModal: null }); this.setState({ selectQuestionModal: null });
...@@ -162,16 +209,18 @@ class NewExaminationPaper extends Component { ...@@ -162,16 +209,18 @@ class NewExaminationPaper extends Component {
const { selectQuestionList } = this.state; const { selectQuestionList } = this.state;
const item = selectQuestionList.splice(index + moveLength, 1); const item = selectQuestionList.splice(index + moveLength, 1);
selectQuestionList.splice(index, 0, item[0]); selectQuestionList.splice(index, 0, item[0]);
this.setState({ selectQuestionList }); this.setState({ selectQuestionList }, () =>
this.setFormData([])
);
}; };
// 移除已选题目 // 移除已选题目
handleDelItem = (delId) => { handleDelItem = (delQuestionId) => {
const { selectQuestionList } = this.state; const { selectQuestionList } = this.state;
this.setState( this.setState(
{ {
selectQuestionList: [...selectQuestionList].filter( selectQuestionList: [...selectQuestionList].filter(
(item) => item.id !== delId (item) => item.questionId !== delQuestionId
), ),
}, },
() => this.setFormData([]) () => this.setFormData([])
...@@ -182,13 +231,13 @@ class NewExaminationPaper extends Component { ...@@ -182,13 +231,13 @@ class NewExaminationPaper extends Component {
saveExaminationPaper = async () => { saveExaminationPaper = async () => {
try { try {
await this.formRef.current.validateFields(); await this.formRef.current.validateFields();
const { selectQuestionList, formData } = this.state; const { selectQuestionList, formData, currentOperate } = this.state;
let questionList = []; let questionList = [];
selectQuestionList.forEach((item, index) => { selectQuestionList.forEach((item, index) => {
questionList.push({ questionList.push({
categoryId: item.categoryId, categoryId: item.categoryId,
portionScore: item.portionScore || 0, portionScore: item.portionScore || 0,
questionId: item.id, questionId: item.questionId,
questionType: item.questionType, questionType: item.questionType,
score: item.score || 2, score: item.score || 2,
sort: index, sort: index,
...@@ -202,15 +251,33 @@ class NewExaminationPaper extends Component { ...@@ -202,15 +251,33 @@ class NewExaminationPaper extends Component {
}, },
}, },
() => { () => {
if (currentOperate === "edit") {
AidToolService.editPaper({
...this.state.formData,
paperId: getParameterByName("paperId"),
}).then((res) => {
if (res.success) {
message.success("编辑成功");
window.RCHistory.push({
pathname: `/examination-paper-index?categoryId=${getParameterByName(
"categoryId"
)}`,
});
}
});
} else if (currentOperate === "new") {
AidToolService.createPaper(this.state.formData).then((res) => { AidToolService.createPaper(this.state.formData).then((res) => {
if (res.success){ if (res.success) {
message.success("新建成功"); message.success("新建成功");
window.RCHistory.push({ window.RCHistory.push({
pathname: `/examination-paper-index?categoryId=${getParameterByName("categoryId")}`, pathname: `/examination-paper-index?categoryId=${getParameterByName(
"categoryId"
)}`,
}); });
} }
}); });
} }
}
); );
} catch (e) { } catch (e) {
console.log(e); console.log(e);
...@@ -303,7 +370,9 @@ class NewExaminationPaper extends Component { ...@@ -303,7 +370,9 @@ class NewExaminationPaper extends Component {
this.setState( this.setState(
{ {
selectQuestionList: _selectQuestionList.map((item) => selectQuestionList: _selectQuestionList.map((item) =>
item.id === record.id ? { ...item, score: value } : item item.questionId === record.questionId
? { ...item, score: value }
: item
), ),
}, },
() => this.setFormData([]) () => this.setFormData([])
...@@ -329,14 +398,14 @@ class NewExaminationPaper extends Component { ...@@ -329,14 +398,14 @@ class NewExaminationPaper extends Component {
)}{" "} )}{" "}
<InputNumber <InputNumber
min={0} min={0}
max={record.score} max={record.score - 1}
value={record.portionScore || 0} value={record.portionScore || 0}
onChange={(value) => { onChange={(value) => {
const _selectQuestionList = [...selectQuestionList]; const _selectQuestionList = [...selectQuestionList];
this.setState( this.setState(
{ {
selectQuestionList: _selectQuestionList.map((item) => selectQuestionList: _selectQuestionList.map((item) =>
item.id === record.id item.questionId === record.questionId
? { ...item, portionScore: value } ? { ...item, portionScore: value }
: item : item
), ),
...@@ -384,7 +453,7 @@ class NewExaminationPaper extends Component { ...@@ -384,7 +453,7 @@ class NewExaminationPaper extends Component {
<div <div
className="record-operate__item" className="record-operate__item"
onClick={() => { onClick={() => {
this.handleDelItem(record.id); this.handleDelItem(record.questionId);
}} }}
> >
移除 移除
...@@ -405,50 +474,23 @@ class NewExaminationPaper extends Component { ...@@ -405,50 +474,23 @@ class NewExaminationPaper extends Component {
const { selectQuestionModal, selectQuestionList, formData } = this.state; const { selectQuestionModal, selectQuestionList, formData } = this.state;
const { const {
singleChoiceCnt,
multiChoiceCnt,
judgeCnt,
gapFillingCnt,
indefiniteChoiceCnt,
singleChoiceScore,
multiChoiceScore,
judgeScore,
gapFillingScore,
indefiniteChoiceScore,
paperName, paperName,
passRate, passRate,
passScore, passScore,
totalScore,
questionCnt, questionCnt,
totalScore,
} = formData; } = formData;
const singleQuestion = _.filter(
selectQuestionList,
(item) => item.questionType === "SINGLE_CHOICE"
);
const multiQuestion = _.filter(
selectQuestionList,
(item) => item.questionType === "MULTI_CHOICE"
);
const judgeQuestion = _.filter(
selectQuestionList,
(item) => item.questionType === "JUDGE"
);
const gapQuestion = _.filter(
selectQuestionList,
(item) => item.questionType === "GAP_FILLING"
);
const indefiniteQuestion = _.filter(
selectQuestionList,
(item) => item.questionType === "INDEFINITE_CHOICE"
);
const singleScore = singleQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const multiScore = multiQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const judgeScore = judgeQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const gapScore = gapQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
const indefiniteScore = indefiniteQuestion.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
return ( return (
<div className="page new-examination-paper"> <div className="page new-examination-paper">
<Breadcrumbs navList={"新建试卷"} goBack={() => this.handleGoBack()} /> <Breadcrumbs navList={"新建试卷"} goBack={() => this.handleGoBack()} />
...@@ -545,19 +587,15 @@ class NewExaminationPaper extends Component { ...@@ -545,19 +587,15 @@ class NewExaminationPaper extends Component {
</Button> </Button>
<div style={{ margin: "10px 0 20px" }}> <div style={{ margin: "10px 0 20px" }}>
总计{totalScore}分,共{questionCnt}题。{" "} 总计{totalScore}分,共{questionCnt}题。{" "}
{singleQuestion.length > 0 && {singleChoiceCnt > 0 &&
`单选题${singleQuestion.length}题,共 `单选题${singleChoiceCnt}题,共${singleChoiceScore}分;`}
${singleScore}分;`} {multiChoiceCnt > 0 &&
{multiQuestion.length > 0 && `多选题${multiChoiceCnt}题,共${multiChoiceScore}分;`}
`多选题${multiQuestion.length}题,共${multiScore}分;`} {judgeCnt > 0 && `判断题${judgeCnt}题,共${judgeScore}分,`}
{judgeQuestion.length > 0 && {gapFillingCnt > 0 &&
`判断题 `填空题${gapFillingCnt}题,共${gapFillingScore}分,`}
${judgeQuestion.length}题,共${judgeScore}分,`} {indefiniteChoiceCnt > 0 &&
{gapQuestion.length > 0 && `不定项选择题${indefiniteChoiceCnt}题,共${indefiniteChoiceScore}分`}
`填空题${gapQuestion.length}题,共${gapScore}
分,`}
{indefiniteQuestion.length > 0 &&
`不定项选择题${indefiniteQuestion.length}题,共${indefiniteScore}分`}
</div> </div>
<ConfigProvider renderEmpty={this.customizeRenderEmpty}> <ConfigProvider renderEmpty={this.customizeRenderEmpty}>
...@@ -572,10 +610,7 @@ class NewExaminationPaper extends Component { ...@@ -572,10 +610,7 @@ class NewExaminationPaper extends Component {
<div className="footer"> <div className="footer">
<Button>取消</Button> <Button>取消</Button>
<Button>预览</Button> <Button>预览</Button>
<Button <Button type="primary" onClick={() => this.saveExaminationPaper()}>
type="primary"
onClick={() => this.saveExaminationPaper()}
>
保存 保存
</Button> </Button>
</div> </div>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-03-27 11:15:03 * @Date: 2021-03-27 11:15:03
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-04-02 12:42:42 * @LastEditTime: 2021-04-02 15:07:17
* @Description: 助学工具-试卷-预览试卷 * @Description: 助学工具-试卷-预览试卷
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -145,7 +145,6 @@ class PaperPreviewModal extends Component { ...@@ -145,7 +145,6 @@ class PaperPreviewModal extends Component {
if (questionType === "GAP_FILLING") { if (questionType === "GAP_FILLING") {
{ {
_.map(gapFillingAnswerList, (gapItem, gapIndex) => { _.map(gapFillingAnswerList, (gapItem, gapIndex) => {
console.log("gapFillingAnswerList", gapFillingAnswerList)
const { correctAnswerList } = gapItem; const { correctAnswerList } = gapItem;
return ( return (
<div> <div>
...@@ -157,7 +156,6 @@ class PaperPreviewModal extends Component { ...@@ -157,7 +156,6 @@ class PaperPreviewModal extends Component {
); );
}); });
} }
// this.renderGapFillingAnswer(gapFillingAnswerList)
} else { } else {
const correctAnswerOption = _.filter( const correctAnswerOption = _.filter(
optionList, optionList,
...@@ -171,7 +169,7 @@ class PaperPreviewModal extends Component { ...@@ -171,7 +169,7 @@ class PaperPreviewModal extends Component {
return ( return (
<div className="answer-line__item"> <div className="answer-line__item">
<span>正确答案</span> <span>正确答案</span>
<span>{correctOptionSort.join("、")}</span> {/* <span>【{correctOptionSort.join("、")}】</span> */}
</div> </div>
); );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-03-29 10:52:26 * @Date: 2021-03-29 10:52:26
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-04-01 14:01:06 * @LastEditTime: 2021-04-02 19:41:26
* @Description: 助学工具-新建试卷-选择题目弹窗 * @Description: 助学工具-新建试卷-选择题目弹窗
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -21,6 +21,16 @@ class SelectQuestionModal extends Component { ...@@ -21,6 +21,16 @@ class SelectQuestionModal extends Component {
}; };
} }
componentDidMount() {
this.listRef.current.state.selectQuestionKeys = this.props.getSelectedQuestion.map(
(item) => {
item.id = item.questionId;
item.questionTypeEnum = item.questionType;
return item;
}
);
}
getCategoryIdFromSider = (selectedCategoryId) => { getCategoryIdFromSider = (selectedCategoryId) => {
if (selectedCategoryId && selectedCategoryId.length > 0) { if (selectedCategoryId && selectedCategoryId.length > 0) {
this.setState({ selectedCategoryId: selectedCategoryId[0] }); this.setState({ selectedCategoryId: selectedCategoryId[0] });
...@@ -37,14 +47,15 @@ class SelectQuestionModal extends Component { ...@@ -37,14 +47,15 @@ class SelectQuestionModal extends Component {
onOk={() => { onOk={() => {
this.props.setSelectedQuestion( this.props.setSelectedQuestion(
this.listRef.current.state.selectQuestionKeys.map((item) => { this.listRef.current.state.selectQuestionKeys.map((item) => {
item.questionType = item.questionTypeEnum; item.questionId = item.id || item.questionId;
item.score = 2; item.questionType = item.questionTypeEnum || item.questionType;
item.score = item.score || 2;
if ( if (
["MULTI_CHOICE", "GAP_FILLING", "INDEFINITE_CHOICE"].includes( ["MULTI_CHOICE", "GAP_FILLING", "INDEFINITE_CHOICE"].includes(
item.questionTypeEnum item.questionTypeEnum
) )
) { ) {
item.portionScore = 0; item.portionScore = item.portionScore || 0;
} }
return item; return item;
}) })
......
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