1
0

page.js 17 KB

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