|
|
|
@ -1,23 +1,15 @@
|
|
|
|
|
/** 模拟考试 | 资质考试选题 */
|
|
|
|
|
//import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Button, InputNumber, message, Space, Form, Input} from 'antd';
|
|
|
|
|
//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout';
|
|
|
|
|
//import { useRequest } from 'umi';
|
|
|
|
|
//import { queryFakeList } from './service';
|
|
|
|
|
//import type { CardListItemDataType } from './data';
|
|
|
|
|
import styles from '../style.less';
|
|
|
|
|
//import SubMenu from 'antd/lib/menu/SubMenu';
|
|
|
|
|
//import ProCard from '@ant-design/pro-card';
|
|
|
|
|
//import ProList from '@ant-design/pro-list';
|
|
|
|
|
import { forwardRef, ReactText, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
|
|
|
//import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons';
|
|
|
|
|
import { useParams, useRequest, history, useRouteMatch } from 'umi';
|
|
|
|
|
import { queryCourseView } from '@/pages/course/option/service';
|
|
|
|
|
import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service';
|
|
|
|
|
|
|
|
|
|
import { InputNumber, Space, Form, Input} from 'antd';
|
|
|
|
|
//import styles from '../style.less';
|
|
|
|
|
import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
|
|
|
//import { useParams, useRequest, history, useRouteMatch } from 'umi';
|
|
|
|
|
//import { queryCourseView } from '@/pages/course/option/service';
|
|
|
|
|
import { queryQuestionType } from '@/pages/questionbank/service';
|
|
|
|
|
//import ProForm, { ProFormSelect } from '@ant-design/pro-form';
|
|
|
|
|
import { ActionType, EditableProTable, ProColumns } from '@ant-design/pro-table';
|
|
|
|
|
//import { ActionType, EditableProTable, ProColumns } from '@ant-design/pro-table';
|
|
|
|
|
import ProTable from '@ant-design/pro-table';
|
|
|
|
|
import ProForm from '@ant-design/pro-form';
|
|
|
|
|
//import ProForm from '@ant-design/pro-form';
|
|
|
|
|
|
|
|
|
|
export type TableListItem = {
|
|
|
|
|
id: string;
|
|
|
|
@ -33,29 +25,18 @@ export type TableListItem = {
|
|
|
|
|
|
|
|
|
|
// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。
|
|
|
|
|
const ScoreSetter = (props: any, ref: any) => {
|
|
|
|
|
|
|
|
|
|
const {questionTypeValues } = props
|
|
|
|
|
|
|
|
|
|
console.log('questionTypeValues::::::::::', questionTypeValues)
|
|
|
|
|
//console.log('passScoreValue:::', passScoreValue)
|
|
|
|
|
|
|
|
|
|
const match = useRouteMatch();
|
|
|
|
|
console.log('match', match);
|
|
|
|
|
|
|
|
|
|
const [typeScore, setTypeScore] = useState(questionTypeValues.map(item=>({question_type:item.code, score: item.score, score_harf: item.score_harf}))) ; // 题型分数数组 [{"question_type": "0","score": "3","score_harf": "0"},]
|
|
|
|
|
const [flag, setFlag] = useState([]) // 分数变更标记
|
|
|
|
|
const {questionTypeValues, passScore: passScoreValue } = props
|
|
|
|
|
const [typeScore, setTypeScore] = useState(questionTypeValues.map((item: { code: number; score: number; score_harf: number; })=>({question_type:item.code, score: item.score, score_harf: item.score_harf}))) ; // 题型分数数组 [{"question_type": "0","score": "3","score_harf": "0"},]
|
|
|
|
|
//const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型
|
|
|
|
|
const [dataSource, setDataSource] = useState([]);
|
|
|
|
|
//const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]);
|
|
|
|
|
//const [addType, setAddType] = useState({name: '', value: 0});
|
|
|
|
|
const [sumScore, setSumScore] = useState(0);
|
|
|
|
|
const [passScore, setPassScore] = useState(0); // 设置通过分数线
|
|
|
|
|
//const [sumScore, setSumScore] = useState();
|
|
|
|
|
const [passScore, setPassScore] = useState(passScoreValue); // 设置通过分数线
|
|
|
|
|
|
|
|
|
|
//let sumScore = 0 // 总分
|
|
|
|
|
console.log('init........', typeScore)
|
|
|
|
|
const formRef = useRef();
|
|
|
|
|
|
|
|
|
|
//setTypeScore(questionTypeValues) // 初始化分值
|
|
|
|
|
//const actionRef = useRef<ActionType>();
|
|
|
|
|
//console.log('init........', typeScore)
|
|
|
|
|
const formRef = useRef<any>();
|
|
|
|
|
|
|
|
|
|
/** 列表项定义 */
|
|
|
|
|
const columns: any = [
|
|
|
|
@ -70,7 +51,7 @@ const ScoreSetter = (props: any, ref: any) => {
|
|
|
|
|
dataIndex: 'score',
|
|
|
|
|
key: 'code',
|
|
|
|
|
width: 400,
|
|
|
|
|
render: (text, record, index) =>
|
|
|
|
|
render: (_text: any, record: { code: number; }, index: string | number) =>
|
|
|
|
|
<Space direction='horizontal'>
|
|
|
|
|
<span>每题</span>
|
|
|
|
|
<Form.Item style={{margin:0}} name={`score[${index}]`}><Input
|
|
|
|
@ -89,13 +70,13 @@ const ScoreSetter = (props: any, ref: any) => {
|
|
|
|
|
size="small"
|
|
|
|
|
onChange={(e)=>{
|
|
|
|
|
const value = e.currentTarget.value;
|
|
|
|
|
console.log('row', index)
|
|
|
|
|
console.log('v1',value)
|
|
|
|
|
const scoreData = typeScore?.map((item, key)=>{
|
|
|
|
|
const scoreData = typeScore?.map((item: { score: any; }, key: string | number)=>{
|
|
|
|
|
return {...item, score: ((index === key) ? Number(value) : Number(item?.score))} // 题型分数
|
|
|
|
|
})
|
|
|
|
|
console.log('question',questionTypeValues)
|
|
|
|
|
console.log('scoreData-----------------',scoreData)
|
|
|
|
|
// 标记重新设置项(序号)
|
|
|
|
|
if(flag.indexOf(index) === -1){
|
|
|
|
|
setFlag([...flag, index])
|
|
|
|
|
}
|
|
|
|
|
setTypeScore(scoreData)
|
|
|
|
|
}}/></Form.Item>
|
|
|
|
|
<span>分</span>
|
|
|
|
@ -113,8 +94,7 @@ const ScoreSetter = (props: any, ref: any) => {
|
|
|
|
|
><InputNumber min={0} max={99} maxLength={2} type="number" defaultValue={questionTypeValues ? questionTypeValues[index]?.score_harf : 0} placeholder="请输入" size="small" name='score_harf' onChange={(value)=>{
|
|
|
|
|
//
|
|
|
|
|
const _data = [];
|
|
|
|
|
console.log('typeScore',typeScore)
|
|
|
|
|
typeScore?.forEach((item, key)=>{
|
|
|
|
|
typeScore?.forEach((item: { score_harf: any; }, key: number)=>{
|
|
|
|
|
_data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)})
|
|
|
|
|
})
|
|
|
|
|
setTypeScore(_data)
|
|
|
|
@ -128,118 +108,93 @@ const ScoreSetter = (props: any, ref: any) => {
|
|
|
|
|
title: '题目数量',
|
|
|
|
|
dataIndex: 'count',
|
|
|
|
|
width: 80,
|
|
|
|
|
render: (text, _, index) => <>{questionTypeValues ? questionTypeValues[index]?.count : '0'}</>,
|
|
|
|
|
/*
|
|
|
|
|
editable: (text, record, index) => {
|
|
|
|
|
return true;
|
|
|
|
|
},*/
|
|
|
|
|
render: (_text: any, _: any, index: number) => <>{questionTypeValues ? questionTypeValues[index]?.count : '0'}</>,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '总分值',
|
|
|
|
|
dataIndex: 'score_sum',
|
|
|
|
|
//key: 'age',
|
|
|
|
|
width: 80,
|
|
|
|
|
render: (text, _, index) => {
|
|
|
|
|
{/*console.log('typeScore---', typeScore)*/}
|
|
|
|
|
defaultValue:()=>{ return 123},
|
|
|
|
|
render: (_text: any, _: any, index: number) => {
|
|
|
|
|
//console.log('typeScore---', typeScore)
|
|
|
|
|
//console.log('questionTypeValues',questionTypeValues)
|
|
|
|
|
//console.log('==score==',typeScore)
|
|
|
|
|
return <>
|
|
|
|
|
{(typeScore && questionTypeValues) ? ((typeScore[index]?.score > 0 ? typeScore[index]?.score : 0) * questionTypeValues[index]?.count).toFixed(1) : '0'}
|
|
|
|
|
{flag?.indexOf(index) === -1 ?
|
|
|
|
|
questionTypeValues[index]?.score * questionTypeValues[index].count :
|
|
|
|
|
(typeScore && questionTypeValues) ? ((typeScore[index]?.score > 0 ? typeScore[index]?.score : 0) * questionTypeValues[index]?.count).toFixed(1) : '0'
|
|
|
|
|
}
|
|
|
|
|
</>
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
//const labels = ['A','B','C','D','E']
|
|
|
|
|
|
|
|
|
|
/** 获取总题数 */
|
|
|
|
|
let sumQuestion = 0;
|
|
|
|
|
questionTypeValues?.forEach((item) => {
|
|
|
|
|
questionTypeValues?.forEach((item: any) => {
|
|
|
|
|
sumQuestion += item.count;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取题型
|
|
|
|
|
const { data } = useRequest(() => {
|
|
|
|
|
return queryQuestionType();
|
|
|
|
|
},{
|
|
|
|
|
formatResult: (result) => {
|
|
|
|
|
const _data = [];
|
|
|
|
|
if(result.list){
|
|
|
|
|
result.list.forEach((item)=>{
|
|
|
|
|
_data.push({
|
|
|
|
|
name: item?.name,
|
|
|
|
|
code: item?.code,
|
|
|
|
|
count: 0,
|
|
|
|
|
score_sum: 0,
|
|
|
|
|
harf: 0
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
console.log('_data',_data)
|
|
|
|
|
return _data;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setDataSource(data);
|
|
|
|
|
console.log('data', data)
|
|
|
|
|
const _typeScore = [];
|
|
|
|
|
data?.forEach((item)=>{
|
|
|
|
|
_typeScore.push({question_type: item?.code, score: item?.count, score_harf: 0})
|
|
|
|
|
})
|
|
|
|
|
setTypeScore(_typeScore) // 初始值
|
|
|
|
|
//return ()=>{}
|
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
|
|
/** 计算总分 */
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log('typeScore', typeScore)
|
|
|
|
|
let _sum = 0;
|
|
|
|
|
typeScore?.forEach((item, index)=>{
|
|
|
|
|
_sum += (item.score > 0 ? item.score : 0 ) * questionTypeValues[index]?.count;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setSumScore(_sum)
|
|
|
|
|
//return ()=>{}
|
|
|
|
|
}, [typeScore]);
|
|
|
|
|
|
|
|
|
|
// 暴露组件的方法 接受外部获取的ref
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
|
|
// 构造ref的获取数据方法
|
|
|
|
|
getData: () => {
|
|
|
|
|
return typeScore?.map((item, idx)=>{return {...item, count: questionTypeValues[idx]?.count, sum: item?.score * questionTypeValues[idx]?.count}});
|
|
|
|
|
return typeScore?.map((item: any, idx: number)=>{
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
count: questionTypeValues[idx]?.count,
|
|
|
|
|
sum: item?.score * questionTypeValues[idx]?.count,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getValue: () => {
|
|
|
|
|
return passScore;
|
|
|
|
|
return passScore
|
|
|
|
|
},
|
|
|
|
|
getSum: () => {
|
|
|
|
|
console.log('getSum', sumScore)
|
|
|
|
|
return sumScore;
|
|
|
|
|
return typeScore?.map((item: any, key: number)=>{return item?.score * questionTypeValues[key].count})?.reduce((total: number, item: number)=>(total + item)) || 0 ;
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form
|
|
|
|
|
ref={formRef}
|
|
|
|
|
>
|
|
|
|
|
<EditableProTable
|
|
|
|
|
title={()=>{
|
|
|
|
|
return <Space size="large"><span>共计 {sumQuestion} 题,</span><span>总计 {sumScore} 分</span> 通过分数线
|
|
|
|
|
<Form.Item style={{margin:0}} name='pass_socre' initialValue={0}><InputNumber min={0} onChange={(value)=>{
|
|
|
|
|
setPassScore(value)
|
|
|
|
|
}} /></Form.Item>
|
|
|
|
|
分</Space>}}
|
|
|
|
|
//formMapRef={formMapRef}
|
|
|
|
|
//rowKey={'code'}
|
|
|
|
|
bordered
|
|
|
|
|
cardProps={{bodyStyle:{padding:0}}}
|
|
|
|
|
recordCreatorProps={false}
|
|
|
|
|
search={false}
|
|
|
|
|
options={false}
|
|
|
|
|
value={dataSource}
|
|
|
|
|
columns={columns}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
|
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
<Form
|
|
|
|
|
ref={formRef}
|
|
|
|
|
>
|
|
|
|
|
<ProTable
|
|
|
|
|
title={()=>{
|
|
|
|
|
return <Space size="large"><span>共计 {sumQuestion} 题,</span><span>总计 {
|
|
|
|
|
typeScore?.map((item: any, key: number)=>{return item?.score * questionTypeValues[key].count})?.reduce((total: number, item: number)=>(total + item)) || 0
|
|
|
|
|
} 分</span> 通过分数线
|
|
|
|
|
<Form.Item style={{margin:0}} name='pass_socre' initialValue={passScore}><InputNumber min={0} onChange={(value)=>{
|
|
|
|
|
setPassScore(value)
|
|
|
|
|
}} /></Form.Item>
|
|
|
|
|
分</Space>}}
|
|
|
|
|
//formMapRef={formMapRef}
|
|
|
|
|
rowKey={'code'}
|
|
|
|
|
request={async ()=>{
|
|
|
|
|
const result = await queryQuestionType() // 从字典获取题型数据 [{code: 0, name:"单选题"},]
|
|
|
|
|
setTypeScore(questionTypeValues?.map((item: { score: any; score_harf: any; }, key: number)=>{
|
|
|
|
|
return {question_type: result.list[key]?.code, score: item?.score, score_harf: (item?.score_harf || 0)}
|
|
|
|
|
}))
|
|
|
|
|
return {data:questionTypeValues?.map((item: any, key: number)=>({
|
|
|
|
|
...item,
|
|
|
|
|
code: result.list[key]?.code,
|
|
|
|
|
question_type: result.list[key]?.code,
|
|
|
|
|
name: result.list[key]?.name,
|
|
|
|
|
count: result.list[key]?.count
|
|
|
|
|
}))}
|
|
|
|
|
}}
|
|
|
|
|
bordered
|
|
|
|
|
cardProps={{bodyStyle:{padding:0}}}
|
|
|
|
|
search={false}
|
|
|
|
|
options={false}
|
|
|
|
|
columns={columns}
|
|
|
|
|
pagination={false}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
// forwardRef这个组件能够将其接受的 ref 属性转发到其组件树下
|
|
|
|
|