|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Button, Form, InputNumber, message } from 'antd';
|
|
|
|
|
import { Button, Form, Input, InputNumber, message } from 'antd';
|
|
|
|
|
//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout';
|
|
|
|
|
//import { useRequest } from 'umi';
|
|
|
|
|
//import { queryFakeList } from './service';
|
|
|
|
@ -50,12 +50,13 @@ type DataSourceType = {
|
|
|
|
|
// 需要处理
|
|
|
|
|
// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。
|
|
|
|
|
const AutoSelector = (props: any, ref: any) => {
|
|
|
|
|
const formRef = useRef()
|
|
|
|
|
/** 获取章节数据 */
|
|
|
|
|
// 获取主题id
|
|
|
|
|
console.log('props subject_id', props)
|
|
|
|
|
const { subjectId, questionType } = props;
|
|
|
|
|
console.log('questionType', questionType)
|
|
|
|
|
const [typeScore, setTypeScore] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}]
|
|
|
|
|
const [rows, setRows] = useState([]) ; // 章节
|
|
|
|
|
|
|
|
|
|
//const [dataSource, setDataSource] = useState<DataSourceType[]>(() => defaultData);
|
|
|
|
|
|
|
|
|
@ -72,24 +73,30 @@ const AutoSelector = (props: any, ref: any) => {
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/* 动态设置题型列 */
|
|
|
|
|
questionType?.forEach((item)=>{
|
|
|
|
|
questionType?.forEach((item, idx)=>{
|
|
|
|
|
columns.push({
|
|
|
|
|
title: <>{item?.name} <Form.Item style={{margin:0}} name={`type${item?.code}`}><InputNumber defaultValue={0} style={{marginLeft:5}} /></Form.Item></>,
|
|
|
|
|
//key: 'code',
|
|
|
|
|
title: <>{item?.name} <Form.Item style={{margin:0}} name={['type',idx,'sum']}><Input type='text' defaultValue={0} onInput={(e)=>{
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
onChange={(e)=>{
|
|
|
|
|
const val = e.currentTarget.value;
|
|
|
|
|
console.log('onchange==', val)
|
|
|
|
|
const values = formRef?.current.getFieldsValue()
|
|
|
|
|
console.log('values', values)
|
|
|
|
|
const { questionType } = values;
|
|
|
|
|
const avg = val / questionType[idx].length // 平均数
|
|
|
|
|
const rem = val % questionType[idx].length // 余数
|
|
|
|
|
const _questionType = questionType[idx].map((item, key)=>{return key < rem ? Math.ceil(avg) : Math.floor(avg)})
|
|
|
|
|
console.log('questionTypeData', _questionType)
|
|
|
|
|
questionType[idx] = _questionType;
|
|
|
|
|
//[[10]]
|
|
|
|
|
formRef?.current.setFieldsValue({questionType: questionType})
|
|
|
|
|
}}
|
|
|
|
|
/></Form.Item></>,
|
|
|
|
|
key: 'code',
|
|
|
|
|
dataIndex: `type${item?.code}`,
|
|
|
|
|
render: ( item, { defaultRender, ...rest }, form) => {
|
|
|
|
|
return <Form.Item style={{margin:0}} ><InputNumber min={0} max={3} defaultValue={1} type='number'
|
|
|
|
|
onChange={(value)=>{
|
|
|
|
|
//
|
|
|
|
|
const _data = [];
|
|
|
|
|
console.log('typeScore',typeScore)
|
|
|
|
|
typeScore?.forEach((item, key)=>{
|
|
|
|
|
_data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)})
|
|
|
|
|
})
|
|
|
|
|
setTypeScore(_data)
|
|
|
|
|
console.log('setTypeScore',typeScore)
|
|
|
|
|
}}
|
|
|
|
|
/></Form.Item>;
|
|
|
|
|
render: ( _dom, record, index) => {
|
|
|
|
|
return <Form.Item style={{margin:0}} name={['questionType', idx, index]}><Input min={0} max={3} defaultValue={0} type='text' /></Form.Item>;
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
@ -99,19 +106,34 @@ const AutoSelector = (props: any, ref: any) => {
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
|
|
// 构造ref的获取数据方法
|
|
|
|
|
getData: () => { // 组卷数据
|
|
|
|
|
return [];
|
|
|
|
|
console.log('useImperativeHandle')
|
|
|
|
|
const values = formRef.current.getFieldsValue()
|
|
|
|
|
console.log(values)
|
|
|
|
|
const data = values?.questionType.map((item, key)=>{
|
|
|
|
|
return {
|
|
|
|
|
question_type:key,
|
|
|
|
|
chapter_list: item.map((val,idx)=>(
|
|
|
|
|
{chapter_id:rows[idx]?.chapter_id, count: val}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}) // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}]
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<EditableProTable
|
|
|
|
|
<Form ref={formRef}>
|
|
|
|
|
<ProTable
|
|
|
|
|
bordered
|
|
|
|
|
recordCreatorProps={false}
|
|
|
|
|
pagination={false}
|
|
|
|
|
//recordCreatorProps={false}
|
|
|
|
|
//formRef={formRef}
|
|
|
|
|
headerTitle={false}
|
|
|
|
|
columns={columns}
|
|
|
|
|
rowKey="id"
|
|
|
|
|
key="id"
|
|
|
|
|
search={false}
|
|
|
|
|
// value={dataSource}
|
|
|
|
|
request={async (value) => {
|
|
|
|
|
const { data } = await queryListChapterBySubject({
|
|
|
|
@ -119,14 +141,16 @@ const AutoSelector = (props: any, ref: any) => {
|
|
|
|
|
page_number: 1,
|
|
|
|
|
page_size: 1000,
|
|
|
|
|
});
|
|
|
|
|
setRows(data?.list)
|
|
|
|
|
console.log('data--',data)
|
|
|
|
|
/*
|
|
|
|
|
const _data = [];
|
|
|
|
|
data?.list.forEach((item)=>{
|
|
|
|
|
_data.push({
|
|
|
|
|
id: item?.chapter_id,
|
|
|
|
|
chapter_name: item?.chapter_name,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})*/
|
|
|
|
|
//chapter_name
|
|
|
|
|
return {data: data?.list};
|
|
|
|
|
/*
|
|
|
|
@ -143,6 +167,7 @@ const AutoSelector = (props: any, ref: any) => {
|
|
|
|
|
}}
|
|
|
|
|
toolBarRender={false}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|