123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- import React from 'react';
- import { Tabs, Form, Row, Col, InputNumber, Button, Switch, DatePicker } from 'antd';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import EditTableCell from '@src/components/EditTableCell';
- import { getMap, flattenObject } from '@src/services/Tools';
- import { asyncSMessage } from '@src/services/AsyncTools';
- import TableLayout from '@src/layouts/TableLayout';
- import { QuestionDifficult } from '../../../../Constant';
- import { System } from '../../../stores/system';
- // import { Examination } from '../../../stores/examination';
- import { Exercise } from '../../../stores/exercise';
- export default class extends Page {
- constructor(props) {
- super(props);
- this.exerciseColumns = [{
- title: '学科',
- dataIndex: 'title',
- }].concat(QuestionDifficult.map(row => {
- return {
- title: row.label,
- dataIndex: row.value,
- render: (text, result) => {
- const { exercise = {} } = this.state;
- return <EditTableCell value={(exercise[result.id] || {})[row.value] || 0} onChange={(v) => {
- this.changeMapValue('exercise', result.id, row.value, v);
- }} />;
- },
- };
- }));
- this.examinationColumns = [{
- title: '学科',
- dataIndex: 'title',
- }, {
- title: '题目数',
- dataIndex: 'number',
- render: (text, result) => {
- const { examination = {} } = this.state;
- return (examination[result.extend] || {}).number || 0;
- // return <EditTableCell value={(examination[result.extend] || {}).number || 0} onChange={(v) => {
- // this.changeMapValue('examination', result.extend, 'number', v);
- // }} />;
- },
- }, {
- title: '做题时间',
- dataIndex: 'time',
- render: (text, result) => {
- const { examination = {} } = this.state;
- return Number((examination[result.extend] || {}).time || 0) / 60;
- // return <EditTableCell value={(examination[result.extend] || {}).time || 0} onChange={(v) => {
- // this.changeMapValue('examination', result.extend, 'time', v);
- // }} />;
- },
- }];
- this.state.tab = 'exercise';
- }
- initData() {
- Promise.all(this.structExamination(), this.structExercise())
- .then(() => {
- return this.refresh(this.state.tab);
- });
- }
- refresh(tab) {
- if (tab === 'exercise') {
- return Promise.all([this.refreshScoreSwitch(), this.refreshExercise(), this.refreshSentence(), this.refreshTextbook()]);
- }
- if (tab === 'examination') {
- return this.refreshExamination();
- }
- if (tab === 'filter') {
- return this.refreshFilter();
- }
- if (tab === 'paper') {
- return this.refreshExercisePaperAuto();
- }
- if (tab === 'textbook') {
- return this.refreshTextbookConfig();
- }
- return Promise.reject();
- }
- refreshScoreSwitch() {
- return System.getScoreSwitch().then(result => {
- this.setState({ score: result || {} });
- });
- }
- refreshExercise() {
- return System.getExerciseTime().then((result) => {
- this.setState({ exercise: result });
- });
- }
- refreshExercisePaperAuto() {
- return System.getExercisePaperAuto().then((result) => {
- this.setState({ exercisePaperAuto: result });
- });
- }
- refreshSentence() {
- return System.getSentenceTime().then((result) => {
- this.setState({ sentence: result || {} });
- const { form } = this.props;
- form.setFieldsValue(flattenObject(result, 'sentence'));
- });
- }
- refreshTextbook() {
- return System.getTextbookTime().then((result) => {
- this.setState({ textbook: result || {} });
- const { form } = this.props;
- form.setFieldsValue(flattenObject(result, 'textbook'));
- });
- }
- refreshExamination() {
- return System.getExaminationTime().then((result) => {
- this.setState({ examination: result });
- });
- }
- refreshFilter() {
- return System.getFilterTime().then((result) => {
- this.setState({ filter: result || {} });
- const { form } = this.props;
- form.setFieldsValue(flattenObject(result, 'filter'));
- });
- }
- refreshTextbookConfig() {
- return System.getTextbookConfig().then((result) => {
- this.setState({ textbookConfig: result || {} });
- const { form } = this.props;
- form.setFieldsValue(flattenObject(result, 'textbookConfig'));
- });
- }
- structExercise() {
- return Exercise.allStruct().then(result => {
- const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; });
- const map = getMap(list, 'id');
- this.setState({
- exerciseList: list.filter(row => row.level === 2).map(row => {
- const parent = map[row.parentId];
- row.title = `${parent.title}-${row.title}`;
- return row;
- }),
- });
- });
- }
- structExamination() {
- return Exercise.allStruct().then(result => {
- const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; });
- this.setState({
- examinationList: list.filter(row => row.level === 1 && row.isExamination),
- });
- });
- }
- changeMapValue(field, index, key, value) {
- const data = this.state[field] || {};
- data[index] = data[index] || {};
- data[index][key] = value;
- this.setState({ [field]: data });
- }
- changeValue(field, key, value) {
- const data = this.state[field] || {};
- data[key] = value;
- this.setState({ [field]: data });
- }
- submit(tab) {
- let handler;
- if (tab === 'exercise') {
- handler = this.submitExercise()
- .then(() => {
- return this.submitTextbook();
- })
- .then(() => {
- return this.submitSentence();
- });
- }
- if (tab === 'examination') {
- handler = this.submitExamination();
- }
- if (tab === 'filter') {
- handler = this.submitFilter();
- }
- if (tab === 'paper') {
- handler = this.submitExercisePaperAuto();
- }
- handler.then(() => {
- asyncSMessage('保存成功');
- });
- }
- submitScore() {
- const { score } = this.state;
- return System.setScoreSwitch(score);
- }
- submitExercise() {
- const { exercise } = this.state;
- return System.setExerciseTime(exercise);
- }
- submitExercisePaperAuto() {
- const { exercisePaperAuto } = this.state;
- return System.setExercisePaperAuto(exercisePaperAuto);
- }
- submitSentence() {
- const { sentence } = this.state;
- return System.setSentenceTime(sentence);
- }
- submitTextbook() {
- const { textbook } = this.state;
- return System.setTextbookTime(textbook);
- }
- submitExamination() {
- const { examination } = this.state;
- return System.setExaminationTime(examination);
- }
- submitFilter() {
- const { form } = this.props;
- return new Promise((resolve, reject) => {
- form.validateFields(['filter'], (err, values) => {
- if (!err) {
- System.setFilterTime(values.filter)
- .then(() => {
- resolve();
- })
- .catch((e) => {
- reject(e);
- });
- }
- });
- });
- }
- renderAll() {
- const { score = {} } = this.state;
- return <Form>
- <Row>
- <Col span={8} offset={16}>
- <Form.Item labelCol={{ span: 12 }} wrapperCol={{ span: 10 }} label='是否启动全站数据'>
- <Switch checked={score.all} checkedChildren='启用' unCheckedChildren='未启用' onChange={(value) => {
- score.all = value;
- this.setState({ score });
- this.submitScore();
- }} />
- </Form.Item>
- </Col>
- </Row>
- </Form>;
- }
- renderExercise() {
- return <TableLayout
- key={this.state.exercise ? 1 : 0}
- columns={this.exerciseColumns}
- list={this.state.exerciseList}
- pagination={false}
- loading={this.props.core.loading}
- />;
- }
- renderOther() {
- const { getFieldDecorator } = this.props.form;
- return <Form>
- <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='长难句'>
- {getFieldDecorator('sentence.time', {
- rules: [
- { required: true, message: '输入每题预估时间' },
- ],
- })(
- <InputNumber placeholder='请输入每题预估时间' addonAfter="s" onChange={(value) => {
- this.changeValue('sentence', 'time', value);
- }} style={{ width: '200px' }} />,
- )}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='数据机经'>
- {getFieldDecorator('textbook.time', {
- rules: [
- { required: true, message: '输入每题预估时间' },
- ],
- })(
- <InputNumber placeholder='请输入每题预估时间' addonAfter="s" onChange={(value) => {
- this.changeValue('textbook', 'time', value);
- }} style={{ width: '200px' }} />,
- )}
- </Form.Item>
- </Col>
- </Row>
- </Form>;
- }
- renderFilterTime() {
- const { getFieldDecorator } = this.props.form;
- return <Form>
- <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='最短时间/题'>
- {getFieldDecorator('filter.min', {
- rules: [
- { required: true, message: '输入最短做题时间' },
- ],
- })(
- <InputNumber placeholder='请输入最短做题时间' addonAfter="s" onChange={(value) => {
- this.changeValue('filter', 'min', value);
- }} style={{ width: '200px' }} />,
- )}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='最长时间/题'>
- {getFieldDecorator('filter.max', {
- rules: [
- { required: true, message: '输入最长做题时间' },
- ],
- })(
- <InputNumber placeholder='请输入最长做题时间' addonAfter="s" onChange={(value) => {
- this.changeValue('filter', 'max', value);
- }} style={{ width: '200px' }} />,
- )}
- </Form.Item>
- </Col>
- </Row>
- </Form>;
- }
- renderExercisePaperAuto() {
- const { getFieldDecorator } = this.props.form;
- return <Form>
- <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} label='下次错误率组卷'>
- {getFieldDecorator('exercisePaper.date', {
- rules: [
- { required: true, message: '下次错误率组卷时间' },
- ],
- })(
- <DatePicker placeholder='请输入下次练习错误率组卷时间' onChange={(value) => {
- this.changeValue('exercisePaper', 'date', value);
- }} />,
- )}
- </Form.Item>
- </Col>
- </Row>
- </Form>;
- }
- renderTextbookConfig() {
- const { getFieldDecorator } = this.props.form;
- return <Form>
- <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='每月基础人数'>
- {getFieldDecorator('textbookConfig.use_number', {
- rules: [
- { required: true, message: '输入每月基础人数' },
- ],
- })(
- <InputNumber placeholder='请输入每月基础人数' onChange={(value) => {
- this.changeValue('textbookConfig', 'use_number', value);
- }} style={{ width: '200px' }} />,
- )}
- </Form.Item>
- </Col>
- </Row>
- </Form>;
- }
- renderExamination() {
- return <TableLayout
- columns={this.examinationColumns}
- list={this.state.examinationList}
- pagination={false}
- loading={this.props.core.loading}
- />;
- }
- renderView() {
- const { tab } = this.state;
- return <Block>
- <Tabs activeKey={tab} onChange={(value) => {
- this.setState({ tab: value, selectedKeys: [], checkedKeys: [] });
- this.refresh(value);
- }}>
- <Tabs.TabPane tab="预估做题时间" key="exercise">
- {this.renderAll()}
- {this.renderExercise()}
- {this.renderOther()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="数据剔除时间" key="filter">
- {this.renderFilterTime()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="预估考试时间" key="examination">
- {this.renderExamination()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="组卷" key="paper">
- {this.renderExercisePaperAuto()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="机经" key="textbook">
- {this.renderTextbookConfig()}
- </Tabs.TabPane>
- </Tabs>
- {tab !== 'examination' && <Row type="flex" justify="center">
- <Col>
- <Button type="primary" onClick={() => {
- this.submit(tab);
- }}>保存</Button>
- </Col>
- </Row>}
- </Block>;
- }
- }
|