123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import React from 'react';
- 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, bindSearch, formatDate } from '@src/services/Tools';
- import { UserUrl } from '../../../../Constant';
- import { Exercise } from '../../../stores/exercise';
- import { Preview } from '../../../stores/preview';
- import { User } from '../../../stores/user';
- // import { System } from '../../../stores/system';
- export default class extends Page {
- constructor(props) {
- super(props);
- this.categoryMap = {};
- this.filterF = null;
- }
- init() {
- this.filterForm = [
- {
- key: 'structId',
- type: 'select',
- allowClear: true,
- name: '课程',
- placeholder: '请选择',
- number: true,
- onChange: (value) => {
- this.refreshPreview(value);
- this.filterF.setFieldsValue({ previewId: '' });
- },
- },
- {
- key: 'previewId',
- type: 'select',
- name: '练习册',
- allowClear: true,
- select: [],
- number: true,
- placeholder: '请选择',
- },
- {
- key: 'userId',
- type: 'select',
- name: '用户',
- allowClear: true,
- select: [],
- number: true,
- placeholder: '请输入',
- },
- {
- key: 'time',
- type: 'daterange',
- name: '做题时间',
- },
- ];
- this.columns = [{
- title: '用户id',
- dataIndex: 'userId',
- render: (text, record) => {
- return record.user.id;
- },
- }, {
- title: '用户名称',
- dataIndex: 'user.realName',
- render: (text, record) => {
- return record.user.realName;
- },
- }, {
- title: '做题时间',
- dataIndex: 'createTime',
- render: (text) => {
- return formatDate(text);
- },
- }, {
- title: '学科',
- dataIndex: 'category',
- render: (text) => {
- return this.categoryMap[text] || text;
- },
- }, {
- title: '练习册',
- dataIndex: 'title',
- render: (text, record) => {
- return record.preview.title;
- },
- }, {
- title: '完成进度',
- dataIndex: 'finish',
- render: (text, record) => {
- return `${record.report.userNumber * 100 / record.report.totalNumber}`;
- },
- }, {
- title: '错误率',
- dataIndex: 'correct',
- render: (text, record) => {
- return `${record.report.correctNumber * 100 / record.questionNo.totalNumber}%`;
- },
- }, {
- title: '时长',
- dataIndex: 'time',
- render: (text, record) => {
- return `${record.report.userTime}s`;
- },
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <a onClick={() => {
- const url = `${UserUrl}paper/report/${record.id}`;
- User.locationUser(record.userId, url);
- }}>查看</a>
- )}
- </div>;
- },
- }];
- Exercise.allStruct().then(result => {
- this.filterForm[0].select = result.filter(row => row.level === 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
- this.categoryMap = getMap(this.filterForm[0].select, 'id', 'title');
- this.setState({ exercise: result });
- });
- bindSearch(this.filterForm, 'userId', this, (search) => {
- return User.list(search);
- }, (row) => {
- return {
- title: `${row.nickname}(${row.mobile})`,
- value: row.id,
- };
- }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
- this.refreshPreview();
- }
- // 筛选条件
- refreshPreview(category) {
- Preview.list({ category })
- .then(result => {
- this.filterForm[1].select = result.list.map(row => { row.value = row.id; row.label = row.title; return row; });
- this.setState({ load: false });
- });
- }
- initData() {
- const { search } = this.state;
- const data = Object.assign({}, search);
- if (data.time) {
- data.startTime = data.time[0] || '';
- data.endTime = data.time[1] || '';
- }
- Preview.list(data).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- renderView() {
- return <Block flex>
- <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- if (data.time.length > 0) {
- data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
- }
- this.search(data);
- }}
- ref={(ref) => {
- if (ref) this.filterF = ref;
- }} />
- <TableLayout
- select
- columns={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>;
- }
- }
|