page.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import { timeRange } from '@src/services/Tools';
  6. import UserLayout from '../../../layouts/User';
  7. import UserTable from '../../../components/UserTable';
  8. import UserAction from '../../../components/UserAction';
  9. import UserPagination from '../../../components/UserPagination';
  10. import menu, { refreshQuestionType, refreshStruct } from '../index';
  11. import Tabs from '../../../components/Tabs';
  12. import { TimeRange } from '../../../../Constant';
  13. import { My } from '../../../stores/my';
  14. const columns = [
  15. {
  16. key: 'title',
  17. title: '笔记对象',
  18. width: 140,
  19. render(text, row) {
  20. return row.group ? (
  21. <div className="group">
  22. <Link to="">{text}</Link>
  23. </div>
  24. ) : (
  25. <div className="sub">{text}</div>
  26. );
  27. },
  28. },
  29. {
  30. key: 'date',
  31. title: '更新时间',
  32. width: 100,
  33. render(text, row) {
  34. return row.group ? (
  35. <div className="group">
  36. <Link to="">{text}</Link>
  37. </div>
  38. ) : (<div className="sub">
  39. <div className="date">{text.split(' ')[0]}</div>
  40. <div className="date">{text.split(' ')[1]}</div>
  41. </div>
  42. );
  43. },
  44. },
  45. {
  46. key: 'content',
  47. title: '内容',
  48. width: 540,
  49. render(text, row) {
  50. return row.group ? (
  51. <div className="group">
  52. <Link to="">{text}</Link>
  53. </div>
  54. ) : (
  55. <div className="sub">{text}</div>
  56. );
  57. },
  58. },
  59. ];
  60. export default class extends Page {
  61. constructor(props) {
  62. props.size = 10;
  63. super(props);
  64. }
  65. initState() {
  66. return {
  67. filterMap: {},
  68. sortMap: {},
  69. data: [
  70. {
  71. group: true,
  72. title: '语法',
  73. date: ' OG18 #678',
  74. content: '「图形」None of the attempts to specify the causes of crime explains why most of the p',
  75. list: [
  76. {
  77. title: '题目',
  78. date: '2019-07-23 15:20:21',
  79. content:
  80. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  81. },
  82. {
  83. title: '官方解析',
  84. date: '2019-07-23 15:20:21',
  85. content:
  86. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  87. },
  88. ],
  89. },
  90. {
  91. group: true,
  92. title: '语法',
  93. date: ' OG18 #678',
  94. content: '「图形」None of the attempts to specify the causes of crime explains why most of the p',
  95. list: [
  96. {
  97. title: '题目',
  98. date: '2019-07-23 15:20:21',
  99. content:
  100. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  101. },
  102. {
  103. title: '官方解析',
  104. date: '2019-07-23 15:20:21',
  105. content:
  106. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  107. },
  108. ],
  109. },
  110. ],
  111. selectList: [],
  112. allChecked: false,
  113. tab: 'exercise',
  114. timerange: 'today',
  115. };
  116. }
  117. initData() {
  118. const data = Object.assign(this.state, this.state.search);
  119. data.filterMap = this.state.search;
  120. if (data.order) {
  121. data.sortMap = { [data.order]: data.direction };
  122. }
  123. if (data.timerange) {
  124. data.filterMap.timerange = data.timerange;
  125. }
  126. const [startTime, endTime] = timeRange(data.timerange);
  127. refreshQuestionType(this, data.subject, data.questionType, { all: true, needSentence: false, allSubject: true })
  128. .then(({ questionTypes }) => {
  129. return refreshStruct(this, data.tab, data.one, data.two, {
  130. all: true, needPreview: false, needTextbook: false,
  131. })
  132. .then(({ structIds, latest, year }) => {
  133. My.listQuestionNote(Object.assign({ module: data.tab, questionTypes, structIds, latest, year, startTime, endTime }, this.state.search, {
  134. order: Object.keys(data.sortMap).map(key => {
  135. return `${key} ${data.sortMap[key]}`;
  136. }).join(','),
  137. })).then(result => {
  138. this.setState({ list: result.list, total: result.total, page: data.page });
  139. });
  140. });
  141. });
  142. }
  143. onTabChange(tab) {
  144. const data = { tab };
  145. this.refreshQuery(data);
  146. }
  147. onFilter(value) {
  148. this.search(value);
  149. }
  150. onSort(value) {
  151. const keys = Object.keys(value);
  152. // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
  153. const { sortMap } = this.state;
  154. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  155. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null });
  156. }
  157. onChangePage(page) {
  158. this.search({ page });
  159. }
  160. onAll(checked) {
  161. if (checked) {
  162. const { data = [] } = this.state;
  163. const list = [];
  164. data.forEach(item => {
  165. list.push(item.key);
  166. });
  167. this.setState({ selectList: list, allChecked: true });
  168. } else {
  169. this.setState({ selectList: [], allChecked: false });
  170. }
  171. }
  172. onAction() { }
  173. onSelect(selectList) {
  174. this.setState({ selectList });
  175. }
  176. renderView() {
  177. const { config } = this.props;
  178. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  179. }
  180. renderTable() {
  181. const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, filterMap = {}, sortMap = {}, list = [] } = this.state;
  182. const { selectList = [], allChecked, page, total } = this.state;
  183. return (
  184. <div className="table-layout">
  185. <Tabs
  186. border
  187. type="division"
  188. theme="theme"
  189. size="small"
  190. space={2.5}
  191. width={100}
  192. active={tab}
  193. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  194. onChange={key => this.onTabChange(key)}
  195. />
  196. <UserAction
  197. search
  198. selectList={[{
  199. children: [{
  200. key: 'subject',
  201. placeholder: '学科',
  202. select: questionSubjectSelect,
  203. }, {
  204. placeholder: '题型',
  205. key: 'questionType',
  206. be: 'subject',
  207. selectMap: questionSubjectMap,
  208. }],
  209. }, {
  210. label: '范围',
  211. children: [{
  212. key: 'one',
  213. placeholder: '全部',
  214. select: oneSelect,
  215. }, {
  216. key: 'two',
  217. be: 'one',
  218. placeholder: '全部',
  219. selectMap: twoSelectMap,
  220. }],
  221. }, {
  222. right: true,
  223. key: 'timerange',
  224. select: TimeRange,
  225. }]}
  226. filterMap={filterMap}
  227. onFilter={value => this.onFilter(value)}
  228. />
  229. <UserAction
  230. allCheckbox
  231. allChecked={allChecked}
  232. help
  233. btnList={[{ title: '删除', key: 'remove' }, { title: '导出', key: 'export', tag: 'vip' }]}
  234. sortList={[{ right: true, label: '更新时间', key: 'update_time' }]}
  235. sortMap={sortMap}
  236. onSort={value => this.onSort(value)}
  237. onAll={checked => this.onAll(checked)}
  238. onAction={key => this.onAction(key)}
  239. />
  240. {list.map((item, index) => {
  241. return (
  242. <div className="group">
  243. <UserTable
  244. theme="dark"
  245. border={false}
  246. size="small"
  247. select
  248. selectList={selectList}
  249. columns={columns}
  250. data={[item]}
  251. header={false}
  252. />
  253. <UserTable
  254. border={false}
  255. size="small"
  256. select
  257. even="default"
  258. selectList={selectList}
  259. columns={columns}
  260. data={item.list}
  261. header={index === 0}
  262. />
  263. </div>
  264. );
  265. })}
  266. {total && list.length > 0 && <UserPagination total={total} current={page} onChange={(p) => this.onChangePage(p)} />}
  267. </div>
  268. );
  269. }
  270. }