123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- import React from 'react';
- import { Button } from 'antd';
- import { Link } from 'react-router-dom';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import FilterLayout from '@src/layouts/FilterLayout';
- import ActionLayout from '@src/layouts/ActionLayout';
- import TableLayout from '@src/layouts/TableLayout';
- import { getMap, formatTreeData, bindSearch, formatDate, formatSeconds, formatPercent } from '@src/services/Tools';
- import { asyncSMessage, asyncDelConfirm, asyncGet } from '@src/services/AsyncTools';
- import { QuestionType, QuestionDifficult } from '../../../../Constant';
- import { Exercise } from '../../../stores/exercise';
- import { System } from '../../../stores/system';
- import { Question } from '../../../stores/question';
- import { Slient } from '../../../stores/slient';
- // import Association from '../../../components/Association';
- const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
- const filterForm = [{
- key: 'questionType',
- type: 'select',
- allowClear: true,
- name: '题型',
- select: QuestionType,
- placeholder: '请选择',
- },
- {
- key: 'structId',
- type: 'tree',
- allowClear: true,
- name: '分册',
- select: [],
- placeholder: '请选择',
- number: true,
- },
- {
- key: 'paperId',
- type: 'select',
- allowClear: true,
- name: '练习册',
- select: [],
- placeholder: '请选择',
- number: true,
- },
- {
- key: 'place',
- type: 'select',
- allowClear: true,
- name: '考点',
- select: [],
- placeholder: '请选择',
- },
- {
- key: 'difficult',
- type: 'select',
- allowClear: true,
- name: '难度',
- select: QuestionDifficult,
- placeholder: '请选择',
- },
- {
- key: 'time',
- type: 'daterange',
- name: '修改时间',
- },
- {
- key: 'questionNoId',
- type: 'select',
- allowClear: true,
- name: '题目ID',
- select: [],
- number: true,
- placeholder: '请输入',
- }];
- export default class extends Page {
- constructor(props) {
- super(props);
- this.actionList = [{
- key: 'add',
- name: '新建',
- render: (item) => {
- return <Button onClick={() => {
- linkTo('/subject/question');
- }}>{item.name}</Button>;
- },
- }, {
- key: 'auto',
- name: '重新组卷',
- }, {
- key: 'delete',
- name: '批量删除',
- needSelect: 1,
- }];
- this.categoryMap = {};
- this.columns = [{
- title: '学科',
- dataIndex: 'first',
- render: (text, record) => {
- return this.categoryMap[record.moduleStruct[0]] || text;
- },
- }, {
- title: '题型',
- dataIndex: 'questionType',
- render: (text, record) => {
- return QuestionTypeMap[record.question.questionType] || text;
- },
- }, {
- title: '题目ID',
- sorter: true,
- dataIndex: 'no',
- render: (text, record) => {
- return record.title;
- },
- }, {
- title: '练习册',
- dataIndex: 'paper',
- render: (text) => {
- return (text || {}).title;
- },
- }, {
- title: '考点',
- dataIndex: 'place',
- render: (text, record) => {
- return record.question.place;
- },
- }, {
- title: '难度',
- sorter: true,
- dataIndex: 'difficult',
- render: (text, record) => {
- return record.question.difficult;
- },
- }, {
- title: '易错度',
- sorter: true,
- dataIndex: 'correct',
- render: (text, record) => {
- return formatPercent(record.totalNumber - record.totalCorrect, record.totalNumber, false);
- },
- }, {
- title: '平均时间',
- sorter: true,
- dataIndex: 'time',
- render: (text, record) => {
- return formatSeconds(record.totalTime / record.totalNumber);
- },
- }, {
- title: '序号',
- sorter: this.state.search.paperId,
- dataIndex: 'number',
- render: (text, record) => {
- const { search } = this.state;
- if (search.paperId) {
- return record.no;
- }
- return '--';
- },
- }, {
- title: '修改时间',
- sorter: true,
- dataIndex: 'updateTime',
- render: (text, record) => {
- return formatDate(record.question.updateTime, 'YYYY-MM-DD HH:mm:ss');
- },
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <Link to={`/subject/question/${record.questionId}`}>编辑</Link>
- )}
- {(
- <a onClick={() => {
- asyncGet(() => import('../../../components/Association'),
- { title: '题源联想', ids: record.question.associationContent, field: 'associationContent', module: 'exercise', modal: true },
- (data) => {
- data.id = record.questionId;
- // data.associationContent = data.associationContent.map(row => row.id);
- return Question.edit(data).then(() => {
- asyncSMessage('修改成功!');
- });
- });
- }}>题源联想</a>
- )}
- </div>;
- },
- }];
- }
- initAuto() {
- this.outPage();
- this.interval = setInterval(() => {
- Slient.exerciseAuto().then((result) => {
- if (result.progress == null || result.progress === 100) {
- this.actionList[1].disabled = false;
- result.progress = 100;
- } else {
- this.actionList[1].disabled = true;
- }
- this.setState({ progress: result.progress });
- });
- }, 30000);
- }
- outPage() {
- if (this.interval) {
- clearInterval(this.interval);
- }
- }
- init() {
- Exercise.allStruct().then(result => {
- const list = result.filter(row => row.level >= 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
- filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
- this.categoryMap = getMap(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id', 'title');
- this.setState({ exercise: result });
- });
- System.getPlace().then(result => {
- filterForm[3].select = [].concat(...Object.keys(result).map(key => result[key].map(row => {
- return {
- label: row,
- value: row,
- };
- })));
- this.setState({ place: result });
- });
- bindSearch(filterForm, 'paperId', this, (search) => {
- return Exercise.listPaper(search);
- }, (row) => {
- return {
- title: row.title,
- value: row.id,
- };
- }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
- bindSearch(filterForm, 'questionNoId', this, (search) => {
- return Question.searchNo(search);
- }, (row) => {
- return {
- title: row.title,
- value: row.id,
- };
- }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
- this.initAuto();
- }
- initData() {
- const { search } = this.state;
- const data = Object.assign({}, search);
- if (data.time) {
- data.startTime = data.time[0] || '';
- data.endTime = data.time[1] || '';
- }
- Exercise.listQuestion(data).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- autoAction() {
- asyncDelConfirm('组卷确认', '是否重新组卷?', () => {
- return Exercise.auto().then(() => {
- asyncSMessage('开始组卷!');
- this.refresh();
- });
- });
- }
- deleteAction() {
- const { selectedRows } = this.state;
- asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
- return Promise.all(selectedRows.map(row => Question.delNo({ id: row.id }))).then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- });
- }
- renderView() {
- const { exercise } = this.state;
- return <Block flex>
- {exercise && <FilterLayout
- show
- itemList={filterForm}
- data={this.state.search}
- onChange={data => {
- if (data.time.length > 0) {
- data.time = [data.time[0].format('YYYY-MM-DD 00:00:00'), data.time[1].format('YYYY-MM-DD 23:59:59')];
- }
- data.page = 1;
- this.search(data);
- }} />}
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- select
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
- onSelect={(keys, rows) => this.tableSelect(keys, rows)}
- selectedKeys={this.state.selectedKeys}
- />
- </Block>;
- }
- }
|