page.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. import React, { Component } from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import { Tooltip, Icon, Calendar } from 'antd';
  5. import Page from '@src/containers/Page';
  6. import Assets from '@src/components/Assets';
  7. import { formatPercent, formatDate, formatSeconds } from '@src/services/Tools';
  8. import { asyncSMessage } from '@src/services/AsyncTools';
  9. import moment from 'moment';
  10. import UserLayout from '../../../layouts/User';
  11. import Tabs from '../../../components/Tabs';
  12. import Button from '../../../components/Button';
  13. import { Icon as GIcon } from '../../../components/Icon';
  14. import UserTable from '../../../components/UserTable';
  15. import Examination from '../../../components/Examination';
  16. import menu from '../index';
  17. import { BindPhone, BindEmail, EditInfo, RealAuth, EditAvatar, InviteModal } from '../../../components/OtherModal';
  18. import VipRenew from '../../../components/VipRenew';
  19. import { My } from '../../../stores/my';
  20. import { Main } from '../../../stores/main';
  21. class LogItem extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.columns = [
  25. { title: '', key: 'title' },
  26. { title: '语法SC', key: 'sc' },
  27. { title: '逻辑CR', key: 'cr' },
  28. { title: '阅读RC', key: 'rc' },
  29. ];
  30. this.state = { open: false };
  31. }
  32. render() {
  33. const { data = {} } = this.props;
  34. const { total = [], type } = data;
  35. const { open } = this.state;
  36. return (
  37. <div className="log-item">
  38. <div className="total">
  39. {total.map(item => {
  40. return (
  41. <div className="text" style={{ width: item.width }} dangerouslySetInnerHTML={{ __html: item.title }} />
  42. );
  43. })}
  44. </div>
  45. <div className="open">
  46. <GIcon name={open ? 'small-up' : 'small-down'} onClick={() => this.setState({ open: !open })} />
  47. </div>
  48. {type === 'exercise' && this.renderExercise()}
  49. {type === 'examination' && this.renderExamination()}
  50. {type === 'course' && this.renderCourse()}
  51. </div>
  52. );
  53. }
  54. renderExercise() {
  55. const { open } = this.state;
  56. return (
  57. <div hidden={!open} className="table">
  58. <UserTable size="small" columns={this.columns} data={[{ title: '123' }]} />
  59. <div className="t-r">
  60. <Link to="/exercise">继续练习></Link>
  61. </div>
  62. </div>
  63. );
  64. }
  65. renderExamination() {
  66. const { open } = this.state;
  67. return (
  68. <div hidden={!open} className="table">
  69. <div className="title p-l-5 m-b-1 t-1 t-s-18 f-w-b">
  70. 千行-CAT01<div className="f-r t-3 t-s-12 f-w-d">2019-05-16 16:21:06</div>
  71. </div>
  72. <UserTable
  73. size="small"
  74. columns={[
  75. { key: '1', title: '' },
  76. { key: '2', title: 'Tobal' },
  77. { key: '3', title: 'IR' },
  78. { key: '4', title: 'Verbal' },
  79. { key: '5', title: 'Quant' },
  80. ]}
  81. data={[{ title: '123' }]}
  82. />
  83. <div className="title p-l-5 m-b-1 t-1 t-s-18 f-w-b m-t-2">
  84. 净化版GWD-CAT01 <div className="f-r t-3 t-s-12 f-w-d">2019-05-16 16:21:06</div>
  85. </div>
  86. <UserTable
  87. size="small"
  88. columns={[
  89. { key: '1', title: '' },
  90. { key: '2', title: 'Tobal' },
  91. { key: '3', title: 'IR' },
  92. { key: '4', title: 'Verbal' },
  93. { key: '5', title: 'Quant' },
  94. ]}
  95. data={[{ title: '123' }]}
  96. />
  97. <div className="t-r">
  98. <Link to="/exercise">继续练习></Link>
  99. </div>
  100. </div>
  101. );
  102. }
  103. renderCourse() {
  104. const { open } = this.state;
  105. return (
  106. <div hidden={!open} className="table">
  107. <UserTable
  108. header={false}
  109. size="small"
  110. even="odd"
  111. columns={[{ key: '1', width: 100 }, { key: '2', width: 310 }, { key: '3', width: 120 }]}
  112. data={[
  113. { 1: '语法SC', 2: '课时3:代词的指代', 3: '2019-04-27\n 15:14:29' },
  114. { 1: '逻辑 RC', 2: '课时3:代词的指代', 3: '2019-04-27\n 15:14:29' },
  115. { 1: '阅读CR', 2: '课时3:代词的指代', 3: '2019-04-27\n 15:14:29' },
  116. { 1: '逻辑 RC', 2: '课时3:代词的指代', 3: '2019-04-27\n 15:14:29' },
  117. ]}
  118. />
  119. <div className="t-r">
  120. <Link to="/exercise">继续练习></Link>
  121. </div>
  122. </div>
  123. );
  124. }
  125. }
  126. export default class extends Page {
  127. initState() {
  128. return {
  129. day: 'today',
  130. showExamination: false,
  131. timeList: [
  132. { title: '长难句', time: '3h60min', ratio: 10, color: '#3C39CC' },
  133. { title: '综合推理IR', time: '3h60min', ratio: 10, color: '#9E9CFF' },
  134. { title: '语法SC', time: '3h60min', ratio: 10, color: '#4292F0' },
  135. { title: '作文AWA', time: '3h60min', ratio: 10, color: '#4374EC' },
  136. { title: '阅读RC', time: '3h60min', ratio: 10, color: '#6865FD' },
  137. { title: '模考', time: '3h60min', ratio: 10, color: '#8D65FD' },
  138. { title: '逻辑CR', time: '3h60min', ratio: 10, color: '#6BABF6' },
  139. { title: '自由组卷', time: '3h60min', ratio: 10, color: '#7BBEFF' },
  140. { title: '数学Quant', time: '3h60min', ratio: 10, color: '#6BABF6' },
  141. ],
  142. logList: [
  143. {
  144. total: [
  145. { title: '<span>练习和订正</span>', width: 130 },
  146. { title: '<b>60</b>min', width: 90 },
  147. { title: '<b>30</b>题', width: 80 },
  148. { title: '超过了<b>30%</b>的用户' },
  149. ],
  150. detail: [
  151. { title: '做题数', sc: '10', cr: '10', rc: '20' },
  152. { title: '平均正确率', sc: '86%', cr: '86%', rc: '86%' },
  153. { title: '平均用时', sc: '1min', cr: '1min20s', rc: '1min' },
  154. ],
  155. },
  156. {
  157. total: [
  158. { title: '<span>模考和订正</span>', width: 130 },
  159. { title: '<b>60</b>min', width: 90 },
  160. { title: '<b>30</b>套卷', width: 80 },
  161. { title: '超过了<b>30%</b>的用户' },
  162. ],
  163. detail: [
  164. { title: '做题数', sc: '10', cr: '10', rc: '20' },
  165. { title: '平均正确率', sc: '86%', cr: '86%', rc: '86%' },
  166. { title: '平均用时', sc: '1min', cr: '1min20s', rc: '1min' },
  167. ],
  168. },
  169. {
  170. total: [
  171. { title: '<span>课程学习</span>', width: 130 },
  172. { title: '<b>60</b>min', width: 90 },
  173. { title: '<b>30</b>课', width: 80 },
  174. { title: '超过了<b>30%</b>的用户' },
  175. ],
  176. detail: [
  177. { title: '做题数', sc: '10', cr: '10', rc: '20' },
  178. { title: '平均正确率', sc: '86%', cr: '86%', rc: '86%' },
  179. { title: '平均用时', sc: '1min', cr: '1min20s', rc: '1min' },
  180. ],
  181. },
  182. ],
  183. };
  184. }
  185. initData() {
  186. // 获取学习数据
  187. My.getStudyTotal().then(total => {
  188. this.setState({ total });
  189. });
  190. My.getStudyWeek(0).then(latest => {
  191. const diff = latest.time - latest.avgTime;
  192. const diffPercent =
  193. diff > 0
  194. ? formatPercent(latest.time - latest.avgTime, latest.avgTime, true)
  195. : formatPercent(latest.avgTime - latest.time, latest.avgTime, true);
  196. this.setState({ latest, diff, diffPercent });
  197. My.getStudyWeek(1).then(last => {
  198. const diffLast = latest.time - last.time;
  199. const diffLastPercent =
  200. diffLast > 0
  201. ? formatPercent(latest.time - last.time, last.time, true)
  202. : formatPercent(last.time - latest.time, last.time, true);
  203. this.setState({ last, diffLast, diffLastPercent });
  204. });
  205. });
  206. // 获取广告
  207. Main.getAd('my-self').then(result => {
  208. this.setState({ ads: result });
  209. });
  210. // 获取未读消息
  211. My.message({ page: 1, size: 2, read: 0 }).then(result => {
  212. this.setState({ messages: result.list });
  213. });
  214. this.refreshDay(this.state.day);
  215. }
  216. readAllMessage() {
  217. My.readAllMessage().then(() => {
  218. asyncSMessage('操作成功');
  219. });
  220. }
  221. refreshDay(value) {
  222. let time = '';
  223. switch (value) {
  224. case 'today':
  225. time = moment().format('YYYY-MM-DD');
  226. break;
  227. case 'yesterday':
  228. time = moment()
  229. .add(-1, 'days')
  230. .format('YYYY-MM-DD');
  231. break;
  232. case 'before':
  233. time = moment()
  234. .add(-2, 'days')
  235. .format('YYYY-MM-DD');
  236. break;
  237. default:
  238. time = value.format('YYYY-MM-DD');
  239. value = 'other';
  240. }
  241. My.getStudy(time).then(result => {
  242. const study = [];
  243. const exerciseMap = {};
  244. result.exerciseList.forEach(row => {
  245. exerciseMap[row.title] = row;
  246. });
  247. study.push({
  248. type: 'exercise',
  249. total: [
  250. { title: '<span>练习和订正</span>', width: 130 },
  251. {
  252. title: result.exerciseTime
  253. ? formatSeconds(result.exerciseTime).replace(/([0-9]+)(m|min|h|hour|s)/g, '<b>$1</b>$2')
  254. : '<b>-</b>',
  255. width: 90,
  256. },
  257. { title: `<b>${result.exerciseQuestion || '-'}</b>题`, width: 80 },
  258. {
  259. title: `超过了<b>${
  260. result.exerciseExceed ? formatPercent(result.exerciseExceed.rank, result.exerciseExceed.total) : '-%'
  261. }</b>的用户`,
  262. },
  263. ],
  264. detail: [
  265. {
  266. title: '做题数',
  267. sc: exerciseMap.sc ? exerciseMap.sc.number : '-',
  268. cr: exerciseMap.cr ? exerciseMap.cr.number : '-',
  269. rc: exerciseMap.rc ? exerciseMap.rc.number : '-',
  270. },
  271. {
  272. title: '平均正确率',
  273. sc: exerciseMap.sc ? formatPercent(exerciseMap.sc.correct, exerciseMap.sc.number) : '-%',
  274. cr: exerciseMap.cr ? formatPercent(exerciseMap.cr.correct, exerciseMap.cr.number) : '-%',
  275. rc: exerciseMap.rc ? formatPercent(exerciseMap.rc.correct, exerciseMap.rc.number) : '-%',
  276. },
  277. {
  278. title: '平均用时',
  279. sc: exerciseMap.sc ? exerciseMap.sc.time / exerciseMap.sc.number : '-',
  280. cr: exerciseMap.cr ? exerciseMap.cr.time / exerciseMap.cr.number : '-',
  281. rc: exerciseMap.rc ? exerciseMap.rc.time / exerciseMap.rc.number : '-',
  282. },
  283. ],
  284. });
  285. this.setState({ study });
  286. });
  287. this.setState({ day: value, time, showCal: false });
  288. }
  289. renderView() {
  290. const { config } = this.props;
  291. return (
  292. <UserLayout
  293. active={config.key}
  294. menu={menu}
  295. center={[this.renderTop(), this.renderLog(), this.renderTime()]}
  296. right={[this.renderInfo(), this.renderMessage()]}
  297. ads={(this.state.ads || []).map(row => {
  298. return (
  299. <a href={row.link} target="_blank">
  300. <Assets src={row.image} />
  301. </a>
  302. );
  303. })}
  304. />
  305. );
  306. }
  307. renderTop() {
  308. return null; // <div className="total-layout">1</div>;
  309. }
  310. renderLog() {
  311. const { study = [{}, { type: 'examination' }, { type: 'course' }] } = this.state;
  312. const {
  313. latest = {},
  314. diff = 0,
  315. diffPercent = 0,
  316. diffLast = 0,
  317. diffLastPercent = 0,
  318. day,
  319. time,
  320. showCal,
  321. } = this.state;
  322. return (
  323. <div className="log-layout">
  324. <div className="header">
  325. <div className="title">学习记录</div>
  326. <div className="right">
  327. <span
  328. dangerouslySetInnerHTML={{
  329. __html: `本周学习时间${formatSeconds(latest.time).replace(/([0-9]+)(m|min|h|hour|s)/g, '<b>$1</b>$2')}`,
  330. }}
  331. />
  332. <span>
  333. 同比上周<b>{diffLastPercent}</b>% <Assets name={diffLast > 0 ? 'up' : 'down'} />
  334. </span>
  335. <span>
  336. 同比全站<b>{diffPercent}</b>% <Assets name={diff > 0 ? 'up' : 'down'} />
  337. </span>
  338. </div>
  339. </div>
  340. <div className="action">
  341. <Tabs
  342. className="d-i-b"
  343. type="tag"
  344. width={54}
  345. space={5}
  346. active={day}
  347. tabs={[
  348. { title: '今天', key: 'today' },
  349. { title: '昨天', key: 'yesterday' },
  350. { title: '前天', key: 'before' },
  351. ]}
  352. onChange={value => {
  353. this.refreshDay(value);
  354. }}
  355. />
  356. <div className="right">
  357. {day === 'other' && formatDate(time, 'YYYY-MM-DD')}
  358. <Assets
  359. className="right"
  360. name="calendar"
  361. onClick={() => {
  362. this.setState({ showCal: true });
  363. }}
  364. />
  365. {showCal && (
  366. <Calendar
  367. className="cal"
  368. fullscreen={false}
  369. disabledDate={date => date.unix() <= moment.unix()}
  370. onSelect={date => {
  371. this.refreshDay(date);
  372. }}
  373. />
  374. )}
  375. </div>
  376. </div>
  377. {study.map((log, index) => {
  378. return <LogItem key={index} data={log} />;
  379. })}
  380. </div>
  381. );
  382. }
  383. renderTime() {
  384. const { timeList = [], total = {} } = this.state;
  385. return (
  386. <div className="time-layout">
  387. <div className="header">
  388. <div className="title">
  389. 时间分配
  390. <Tooltip overlayClassName="gray" title="包括听课、练习与订正">
  391. <Icon type="question-circle" theme="filled" />
  392. </Tooltip>
  393. </div>
  394. <div className="right">
  395. 自 {total.createTIme && formatDate(total.createTime, 'YYYY-MM-DD')} ,您已在千行学习<b>{total.days}</b>
  396. 天,累计
  397. <span
  398. dangerouslySetInnerHTML={{
  399. __html: formatSeconds(total.time).replace(/([0-9]+)(m|min|h|hour|s)/g, '<b>$1</b>$2'),
  400. }}
  401. />
  402. </div>
  403. </div>
  404. <div className="body">
  405. <div className="line">
  406. {timeList.map(item => {
  407. return (
  408. <Tooltip overlayClassName="gray" title={`${item.title} ${item.time}`}>
  409. <i style={{ background: item.color, width: `${item.ratio}%` }} />
  410. </Tooltip>
  411. );
  412. })}
  413. </div>
  414. <div className="list">
  415. {timeList.map(item => {
  416. return (
  417. <div className="item">
  418. <div className="color" style={{ background: item.color }} />
  419. <div className="title">{item.title}</div>
  420. <div className="date">{item.time}</div>
  421. </div>
  422. );
  423. })}
  424. </div>
  425. </div>
  426. </div>
  427. );
  428. }
  429. renderInfo() {
  430. const { info = {} } = this.props.user;
  431. const { showExamination, showPhone, showEmail, showEdit, showReal, showAvatar, showInvite, showVip } = this.state;
  432. return (
  433. <div className="info-layout">
  434. <div className="body">
  435. <div className="info">
  436. <Assets
  437. name="sun_blue"
  438. src={info.avatar}
  439. onClick={() => {
  440. this.setState({ showEdit: true });
  441. }}
  442. />
  443. <div className="detail">
  444. <div
  445. className="name"
  446. onClick={() => {
  447. this.setState({ showEdit: true });
  448. }}
  449. >
  450. {info.nickname}{' '}
  451. </div>
  452. <div className="id">ID: {info.id} </div>
  453. </div>
  454. </div>
  455. <div className="auth">
  456. <span className="invite">
  457. <Button
  458. radius
  459. size="small"
  460. onClick={() => {
  461. this.setState({ showInvite: true });
  462. }}
  463. >
  464. 邀请
  465. </Button>
  466. </span>
  467. <Assets name="wechat" active={info.bindWechat} />
  468. <Assets
  469. name="phone_1"
  470. active={info.bindMobile}
  471. onClick={() => {
  472. this.setState({ showPhone: true });
  473. }}
  474. />
  475. <Assets
  476. name="realname"
  477. active={info.bindReal}
  478. onClick={() => {
  479. this.setState({ showReal: true });
  480. }}
  481. />
  482. <Assets
  483. name="email"
  484. active={!!info.email}
  485. onClick={() => {
  486. this.setState({ showEmail: true });
  487. }}
  488. />
  489. <Assets
  490. name="information"
  491. active={info.bindPrepare}
  492. onClick={() => {
  493. this.setState({ showExamination: true });
  494. }}
  495. />
  496. </div>
  497. </div>
  498. {
  499. <div className="footer">
  500. <Assets className="m-r-5" name="VIP" />
  501. {info.vip && <span className="date">{formatDate(info.vip, 'YYYY-MM-DD')}到期</span>}
  502. <a
  503. onClick={() => {
  504. this.setState({ showVip: true });
  505. }}
  506. >
  507. 续费
  508. </a>
  509. </div>
  510. }
  511. <Examination
  512. show={showExamination}
  513. data={info}
  514. onConfirm={() => this.setState({ showExamination: false })}
  515. onCancel={() => this.setState({ showExamination: false })}
  516. onClose={() => this.setState({ showExamination: false })}
  517. />
  518. <BindPhone
  519. show={showPhone}
  520. data={info}
  521. onConfirm={() => this.setState({ showPhone: false })}
  522. onCancel={() => this.setState({ showPhone: false })}
  523. />
  524. <BindEmail
  525. show={showEmail}
  526. data={info}
  527. onConfirm={() => this.setState({ showEmail: false })}
  528. onCancel={() => this.setState({ showEmail: false })}
  529. />
  530. <EditInfo
  531. show={showEdit}
  532. data={info}
  533. image={this.state.avatarFile}
  534. onSelectImage={file => this.setState({ showEdit: false, showAvatar: true, avatarImage: file })}
  535. onConfirm={() => this.setState({ showEdit: false, avatarFile: null })}
  536. onCancel={() => this.setState({ showEdit: false, avatarFile: null })}
  537. />
  538. <RealAuth show={showReal} data={info} onConfirm={() => this.setState({ showReal: false })} />
  539. <EditAvatar
  540. show={showAvatar}
  541. data={info}
  542. crop={{ width: 200, height: 200 }}
  543. image={this.state.avatarImage}
  544. onConfirm={file => this.setState({ showAvatar: false, showEdit: true, avatarFile: file, avatarImage: null })}
  545. onCancel={() => this.setState({ showAvatar: false, showEdit: true, avatarImage: null })}
  546. />
  547. <InviteModal show={showInvite} data={info} onClose={() => this.setState({ showInvite: false })} />
  548. <VipRenew
  549. show={showVip}
  550. data={info}
  551. onReal={() => this.setState({ showVip: false, showReal: true })}
  552. onPrepare={() => this.setState({ showVip: false, showExamination: true })}
  553. onClose={() => this.setState({ showVip: false })}
  554. />
  555. </div>
  556. );
  557. }
  558. renderMessage() {
  559. const { messages = [] } = this.state;
  560. const number = (messages || []).length;
  561. return (
  562. number > 0 && (
  563. <div className="message-layout">
  564. <div className="header">
  565. <Assets
  566. name="all"
  567. onCancel={() => {
  568. this.readAllMessage();
  569. }}
  570. />
  571. 全部已读
  572. </div>
  573. <div className="body">
  574. {(messages || []).map(row => {
  575. return (
  576. <div className="item">
  577. <div className="title dot">老师回答了您的提问</div>
  578. <div className="date">{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  579. {row.link && (
  580. <GIcon
  581. name="arrow-right-small"
  582. onClick={() => {
  583. openLink(row.link);
  584. }}
  585. />
  586. )}
  587. </div>
  588. );
  589. })}
  590. </div>
  591. <div className="footer">
  592. <Button
  593. radius
  594. size="small"
  595. onClick={() => {
  596. linkTo('/my/message');
  597. }}
  598. >
  599. 全部消息
  600. </Button>
  601. </div>
  602. </div>
  603. )
  604. );
  605. }
  606. }