page.js 14 KB

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