123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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 } from '@src/services/Tools';
- import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
- import { CourseModule, QuestionType } from '../../../../Constant';
- import { Exercise } from '../../../stores/exercise';
- import { Course } from '../../../stores/course';
- import { Preview } from '../../../stores/preview';
- const CourseModuleMap = getMap(CourseModule, 'value', 'label');
- const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
- export default class extends Page {
- init() {
- this.exerciseMap = {};
- this.actionList = [{
- key: 'addVideo',
- type: 'primary',
- name: '创建视频作业',
- render: (item) => {
- return <Link to='/course/preview/detail?module=video'><Button type='primary'>{item.name}</Button></Link>;
- },
- }, {
- key: 'addOnline',
- type: 'primary',
- name: '创建小班作业',
- render: (item) => {
- return <Link to='/course/preview/detail?module=online'><Button type='primary'>{item.name}</Button></Link>;
- },
- }, {
- key: 'addVs',
- type: 'primary',
- name: '创建1vs1作业',
- render: (item) => {
- return <Link to='/course/preview/detail?module=vs'><Button type='primary'>{item.name}</Button></Link>;
- },
- }];
- this.filterForm = [{
- key: 'courseModule',
- type: 'select',
- allowClear: true,
- name: '课程类型',
- placeholder: '请选择',
- select: CourseModule,
- }, {
- key: 'questionType',
- type: 'select',
- allowClear: true,
- name: '题型',
- placeholder: '请选择',
- select: QuestionType,
- }, {
- key: 'courseId',
- type: 'select',
- name: '课程名称',
- select: [],
- number: true,
- placeholder: '请选择',
- }];
- this.columns = [{
- title: '课程类型',
- dataIndex: 'courseModule',
- render: (text) => {
- return CourseModuleMap[text] || text;
- },
- }, {
- title: '课程名称',
- dataIndex: 'course.title',
- }, {
- title: '题型',
- dataIndex: 'questionType',
- render: (text) => {
- return QuestionTypeMap[text] || '';
- },
- }, {
- title: '作业标题',
- dataIndex: 'title',
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <Link to={`/course/preview/detail/${record.id}`}>编辑</Link>
- )}
- </div>;
- },
- }];
- Exercise.courseStruct().then((result) => {
- const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
- this.filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
- this.exerciseMap = getMap(result.map(row => {
- row.title = `${row.titleZh}`;
- row.value = row.id;
- return row;
- }), 'id', 'title');
- this.setState({ exercise: result });
- });
- bindSearch(this.filterForm, 'courseId', this, (search) => {
- return Course.list(search);
- }, (row) => {
- return {
- title: row.title,
- value: row.id,
- };
- }, this.state.search.courseId ? Number(this.state.search.courseId) : null, null);
- }
- initData() {
- Preview.list(this.state.search).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- deleteAction() {
- const { selectedKeys } = this.state;
- asyncDelConfirm('删除确认', '是否删除选中作业?', () => {
- return Promise.all(selectedKeys.map(row => Preview.del({ id: row }))).then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- });
- }
- renderView() {
- const { exercise } = this.state;
- return <Block flex>
- {exercise && <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- data.page = 1;
- this.search(data);
- }} />}
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- 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>;
- }
- }
|