page.js 4.5 KB

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