123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import React from 'react';
- import { Link } from 'react-router-dom';
- import { Button } from 'antd';
- 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, formatDate } from '@src/services/Tools';
- // import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
- import { DataType, SwitchSelect } from '../../../../Constant';
- // import { User } from '../../../stores/user';
- import { Exercise } from '../../../stores/exercise';
- import { Course } from '../../../stores/course';
- const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
- const DataTypeMap = getMap(DataType, 'value', 'label');
- export default class extends Page {
- init() {
- this.actionList = [{
- key: 'add',
- type: 'primary',
- name: '创建',
- render: (item) => {
- return <Button onClick={() => {
- linkTo('/course/data/detail');
- }}>{item.name}</Button>;
- },
- }];
- this.exerciseMap = {};
- this.filterForm = [{
- key: 'structId',
- type: 'tree',
- allowClear: true,
- name: '学科',
- select: [],
- placeholder: '请选择',
- number: true,
- }, {
- key: 'dataType',
- type: 'select',
- allowClear: true,
- name: '资料形式',
- select: DataType,
- placeholder: '请选择',
- }];
- this.columns = [{
- title: '学科',
- dataIndex: 'structId',
- render: (text, record) => {
- return `${record.parentStructId ? `${this.exerciseMap[record.parentStructId]}-` : ''}${this.exerciseMap[record.structId]}`;
- },
- },
- {
- title: '资料形式',
- dataIndex: 'dataType',
- render: (text) => {
- return DataTypeMap[text] || text;
- },
- },
- {
- title: '适合新手',
- dataIndex: 'isNovice',
- render: (text) => {
- return SwitchSelectMap[text];
- },
- },
- {
- title: '原创资料',
- dataIndex: 'isOriginal',
- render: (text) => {
- return SwitchSelectMap[text];
- },
- }, {
- title: '资料名称',
- dataIndex: 'title',
- }, {
- title: '查看人数',
- sorter: true,
- // sortDirections: ['ascend'],
- dataIndex: 'viewNumber',
- }, {
- title: '购买人数',
- sorter: true,
- // sortDirections: ['descend'],
- dataIndex: 'saleNumber',
- }, {
- title: '更新时间',
- sorter: true,
- dataIndex: 'updateTime',
- render: (text) => {
- return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
- },
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <Link to={`/course/data/detail/${record.id}`}>编辑</Link>
- )}
- {(
- <Link to={`/course/data/history/${record.id}`}>更新历史</Link>
- )}
- </div>;
- },
- }];
- Exercise.dataStruct().then((result) => {
- const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
- this.filterForm[0].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 });
- });
- }
- initData() {
- Course.listData(this.state.search).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- 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>;
- }
- }
|