page.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import React from 'react';
  2. import './index.less';
  3. import { Anchor, Icon } from 'antd';
  4. import Assets from '@src/components/Assets';
  5. import Page from '@src/containers/Page';
  6. import Select from '../../../components/Select';
  7. import Button from '../../../components/Button';
  8. import { SuppleModal, SuppleFinishModal } from '../../../components/OtherModal';
  9. export default class extends Page {
  10. initState() {
  11. return {
  12. load: false,
  13. list: [
  14. {
  15. key: '1',
  16. title: '了解GMAT',
  17. children: true,
  18. },
  19. { key: '2', title: '推荐阅读' },
  20. { key: '3', title: '考场查询' },
  21. { key: '4', title: '熟悉备考资料', children: true },
  22. ],
  23. current: '1',
  24. scrollCurrent: '1-1',
  25. result: [{}, {}, {}],
  26. data: [
  27. { key: '1', id: 'data1', title: '官方', children: [{}, {}, {}] },
  28. { key: '2', id: 'data2', title: '非官方', children: [{}, {}, {}] },
  29. ],
  30. page: [
  31. {
  32. key: '1-1',
  33. title: '考试功能',
  34. id: '#test1',
  35. content:
  36. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  37. },
  38. {
  39. key: '1-2',
  40. title: '出题原理',
  41. id: '#test2',
  42. content:
  43. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  44. },
  45. {
  46. key: '1-3',
  47. title: '出题原理',
  48. id: '#test3',
  49. content:
  50. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  51. },
  52. {
  53. key: '1-4',
  54. title: '出题原理',
  55. id: '#test4',
  56. content:
  57. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  58. },
  59. {
  60. key: '1-5',
  61. title: '出题原理',
  62. id: '#test5',
  63. content:
  64. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  65. },
  66. {
  67. key: '1-6',
  68. title: '出题原理',
  69. id: '#test6',
  70. content:
  71. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  72. },
  73. {
  74. key: '1-7',
  75. title: '出题原理',
  76. id: '#test7',
  77. content:
  78. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  79. },
  80. {
  81. key: '1-8',
  82. title: '出题原理',
  83. id: '#test8',
  84. content:
  85. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  86. },
  87. {
  88. key: '1-9',
  89. title: '出题原理',
  90. id: '#test9',
  91. content:
  92. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  93. },
  94. {
  95. key: '1-10',
  96. title: '出题原理',
  97. id: '#test10',
  98. content:
  99. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  100. },
  101. {
  102. key: '1-11',
  103. title: '出题原理',
  104. id: '#test11',
  105. content:
  106. '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
  107. },
  108. ],
  109. };
  110. }
  111. initData() {
  112. this.initInfo();
  113. }
  114. initInfo() {
  115. this.load = false;
  116. try {
  117. const { page, current, data } = this.state;
  118. const _list = current === '4' ? data : page;
  119. _list.forEach(item => {
  120. item.top = document.getElementById(item.id).offsetTop - 100;
  121. return item;
  122. });
  123. this.load = true;
  124. } catch (e) {
  125. setTimeout(() => {
  126. this.initInfo();
  127. }, 500);
  128. }
  129. }
  130. inPage() {
  131. document.getElementById('root').addEventListener('scroll', e => {
  132. if (!this.load) return;
  133. this.onScroll(e);
  134. });
  135. }
  136. outPage() {
  137. document.getElementById('root').removeEventListener('scroll');
  138. }
  139. onScroll(e) {
  140. const t = e.target.scrollTop;
  141. const { page, data, current, scrollCurrent } = this.state;
  142. const _list = current === '4' ? data : page;
  143. let _current = null;
  144. for (let i = 0; i < _list.length; i += 1) {
  145. if (!_current) _current = _list[i].key;
  146. if (t < _list[i].top) break;
  147. _current = _list[i].key;
  148. }
  149. if (_current !== scrollCurrent) {
  150. this.setState({ scrollCurrent: _current });
  151. }
  152. }
  153. scrollTo(top) {
  154. document.getElementById('root').scrollTo({ top, behavior: 'smooth' });
  155. }
  156. changePage(key) {
  157. this.setState({ current: key });
  158. setTimeout(() => {
  159. this.initInfo();
  160. }, 1);
  161. }
  162. renderView() {
  163. const { list, current, scrollCurrent, page, data } = this.state;
  164. let detail = {};
  165. return (
  166. <div>
  167. <div className="content">
  168. <div className="left">
  169. <Anchor offsetTop={90} getContainer={() => document.getElementById('root')}>
  170. {list.map(item => {
  171. if (item.key === current) detail = item;
  172. const _list = item.key === '4' ? data : page;
  173. return (
  174. <div
  175. className={`page-item ${item.key === current ? 'active' : ''}`}
  176. onClick={() => this.changePage(item.key)}
  177. >
  178. {item.children && <Assets name="dropdown_hover" className="up" />}
  179. {item.children && <Assets name="dropdown_normal" className="down" />}
  180. <div className="page-item-title">{item.title}</div>
  181. {current === item.key &&
  182. item.children &&
  183. _list.map(child => {
  184. return (
  185. <div
  186. style={{ margin: 3 }}
  187. className={`t-s-12 t-2 c-p ${child.key === scrollCurrent ? 't-4' : ''}`}
  188. onClick={() => this.scrollTo(child.top)}
  189. title={child.title}
  190. >
  191. {child.title}
  192. </div>
  193. );
  194. })}
  195. </div>
  196. );
  197. })}
  198. </Anchor>
  199. </div>
  200. <div className="center">
  201. <div className="t-1 t-s-24 m-b-2">{detail.title}</div>
  202. {current !== '3' && current !== '4' && this.renderList()}
  203. {current === '3' && this.renderQuery()}
  204. {current === '4' && this.renderData()}
  205. </div>
  206. </div>
  207. </div>
  208. );
  209. }
  210. renderQuery() {
  211. const { result } = this.state;
  212. return (
  213. <div className="query-layout">
  214. <div className="search-wrapper">
  215. <Select theme="white" list={[{ title: '中国', key: '1' }, { title: '海外', key: '2' }]} />
  216. <input />
  217. <Button width={150}>
  218. <Icon className="m-r-5" type="search" />
  219. 搜索题目
  220. </Button>
  221. </div>
  222. {result.map(() => {
  223. return (
  224. <div className="m-b-2">
  225. <div className="t-1 t-s-18">1.上海财经大学</div>
  226. <div className="t-1">上海市徐汇区天钥桥路333号腾飞大厦8层805室</div>
  227. <div className="t-1">
  228. 温馨提示: 本考场提供听力耳机 <span className="t-4">我要补充</span>
  229. </div>
  230. </div>
  231. );
  232. })}
  233. <SuppleModal />
  234. <SuppleFinishModal />
  235. </div>
  236. );
  237. }
  238. renderData() {
  239. const { data } = this.state;
  240. return data.map(item => {
  241. return (
  242. <div className="p-t-1 m-b-2" id={item.id}>
  243. <div className="t-1 t-s-18 m-b-1">{item.title}</div>
  244. <div className="data-list">
  245. {item.children.map(child => {
  246. return <Assets width={240} height={310} src={child} className="data-item" />;
  247. })}
  248. </div>
  249. </div>
  250. );
  251. });
  252. }
  253. renderList() {
  254. const { page } = this.state;
  255. return page.map(item => {
  256. return (
  257. <div className="p-t-1 m-b-2" id={item.id}>
  258. <div className="t-1 t-s-18 m-b-1">{item.title}</div>
  259. <div className="t-2">{item.content}</div>
  260. </div>
  261. );
  262. });
  263. }
  264. }