page.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 { 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. 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. return Promise.reject();
  61. })}
  62. >
  63. <Button>{item.name}</Button>
  64. </Upload>;
  65. },
  66. }, {
  67. key: 'delete',
  68. name: '批量删除',
  69. needSelect: 1,
  70. }];
  71. this.categoryMap = {};
  72. this.columns = [{
  73. title: '课程',
  74. dataIndex: 'category',
  75. render: (text) => {
  76. return this.categoryMap[text] || text;
  77. },
  78. }, {
  79. title: '开始时间',
  80. dataIndex: 'startTime',
  81. render: (text) => {
  82. return formatDate(text);
  83. },
  84. }, {
  85. title: '结束时间',
  86. dataIndex: 'endTime',
  87. render: (text) => {
  88. return formatDate(text);
  89. },
  90. }, {
  91. title: '作业标题',
  92. dataIndex: 'title',
  93. }, {
  94. title: '完成进度',
  95. dataIndex: 'finish',
  96. render: (text, record) => {
  97. return `${text}/${record.userIds.length}`;
  98. },
  99. }, {
  100. title: '操作',
  101. dataIndex: 'handler',
  102. render: (text, record) => {
  103. return <div className="table-button">
  104. {(
  105. <Link to={`/subject/preview/detail/${record.id}`}>编辑</Link>
  106. )}
  107. {(
  108. <Link to={`/user/previewList?previewId=${record.id}&startTime=${record.startTime}&endTime=${record.endTime}`}>查看</Link>
  109. )}
  110. {(
  111. <Button
  112. size="small"
  113. type="link"
  114. onClick={() => {
  115. }}
  116. >
  117. 复制
  118. </Button>
  119. )}
  120. </div>;
  121. },
  122. }];
  123. }
  124. init() {
  125. Exercise.allStruct().then(result => {
  126. filterForm[0].select = result.filter(row => row.level === 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  127. this.categoryMap = getMap(filterForm[0].select, 'id', 'title');
  128. this.setState({ exercise: result });
  129. });
  130. }
  131. initData() {
  132. Preview.list(this.state.search).then(result => {
  133. this.setTableData(result.list, result.total);
  134. });
  135. }
  136. deleteAction() {
  137. const { selectedKeys } = this.state;
  138. asyncDelConfirm('删除确认', '是否删除选中作业?', () => {
  139. return Promise.all(selectedKeys.map(row => Preview.delStruct({ id: row }))).then(() => {
  140. asyncSMessage('删除成功!');
  141. this.refresh();
  142. });
  143. });
  144. }
  145. renderView() {
  146. return <Block flex>
  147. <FilterLayout
  148. show
  149. itemList={filterForm}
  150. data={this.state.search}
  151. onChange={data => {
  152. this.search(data);
  153. }} />
  154. <ActionLayout
  155. itemList={this.actionList}
  156. selectedKeys={this.state.selectedKeys}
  157. onAction={key => this.onAction(key)}
  158. />
  159. <TableLayout
  160. select
  161. columns={this.columns}
  162. list={this.state.list}
  163. pagination={this.state.page}
  164. loading={this.props.core.loading}
  165. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  166. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  167. selectedKeys={this.state.selectedKeys}
  168. />
  169. </Block>;
  170. }
  171. }