page.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { Button } from 'antd';
  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, formatTreeData, formatDate } from '@src/services/Tools';
  11. // import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { DataType, SwitchSelect } from '../../../../Constant';
  13. // import { User } from '../../../stores/user';
  14. import { Exercise } from '../../../stores/exercise';
  15. import { Course } from '../../../stores/course';
  16. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  17. const DataTypeMap = getMap(DataType, 'value', 'label');
  18. export default class extends Page {
  19. init() {
  20. this.actionList = [{
  21. key: 'add',
  22. type: 'primary',
  23. name: '创建',
  24. render: (item) => {
  25. return <Button onClick={() => {
  26. linkTo('/course/data/detail');
  27. }}>{item.name}</Button>;
  28. },
  29. }];
  30. this.exerciseMap = {};
  31. this.filterForm = [{
  32. key: 'structId',
  33. type: 'tree',
  34. allowClear: true,
  35. name: '学科',
  36. select: [],
  37. placeholder: '请选择',
  38. number: true,
  39. }, {
  40. key: 'dataType',
  41. type: 'select',
  42. allowClear: true,
  43. name: '资料形式',
  44. select: DataType,
  45. placeholder: '请选择',
  46. }];
  47. this.columns = [{
  48. title: '学科',
  49. dataIndex: 'structId',
  50. render: (text, record) => {
  51. return `${record.parentStructId ? `${this.exerciseMap[record.parentStructId]}-` : ''}${this.exerciseMap[record.structId]}`;
  52. },
  53. },
  54. {
  55. title: '资料形式',
  56. dataIndex: 'dataType',
  57. render: (text) => {
  58. return DataTypeMap[text] || text;
  59. },
  60. },
  61. {
  62. title: '适合新手',
  63. dataIndex: 'isNovice',
  64. render: (text) => {
  65. return SwitchSelectMap[text];
  66. },
  67. },
  68. {
  69. title: '原创资料',
  70. dataIndex: 'isOriginal',
  71. render: (text) => {
  72. return SwitchSelectMap[text];
  73. },
  74. }, {
  75. title: '资料名称',
  76. dataIndex: 'title',
  77. }, {
  78. title: '查看人数',
  79. sorter: true,
  80. // sortDirections: ['ascend'],
  81. dataIndex: 'viewNumber',
  82. }, {
  83. title: '购买人数',
  84. sorter: true,
  85. // sortDirections: ['descend'],
  86. dataIndex: 'saleNumber',
  87. }, {
  88. title: '更新时间',
  89. sorter: true,
  90. dataIndex: 'updateTime',
  91. render: (text) => {
  92. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  93. },
  94. }, {
  95. title: '操作',
  96. dataIndex: 'handler',
  97. render: (text, record) => {
  98. return <div className="table-button">
  99. {(
  100. <Link to={`/course/data/detail/${record.id}`}>编辑</Link>
  101. )}
  102. {(
  103. <Link to={`/course/data/history/${record.id}`}>更新历史</Link>
  104. )}
  105. </div>;
  106. },
  107. }];
  108. Exercise.dataStruct().then((result) => {
  109. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  110. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  111. this.exerciseMap = getMap(result.map(row => {
  112. row.title = `${row.titleZh}`;
  113. row.value = row.id;
  114. return row;
  115. }), 'id', 'title');
  116. this.setState({ exercise: result });
  117. });
  118. }
  119. initData() {
  120. Course.listData(this.state.search).then(result => {
  121. this.setTableData(result.list, result.total);
  122. });
  123. }
  124. renderView() {
  125. const { exercise } = this.state;
  126. return <Block flex>
  127. {exercise && <FilterLayout
  128. show
  129. itemList={this.filterForm}
  130. data={this.state.search}
  131. onChange={data => {
  132. data.page = 1;
  133. this.search(data);
  134. }} />}
  135. <ActionLayout
  136. itemList={this.actionList}
  137. selectedKeys={this.state.selectedKeys}
  138. onAction={key => this.onAction(key)}
  139. />
  140. <TableLayout
  141. columns={this.tableSort(this.columns)}
  142. list={this.state.list}
  143. pagination={this.state.page}
  144. loading={this.props.core.loading}
  145. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  146. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  147. selectedKeys={this.state.selectedKeys}
  148. />
  149. </Block>;
  150. }
  151. }