page.js 19 KB

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