page.js 14 KB

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