1
0

page.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import React from 'react';
  2. import { Button } from 'antd';
  3. import { Link } from 'react-router-dom';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { getMap, formatDate } from '@src/services/Tools';
  11. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { PreviewStatus } from '../../../../Constant';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { Preview } from '../../../stores/preview';
  15. const filterForm = [
  16. {
  17. key: 'category',
  18. type: 'select',
  19. allowClear: true,
  20. name: '课程',
  21. placeholder: '请选择',
  22. number: true,
  23. },
  24. {
  25. key: 'status',
  26. type: 'select',
  27. name: '状态',
  28. select: PreviewStatus,
  29. number: true,
  30. placeholder: '请选择',
  31. },
  32. ];
  33. export default class extends Page {
  34. constructor(props) {
  35. super(props);
  36. this.actionList = [{
  37. key: 'add',
  38. name: '新建作业',
  39. render: (item) => {
  40. // return <Link to='/subject/preview/add'><Button>{item.name}</Button></Link>;
  41. return <Button onClick={() => {
  42. linkTo('/subject/preview/detail');
  43. }}>{item.name}</Button>;
  44. },
  45. }];
  46. this.categoryMap = {};
  47. this.columns = [{
  48. title: '课程',
  49. dataIndex: 'category',
  50. render: (text) => {
  51. return this.categoryMap[text] || text;
  52. },
  53. }, {
  54. title: '开始时间',
  55. dataIndex: 'startTime',
  56. render: (text) => {
  57. return formatDate(text);
  58. },
  59. }, {
  60. title: '结束时间',
  61. dataIndex: 'endTime',
  62. render: (text) => {
  63. return formatDate(text);
  64. },
  65. }, {
  66. title: '作业标题',
  67. dataIndex: 'title',
  68. }, {
  69. title: '完成进度',
  70. dataIndex: 'finish',
  71. render: (text, record) => {
  72. return `${text}/${record.userIds.length}`;
  73. },
  74. }, {
  75. title: '操作',
  76. dataIndex: 'handler',
  77. render: (text, record) => {
  78. return <div className="table-button">
  79. {(
  80. <Link to={`/subject/preview/detail/${record.id}`}>编辑</Link>
  81. )}
  82. {(
  83. <Link to={`/user/previewList?previewId=${record.id}&startTime=${record.startTime}&endTime=${record.endTime}`}>查看</Link>
  84. )}
  85. {(
  86. <Button
  87. size="small"
  88. type="link"
  89. onClick={() => {
  90. }}
  91. >
  92. 复制
  93. </Button>
  94. )}
  95. </div>;
  96. },
  97. }];
  98. }
  99. init() {
  100. Exercise.allStruct().then(result => {
  101. filterForm[0].select = result.filter(row => row.level === 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  102. this.categoryMap = getMap(filterForm[0].select, 'id', 'title');
  103. this.setState({ exercise: result });
  104. });
  105. }
  106. initData() {
  107. Preview.list(this.state.search).then(result => {
  108. this.setTableData(result.list, result.total);
  109. });
  110. }
  111. deleteAction() {
  112. const { selectedKeys } = this.state;
  113. asyncDelConfirm('删除确认', '是否删除选中作业?', () => {
  114. return Promise.all(selectedKeys.map(row => Preview.delStruct({ id: row }))).then(() => {
  115. asyncSMessage('删除成功!');
  116. this.refresh();
  117. });
  118. });
  119. }
  120. renderView() {
  121. return <Block flex>
  122. <FilterLayout
  123. show
  124. itemList={filterForm}
  125. data={this.state.search}
  126. onChange={data => {
  127. this.search(data);
  128. }} />
  129. <ActionLayout
  130. itemList={this.actionList}
  131. selectedKeys={this.state.selectedKeys}
  132. onAction={key => this.onAction(key)}
  133. />
  134. <TableLayout
  135. select
  136. columns={this.columns}
  137. list={this.state.list}
  138. pagination={this.state.page}
  139. loading={this.props.core.loading}
  140. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  141. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  142. selectedKeys={this.state.selectedKeys}
  143. />
  144. </Block>;
  145. }
  146. }