page.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 Switch from '../../../components/Switch';
  11. import menu, { refreshQuestionType, refreshStruct } from '../index';
  12. import Tabs from '../../../components/Tabs';
  13. import { TimeRange } from '../../../../Constant';
  14. import { My } from '../../../stores/my';
  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. <div className="sub">{text}</div>
  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. ask:
  81. '从比较对象和句子结构我们能把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排除掉',
  82. answer:
  83. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  84. },
  85. {
  86. title: '题目',
  87. ask:
  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排除掉',
  89. answer:
  90. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  91. },
  92. ],
  93. },
  94. {
  95. group: true,
  96. title: '语法',
  97. date: ' OG18 #678',
  98. content: '「图形」None of the attempts to specify the causes of crime explains why most of the p',
  99. list: [
  100. {
  101. title: '题目',
  102. ask:
  103. '从比较对象和句子结构我们能把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排除掉',
  104. answer:
  105. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  106. },
  107. {
  108. title: '题目',
  109. ask:
  110. '从比较对象和句子结构我们能把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排除掉',
  111. answer:
  112. '从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题,',
  113. },
  114. ],
  115. },
  116. ],
  117. selectList: [],
  118. tab: 'exercise',
  119. timerange: 'today',
  120. };
  121. }
  122. initData() {
  123. const data = Object.assign(this.state, this.state.search);
  124. data.filterMap = this.state.search;
  125. if (data.order) {
  126. data.sortMap = { [data.order]: data.direction };
  127. }
  128. if (data.timerange) {
  129. data.filterMap.timerange = data.timerange;
  130. }
  131. const [startTime, endTime] = timeRange(data.timerange);
  132. refreshQuestionType(this, data.subject, data.questionType, {
  133. all: true,
  134. needSentence: false,
  135. allSubject: true,
  136. }).then(({ questionTypes }) => {
  137. return refreshStruct(this, data.tab, data.one, data.two, {
  138. all: true,
  139. needPreview: false,
  140. needTextbook: true,
  141. }).then(({ structIds, latest, year }) => {
  142. My.listQuestionAsk(
  143. Object.assign(
  144. { module: data.tab, questionTypes, structIds, latest, year, startTime, endTime },
  145. this.state.search,
  146. {
  147. order: Object.keys(data.sortMap)
  148. .map(key => {
  149. return `${key} ${data.sortMap[key]}`;
  150. })
  151. .join(','),
  152. },
  153. ),
  154. ).then(result => {
  155. this.setState({ list: result.list, total: result.total, page: data.page });
  156. });
  157. });
  158. });
  159. }
  160. onTabChange(tab) {
  161. const data = { tab };
  162. this.refreshQuery(data);
  163. }
  164. onFilter(value) {
  165. this.search(value);
  166. }
  167. onSort(value) {
  168. const keys = Object.keys(value);
  169. // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
  170. const { sortMap } = this.state;
  171. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  172. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null });
  173. }
  174. onChangePage(page) {
  175. this.search({ page });
  176. }
  177. onAction() {}
  178. onSelect(selectList) {
  179. this.setState({ selectList });
  180. }
  181. renderView() {
  182. const { config } = this.props;
  183. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  184. }
  185. renderTable() {
  186. const {
  187. tab,
  188. questionSubjectSelect,
  189. questionSubjectMap = {},
  190. oneSelect,
  191. twoSelectMap = {},
  192. filterMap = {},
  193. sortMap = {},
  194. list = [],
  195. } = this.state;
  196. const { total, page } = this.state;
  197. return (
  198. <div className="table-layout">
  199. <Tabs
  200. border
  201. type="division"
  202. theme="theme"
  203. size="small"
  204. space={2.5}
  205. width={100}
  206. active={tab}
  207. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  208. onChange={key => this.onTabChange(key)}
  209. />
  210. <UserAction
  211. search
  212. selectList={[
  213. {
  214. children: [
  215. {
  216. key: 'subject',
  217. placeholder: '学科',
  218. select: questionSubjectSelect,
  219. },
  220. {
  221. placeholder: '题型',
  222. key: 'questionType',
  223. be: 'subject',
  224. selectMap: questionSubjectMap,
  225. },
  226. ],
  227. },
  228. {
  229. label: '范围',
  230. children: [
  231. {
  232. key: 'one',
  233. placeholder: '全部',
  234. select: oneSelect,
  235. },
  236. {
  237. key: 'two',
  238. be: 'one',
  239. placeholder: '全部',
  240. selectMap: twoSelectMap,
  241. },
  242. ],
  243. },
  244. {
  245. right: true,
  246. key: 'timerange',
  247. select: TimeRange,
  248. },
  249. ]}
  250. filterMap={filterMap}
  251. onFilter={value => this.onFilter(value)}
  252. />
  253. <UserAction
  254. sortList={[
  255. { right: true, label: '提问时间', key: 'create_time', fixed: true },
  256. { right: true, label: '回答时间', key: 'ask_time' },
  257. ]}
  258. sortMap={sortMap}
  259. left={
  260. <div className="email">
  261. 只看已回答{' '}
  262. <Switch
  263. checked={filterMap.askStatus}
  264. onChange={() => {
  265. filterMap.askStatus = !filterMap.askStatus;
  266. this.onFilter(filterMap);
  267. }}
  268. />
  269. </div>
  270. }
  271. onSort={value => this.onSort(value)}
  272. />
  273. {list.map(item => {
  274. return (
  275. <div className="group">
  276. <UserTable border={false} size="small" columns={columns} data={[item]} header={false} />
  277. <div className="answer-layout">
  278. <div className="title">
  279. 提问区域: <b>{item.target}</b>
  280. </div>
  281. <div className="small-tag">提问</div>
  282. <div className="desc">{item.content}</div>
  283. <div className="small-tag">回答</div>
  284. <div className="desc">{item.answer}</div>
  285. </div>
  286. </div>
  287. );
  288. })}
  289. {total && list.length > 0 && (
  290. <UserPagination total={total} current={page} onChange={p => this.onChangePage(p)} />
  291. )}
  292. </div>
  293. );
  294. }
  295. }