page.js 10 KB

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