page.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. import React from 'react';
  2. import './index.less';
  3. import { Modal } from 'antd';
  4. import { Link } from 'react-router-dom';
  5. import Page from '@src/containers/Page';
  6. import { asyncConfirm } from '@src/services/AsyncTools';
  7. import { formatTreeData, formatSeconds, formatDate, formatPercent, getMap } from '@src/services/Tools';
  8. import Continue from '../../../components/Continue';
  9. import Step from '../../../components/Step';
  10. import Panel from '../../../components/Panel';
  11. import List from '../../../components/List';
  12. import Tabs from '../../../components/Tabs';
  13. import Module from '../../../components/Module';
  14. import Input from '../../../components/Input';
  15. import Button from '../../../components/Button';
  16. import AnswerButton from '../../../components/AnswerButton';
  17. import Division from '../../../components/Division';
  18. import { Card1 } from '../../../components/Card';
  19. import ListTable from '../../../components/ListTable';
  20. import ProgressText from '../../../components/ProgressText';
  21. import IconButton from '../../../components/IconButton';
  22. import QAList from '../../../components/QAList';
  23. import { Main } from '../../../stores/main';
  24. import { My } from '../../../stores/my';
  25. import { Sentence } from '../../../stores/sentence';
  26. import { Question } from '../../../stores/question';
  27. import { Course } from '../../../stores/course';
  28. import { User } from '../../../stores/user';
  29. import { CourseModuleShow, CourseModule } from '../../../../Constant';
  30. import { Order } from '../../../stores/order';
  31. const SENTENCE = 'sentence';
  32. const PREVIEW = 'preview';
  33. const PREVIEW_COURSE = 'PREVIEW_COURSE';
  34. const PREVIEW_LIST = 'PREVIEW_LIST';
  35. const CourseModuleMap = getMap(CourseModule, 'value', 'label');
  36. const CourseSorted = getMap([{ value: 'sc', sort: 1 }, { value: 'rc', sort: 2 }, { value: 'cr', sort: 3 }], 'value', 'sort');
  37. const exerciseColumns = [{
  38. title: '练习册',
  39. width: 250,
  40. align: 'left',
  41. render: record => {
  42. let progress = 0;
  43. if (record.report) {
  44. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  45. }
  46. return (
  47. <div className="table-row">
  48. <div className="night f-s-16">{record.title}</div>
  49. <div>
  50. <ProgressText progress={progress} times={record.paper ? record.paper.times : 0} size="small" />
  51. </div>
  52. </div>
  53. );
  54. },
  55. }, {
  56. title: '正确率',
  57. width: 150,
  58. align: 'left',
  59. render: item => {
  60. return (
  61. <div className="table-row">
  62. <div className="night f-s-16 f-w-b">--</div>
  63. <div className="f-s-12">{formatPercent(item.stat.totalCorrect, item.stat.totalNumber, false)}</div>
  64. </div>
  65. );
  66. },
  67. }, {
  68. title: '全站用时',
  69. width: 150,
  70. align: 'left',
  71. render: record => {
  72. let time = '--';
  73. if (record.paper) {
  74. time = formatSeconds(record.paper.report.userTime / record.paper.report.userNumber);
  75. }
  76. return (
  77. <div className="table-row">
  78. <div className="night f-s-16 f-w-b">{time}</div>
  79. <div className="f-s-12">全站{formatSeconds(record.stat.totalTime / record.stat.totalNumber)}</div>
  80. </div>
  81. );
  82. },
  83. }, {
  84. title: '最近做题',
  85. width: 150,
  86. align: 'left',
  87. render: (record) => {
  88. const time = record.report ? record.report.updateTime : record.paper ? record.paper.latestTime : null;
  89. return (
  90. <div className="table-row">
  91. <div>{time && formatDate(time, 'YYYY-MM-DD')}</div>
  92. <div>{time && formatDate(time, 'HH:mm')}</div>
  93. </div>
  94. );
  95. },
  96. }, {
  97. title: '操作',
  98. width: 180,
  99. align: 'left',
  100. render: record => {
  101. return (
  102. <div className="table-row p-t-1">
  103. {!record.report && <IconButton type="start" tip="Start" onClick={() => {
  104. Question.startLink('exercise', record);
  105. }} />}
  106. {(record.report && !record.report.isFinish) && <IconButton className="m-r-2" type="continue" tip="Continue" onClick={() => {
  107. Question.continueLink('exercise', record);
  108. }} />}
  109. <IconButton type="restart" tip="Restart" onClick={() => {
  110. this.restart(record);
  111. }} />
  112. </div>
  113. );
  114. },
  115. }, {
  116. title: '报告',
  117. width: 30,
  118. align: 'right',
  119. render: record => {
  120. return (
  121. <div className="table-row p-t-1">
  122. {record.report && record.report.isFinish && <IconButton type="report" tip="Report" onClick={() => {
  123. Question.reportLink(record);
  124. }} />}
  125. </div>
  126. );
  127. },
  128. }];
  129. export default class extends Page {
  130. constructor(props) {
  131. super(props);
  132. this.sentenceColums = [{
  133. title: '练习册',
  134. width: 250,
  135. align: 'left',
  136. render: record => {
  137. let progress = 0;
  138. if (record.report) {
  139. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  140. }
  141. return (
  142. <div className="table-row">
  143. <div className="night f-s-16">{record.title}</div>
  144. <div>
  145. <ProgressText progress={progress} times={record.paper ? record.paper.times : 0} size="small" />
  146. </div>
  147. </div>
  148. );
  149. },
  150. }, {
  151. title: '正确率',
  152. width: 150,
  153. align: 'left',
  154. render: record => {
  155. let correct = '--';
  156. if (record.report) {
  157. correct = formatPercent(record.report.userCorrect, record.report.userNumber, false);
  158. }
  159. return (
  160. <div className="table-row">
  161. <div className="night f-s-16 f-w-b">{correct}</div>
  162. <div className="f-s-12">
  163. 全站{formatPercent(record.stat.totalCorrect, record.stat.totalNumber, false)}
  164. </div>
  165. </div>
  166. );
  167. },
  168. }, {
  169. title: '全站用时',
  170. width: 150,
  171. align: 'left',
  172. render: record => {
  173. let time = '--';
  174. if (record.report) {
  175. time = formatSeconds(record.report.userTime / record.report.userNumber);
  176. }
  177. return (
  178. <div className="table-row">
  179. <div className="night f-s-16 f-w-b">{time}</div>
  180. <div className="f-s-12">全站{formatSeconds(record.stat.totalTime / record.stat.totalNumber)}</div>
  181. </div>
  182. );
  183. },
  184. }, {
  185. title: '最近做题',
  186. width: 150,
  187. align: 'left',
  188. render: record => {
  189. const time = record.report ? record.report.updateTime : record.paper ? record.paper.latestTime : null;
  190. return (
  191. <div className="table-row">
  192. <div>{time && formatDate(time, 'YYYY-MM-DD')}</div>
  193. <div>{time && formatDate(time, 'HH:mm')}</div>
  194. </div>
  195. );
  196. },
  197. }, {
  198. title: '操作',
  199. width: 180,
  200. align: 'left',
  201. render: record => {
  202. return (
  203. <div className="table-row p-t-1">
  204. {!record.report && (
  205. <IconButton
  206. type="start"
  207. tip="Start"
  208. onClick={() => {
  209. User.needLogin()
  210. .then(() => {
  211. Question.startLink('sentence', record);
  212. });
  213. }}
  214. />
  215. )}
  216. {record.report && !record.report.isFinish && (
  217. <IconButton
  218. className="m-r-2"
  219. type="continue"
  220. tip="Continue"
  221. onClick={() => {
  222. User.needLogin()
  223. .then(() => {
  224. Question.continueLink('sentence', record);
  225. });
  226. }}
  227. />
  228. )}
  229. {record.report && !!record.report.isFinish && (
  230. <IconButton
  231. type="restart"
  232. tip="Restart"
  233. onClick={() => {
  234. User.needLogin()
  235. .then(() => {
  236. this.restart(record);
  237. });
  238. }}
  239. />
  240. )}
  241. </div>
  242. );
  243. },
  244. }, {
  245. title: '报告',
  246. width: 30,
  247. align: 'right',
  248. render: record => {
  249. return (
  250. <div className="table-row p-t-1">
  251. {record.report && record.report.isFinish > 0 && <IconButton type="report" tip="Report" onClick={() => {
  252. User.needLogin()
  253. .then(() => {
  254. Question.reportLink(record);
  255. });
  256. }} />}
  257. </div>
  258. );
  259. },
  260. }];
  261. }
  262. initState() {
  263. this.code = null;
  264. this.columns = exerciseColumns;
  265. this.exerciseProgress = {};
  266. this.courseProgress = {};
  267. this.inited = false;
  268. return {
  269. tab1: SENTENCE,
  270. tab2: '',
  271. previewType: PREVIEW_COURSE,
  272. tabs: [],
  273. allCourse: [],
  274. courseProgress: {},
  275. };
  276. }
  277. init() {
  278. Main.getExercise().then(result => {
  279. const list = result.map(row => {
  280. row.title = `${row.titleZh}${row.titleEn}`;
  281. row.key = row.extend;
  282. return row;
  283. });
  284. const tabs = formatTreeData(list, 'id', 'title', 'parentId');
  285. // 课程顶级分类
  286. const courseStructs = result.filter(row => row.isCourse && row.level === 1);
  287. courseStructs.unshift({ key: '', name: '全部' });
  288. tabs.push({ key: PREVIEW, name: '预习作业' });
  289. this.courseStructMap = getMap(courseStructs, 'id', 'title');
  290. this.setState({
  291. tabs,
  292. courseStructs,
  293. courseTabs: CourseModuleShow.map(row => {
  294. row.title = row.label;
  295. row.key = row.value;
  296. return row;
  297. }),
  298. });
  299. this.inited = true;
  300. this.refreshData();
  301. });
  302. Main.getContract('course')
  303. .then(result => {
  304. this.setState({ contract: result });
  305. });
  306. }
  307. initData() {
  308. const { info = {} } = this.props.user;
  309. if (info.latestExercise) {
  310. // 获取最后一次做题记录
  311. Question.baseReport(info.latestExercise).then(result => {
  312. this.setState({ latest: result });
  313. });
  314. }
  315. const data = Object.assign(this.state, this.state.search);
  316. if (!data.tab1) {
  317. data.tab1 = SENTENCE;
  318. }
  319. if (data.recordId) {
  320. // 作业列表
  321. data.previewType = PREVIEW_LIST;
  322. }
  323. this.setState(data);
  324. if (this.inited) this.refreshData();
  325. }
  326. refreshData(tab) {
  327. const { tab1 } = this.state;
  328. switch (tab || tab1) {
  329. case SENTENCE:
  330. this.refreshSentence();
  331. break;
  332. case PREVIEW:
  333. this.refreshPreview();
  334. break;
  335. default:
  336. this.refreshExercise(tab || tab1);
  337. }
  338. }
  339. refreshSentence() {
  340. const { sentence } = this.state;
  341. if (!sentence) {
  342. User.clearSentenceTrail();
  343. Sentence.getInfo()
  344. .then(result => {
  345. // result.code = '123123';
  346. // result.trailPages = 20;
  347. this.setState({ sentence: result });
  348. return result;
  349. })
  350. .then(({ code, trailPages, chapters }) => {
  351. return Sentence.listArticle().then(result => {
  352. const chapterSteps = [];
  353. const chapterMap = {};
  354. const map = {};
  355. const trailArticles = [];
  356. let totalPage = 0;
  357. let introduction = null;
  358. let exerciseChapter = null;
  359. let index = 0;
  360. let lastChapter = -1;
  361. chapters.forEach(row => {
  362. chapterMap[row.value] = row;
  363. if (row.exercise) exerciseChapter = row;
  364. });
  365. result.forEach(article => {
  366. if (article.chapter === 0) introduction = article;
  367. if (!map[article.chapter]) {
  368. map[article.chapter] = [];
  369. }
  370. article.startPage = totalPage + 1;
  371. article.endPage = totalPage + article.pages;
  372. if (article.chapter) {
  373. article.position = `Part ${article.part}`;
  374. } else {
  375. // 设置list中的样式
  376. article.style = 'introduction';
  377. }
  378. totalPage += article.pages;
  379. if (article.startPage < trailPages) {
  380. if (lastChapter !== article.chapter) {
  381. lastChapter = article.chapter;
  382. trailArticles.push(Object.assign({ articles: [] }, chapterMap[article.chapter] || {}));
  383. }
  384. trailArticles[trailArticles.length - 1].articles.push(article);
  385. }
  386. map[article.chapter].push(article);
  387. });
  388. if (!code) {
  389. chapterSteps.push('试用');
  390. }
  391. // 添加前言
  392. if (introduction) {
  393. chapterSteps.push(`${introduction.title}`);
  394. chapterMap[0] = {
  395. title: introduction.title,
  396. value: 0,
  397. };
  398. }
  399. index += 1;
  400. chapters.forEach(row => {
  401. chapterSteps.push(`「${index}」${row.short}`);
  402. index += 1;
  403. });
  404. this.setState({ articleMap: map, trailArticles, chapterSteps, introduction, chapterMap, exerciseChapter });
  405. });
  406. })
  407. .then(() => {
  408. return Sentence.listPaper().then(result => {
  409. this.setState({ paperList: result, paperFilterList: result });
  410. });
  411. });
  412. }
  413. }
  414. refreshPreview() {
  415. const { previewType } = this.state;
  416. switch (previewType) {
  417. case PREVIEW_LIST:
  418. this.refreshListPreview();
  419. break;
  420. case PREVIEW_COURSE:
  421. default:
  422. this.refreshCourseProcess();
  423. break;
  424. }
  425. }
  426. refreshCourseProcess() {
  427. const { courseTabs, courseStructs, struct } = this.state;
  428. let { tab2 } = this.state;
  429. let tab;
  430. if (tab2 === '') {
  431. tab2 = courseTabs[0].key;
  432. this.setState({ tab2 });
  433. ([tab] = courseTabs);
  434. } else {
  435. ([tab] = courseTabs.filter(row => row.key === tab2));
  436. }
  437. const [courseStruct] = courseStructs.filter(row => row.key === struct);
  438. Course.progress(tab.value, courseStruct ? courseStruct.id : null).then(result => {
  439. const courseMap = {};
  440. // 排序:sc,rc,cr
  441. result = result.map(row => {
  442. row.sort = CourseSorted[row.course.extend] || 10;
  443. return row;
  444. });
  445. result.sort((a, b) => {
  446. return a.sort < b.sort ? -1 : (a.sort > b.sort ? 1 : 0);
  447. });
  448. const now = new Date().getTime();
  449. courseMap.open = result.filter(row => !row.isUsed && (!row.useEndTime || new Date(row.useEndTime).getTime() > now));
  450. courseMap.end = result.filter(row => (!row.isSuspend || (row.isSuspend && row.restoreTime)) && new Date(row.useEndTime).getTime() < now);
  451. courseMap.process = result.filter(row => row.isUsed && ((!row.isSuspend && new Date(row.useEndTime).getTime() >= now) || (row.isSuspend && !row.restoreTime)));
  452. this.setState({ courseMap });
  453. });
  454. Main.listFaq({ page: 1, size: 100, channel: 'exercise-preview' }).then(result => {
  455. this.setState({ faqs: result.list });
  456. });
  457. }
  458. refreshListPreview() {
  459. const { recordId, endTime, finish } = this.state;
  460. Course.listPreview({ recordId, endTime, finish }).then(result => {
  461. this.setState({ previews: result.list });
  462. });
  463. Course.record(recordId).then(result => {
  464. this.setState({ record: result });
  465. });
  466. }
  467. refreshExercise(tab) {
  468. const { tabs, tab1 } = this.state;
  469. let { tab2 } = this.state;
  470. if (!tabs) {
  471. // 等待数据加载
  472. return;
  473. }
  474. const [subject] = tabs.filter(row => row.key === tab);
  475. // 切换tab1的情况
  476. if (tab2 === '' || tab1 !== tab) {
  477. tab2 = subject.children[0].key;
  478. this.setState({ tab2 });
  479. }
  480. const [type] = subject.children.filter(row => row.key === tab2);
  481. Question.getExerciseProgress(type.id).then(result => {
  482. // const exerciseProgress = getMap(r, 'id');
  483. result = result.map(row => {
  484. row.info = [
  485. {
  486. title: '已做',
  487. number: row.userNumber || '-',
  488. unit: '题',
  489. },
  490. {
  491. title: '剩余',
  492. number: row.userNumber ? row.questionNumber - row.userNumber : '-',
  493. unit: '题',
  494. },
  495. {
  496. title: '总计',
  497. number: row.questionNumber || 0,
  498. unit: '题',
  499. },
  500. ];
  501. if (row.userStat) {
  502. row.correct = formatPercent(row.userStat.userCorrect, row.userStat.userNumber, false);
  503. } else {
  504. row.correct = '--';
  505. }
  506. row.progress = formatPercent(row.questionNumber - row.userNumber || 0, row.questionNumber);
  507. row.totalCorrect = formatPercent(row.stat.totalCorrect, row.stat.totalNumber, false);
  508. row.pieValue = formatPercent(row.userNumber, row.questionNumber);
  509. row.pieText = formatPercent(row.userNumber, row.questionNumber, false);
  510. row.pieSubText = `共${row.questionNumber}题`;
  511. row.children = row.children.map(r => {
  512. r.title = r.title || r.titleZh;
  513. r.progress = formatPercent(r.userNumber, r.questionNumber);
  514. return r;
  515. });
  516. return row;
  517. });
  518. this.setState({ exerciseProgress: result });
  519. });
  520. }
  521. onChangeTab(level, tab) {
  522. const { tab1 } = this.state;
  523. const data = {};
  524. if (level > 1) {
  525. data.tab1 = tab1;
  526. data.tab2 = tab;
  527. } else {
  528. data.tab1 = tab;
  529. }
  530. // this.refreshData(tab);
  531. this.refreshQuery(data);
  532. }
  533. onChangeCourse(struct) {
  534. const { tab1, tab2 } = this.state;
  535. const data = {
  536. tab1, tab2, struct,
  537. };
  538. this.refreshQuery(data);
  539. }
  540. onPreviewCourse() {
  541. const { tab1, tab2, struct } = this.state;
  542. const data = {
  543. tab1, tab2, struct,
  544. };
  545. this.refreshQuery(data);
  546. }
  547. onPreviewList(recordId) {
  548. const { tab1, tab2, struct } = this.state;
  549. const data = {
  550. tab1, tab2, struct, recordId,
  551. };
  552. this.refreshQuery(data);
  553. }
  554. previewAction(type, item) {
  555. switch (type) {
  556. case 'start':
  557. Question.startLink('preview', item);
  558. break;
  559. case 'restart':
  560. this.restart(item);
  561. break;
  562. case 'continue':
  563. Question.continueLink('preview', item);
  564. break;
  565. default:
  566. break;
  567. }
  568. }
  569. // 开通课程
  570. open(recordId) {
  571. Order.useRecord(recordId).then(() => {
  572. this.refresh();
  573. });
  574. }
  575. restart(item) {
  576. asyncConfirm('提示', '是否重置', () => {
  577. Question.restart(item.paper.id).then(() => {
  578. this.refresh();
  579. });
  580. });
  581. }
  582. exerciseList(item) {
  583. User.needLogin().then(() => {
  584. linkTo(`/exercise/list/${item.id}`);
  585. });
  586. }
  587. activeSentence() {
  588. User.needLogin().then(() => {
  589. Sentence.active(this.code)
  590. .then(() => {
  591. // 重新获取长难句信息
  592. User.clearSentenceTrail();
  593. this.setState({ sentence: null, articleMap: null, paperList: null });
  594. this.refresh();
  595. })
  596. .catch(err => {
  597. this.setState({ sentenceError: err.message });
  598. });
  599. });
  600. }
  601. trailSentence() {
  602. User.needLogin().then(() => {
  603. User.sentenceTrail();
  604. this.setState({ sentenceError: null });
  605. });
  606. }
  607. sentenceRead(article) {
  608. if (article) {
  609. linkTo(`/sentence/read?chapter=${article.chapter}&part=${article.part}`);
  610. } else {
  611. linkTo('/sentence/read');
  612. }
  613. }
  614. sentenceFilter(value) {
  615. const { paperChecked, paperList } = this.state;
  616. value = paperChecked === value ? null : value;
  617. const list = paperList.filter(row => {
  618. const finish = row.paper ? row.paper.times > 0 : false;
  619. if (value === 0) {
  620. return !finish;
  621. } if (value === 1) {
  622. return finish;
  623. }
  624. return true;
  625. });
  626. this.setState({ paperFilterList: list, paperChecked: value });
  627. }
  628. clearExercise() {
  629. My.clearLatestExercise()
  630. .then(() => {
  631. const { info } = this.props.user;
  632. info.latestExercise = 0;
  633. User.infoHandle(info);
  634. });
  635. this.setState({ latest: null });
  636. }
  637. renderView() {
  638. const { tab1, tab2, tabs, latest, sentenceModel, previewType, courseTabs = [] } = this.state;
  639. const [subject] = tabs.filter(row => row.key === tab1);
  640. const children = (subject && subject.children) ? subject.children : (tab1 === 'preview' && previewType === PREVIEW_COURSE ? courseTabs : []);
  641. return (
  642. <div>
  643. {latest && (
  644. <Continue
  645. data={latest}
  646. onClose={() => {
  647. this.clearExercise();
  648. }}
  649. onContinue={() => {
  650. Question.continueLink('exercise', { id: latest.originId, report: latest });
  651. }}
  652. onRestart={() => {
  653. this.restart(latest);
  654. Question.startLink('exercise', { id: latest.originId, report: latest });
  655. }}
  656. onNext={() => {
  657. Question.continueLink('exercise', { id: latest.originId, report: latest });
  658. }}
  659. />
  660. )}
  661. <div className="content">
  662. <Module className="m-t-2">
  663. <Tabs
  664. type="card"
  665. active={tab1}
  666. tabs={tabs}
  667. onChange={key => {
  668. this.onChangeTab(1, key);
  669. }}
  670. />
  671. {children && children.length > 1 && (
  672. <Tabs active={tab2} tabs={children} onChange={key => this.onChangeTab(2, key)} />
  673. )}
  674. </Module>
  675. {tab1 !== SENTENCE && tab1 !== PREVIEW && this.renderExercise()}
  676. {tab1 === SENTENCE && this.renderSentence()}
  677. {tab1 === PREVIEW && this.renderPreview()}
  678. {this.state.faqs && <QAList data={this.state.faqs} active={'faq'} tabs={[{ key: 'faq', name: 'FAQs' }]} />}
  679. </div>
  680. {sentenceModel && this.renderInputCodeModel()}
  681. </div>
  682. );
  683. }
  684. renderPreview() {
  685. const { previewType } = this.state;
  686. switch (previewType) {
  687. case PREVIEW_COURSE:
  688. return this.renderPreviewCourse();
  689. case PREVIEW_LIST:
  690. return this.renderPreviewList();
  691. default:
  692. return <div />;
  693. }
  694. }
  695. renderPreviewCourse() {
  696. const { courseStructs, struct, tab2, courseTabs, courseMap = {}, contract = {} } = this.state;
  697. return (
  698. <div className="work-body">
  699. <div className="work-nav" hidden={courseTabs && courseTabs.length > 0 && tab2 !== courseTabs[0].key}>
  700. <Tabs
  701. type="tag"
  702. active={struct || ''}
  703. space={5}
  704. tabs={courseStructs}
  705. onChange={key => {
  706. this.onChangeCourse(key);
  707. }}
  708. />
  709. </div>
  710. <div className="work-nav">
  711. <div className="left">学习中</div>
  712. </div>
  713. <Division col="3">
  714. {(courseMap.process || []).map(row => {
  715. return <Card1
  716. title={`${row.course.title}${row.vsNo > 0 ? `V${row.vsNo}` : ''}${row.number > 0 ? `(${row.number}课时)` : ''}`}
  717. tag={CourseModuleMap[row.course.courseModule]}
  718. status={row.isSuspend && !row.restoreTime ? 'stop' : 'ing'}
  719. list={(row.papers || []).map(r => {
  720. let progress = 0;
  721. if (r.report) {
  722. progress = formatPercent(r.report.userNumber, r.report.questionNumber);
  723. }
  724. r.progress = progress;
  725. return r;
  726. })}
  727. data={row}
  728. onPreview={() => {
  729. this.onPreviewList(row.id);
  730. }}
  731. previewAction={(type, item) => {
  732. this.previewAction(type, item);
  733. }}
  734. />;
  735. })}
  736. </Division>
  737. <div className="work-nav">
  738. <div className="left">待开通</div>
  739. </div>
  740. <Division col="3">
  741. {(courseMap.open || []).map(row => {
  742. return <Card1
  743. title={`${row.course.title}${row.vsNo > 0 ? `V${row.vsNo}` : ''}${row.number > 0 ? `(${row.number}课时)` : ''}`}
  744. tag={CourseModuleMap[row.course.courseModule]}
  745. contract={contract}
  746. status='open'
  747. data={row}
  748. onOpen={() => {
  749. this.open(row.id);
  750. }}
  751. />;
  752. })}
  753. </Division>
  754. <div className="work-nav">
  755. <div className="left">已结束</div>
  756. </div>
  757. <Division col="3">
  758. {(courseMap.end || []).map(row => {
  759. return <Card1
  760. title={`${row.course.title}${row.vsNo > 0 ? `V${row.vsNo}` : ''}${row.number > 0 ? `(${row.number}课时)` : ''}`}
  761. tag={CourseModuleMap[row.course.courseModule]}
  762. status='end'
  763. data={row}
  764. onPreview={() => {
  765. this.onPreviewList(row.id);
  766. }}
  767. />;
  768. })}
  769. </Division>
  770. </div>
  771. );
  772. }
  773. renderPreviewList() {
  774. const { previews = [], record = {}, search = {} } = this.state;
  775. const { finish, endTime } = search;
  776. let finishTime = '';
  777. if (endTime) {
  778. const endTimeD = new Date(endTime);
  779. const now = new Date();
  780. if ((now.getTime() + 86400000) > endTimeD.getTime()) {
  781. finishTime = 'today';
  782. } else {
  783. finishTime = 'tomorrow';
  784. }
  785. }
  786. return (
  787. <div className="work-body">
  788. <div className="work-nav">
  789. <div className="left">{`${(record.course || {}).title || ''}${record.vsNo > 0 ? `V${record.vsNo}` : ''}${record.number > 0 ? `(${record.number}课时)` : ''}`}全部作业</div>
  790. <div className="right theme c-p" onClick={() => this.onPreviewCourse()}>
  791. 我的课程 >
  792. </div>
  793. </div>
  794. <ListTable
  795. filters={[
  796. {
  797. type: 'radio',
  798. checked: finishTime,
  799. list: [{ key: 'today', title: '今日需完成' }, { key: 'tomorrow', title: '明日需完成' }],
  800. onChange: (item) => {
  801. if (item.key === finishTime) {
  802. this.search({ endTime: null });
  803. } else if (item.key === 'today') {
  804. const a = new Date();
  805. a.setDate(a.getDate() + 1);
  806. a.setHours(0);
  807. a.setMinutes(0);
  808. a.setMilliseconds(0);
  809. a.setSeconds(0);
  810. this.search({ endTime: formatDate(a, 'YYYY-MM-DD') });
  811. } else if (item.key === 'tomorrow') {
  812. const a = new Date();
  813. a.setDate(a.getDate() + 2);
  814. a.setHours(0);
  815. a.setMinutes(0);
  816. a.setMilliseconds(0);
  817. a.setSeconds(0);
  818. this.search({ endTime: formatDate(a, 'YYYY-MM-DD') });
  819. } else {
  820. this.search({ endTime: null });
  821. }
  822. },
  823. },
  824. {
  825. type: 'radio',
  826. checked: finish,
  827. list: [{ key: '0', title: '未完成' }, { key: '1', title: '已完成' }],
  828. onChange: (item) => {
  829. if (item.key === finish) {
  830. this.search({ finish: null });
  831. } else if (item.key === '0') {
  832. this.search({ finish: '0' });
  833. } else if (item.key === '1') {
  834. this.search({ finish: '1' });
  835. } else {
  836. this.search({ finish: null });
  837. }
  838. },
  839. },
  840. ]}
  841. data={previews}
  842. columns={this.columns}
  843. />
  844. </div>
  845. );
  846. }
  847. renderSentence() {
  848. const { sentence = {} } = this.state;
  849. const { sentenceTrail } = this.props.user;
  850. if (sentence.code || sentenceTrail) {
  851. return this.renderSentenceArticle();
  852. }
  853. return this.renderInputCode();
  854. }
  855. renderSentenceArticle() {
  856. const {
  857. sentence = {},
  858. introduction,
  859. chapterSteps,
  860. chapterStep = 1,
  861. exerciseChapter = {},
  862. chapterMap = {},
  863. articleMap = {},
  864. trailArticles = [],
  865. paperFilterList = [],
  866. paperList = [],
  867. paperChecked,
  868. sentenceInfo = {},
  869. } = this.state;
  870. const { sentenceTrail } = this.props.user;
  871. let maxStep = 0;
  872. if (sentenceTrail) {
  873. // 试用只能访问第一step
  874. maxStep = 1;
  875. // 查找练习章节
  876. }
  877. // 减去前言计算chapter
  878. const chapter = introduction ? chapterStep - 1 : chapterStep;
  879. const chapterInfo = chapterMap[chapter] || {};
  880. let isExercise = false;
  881. if (chapterInfo && chapterInfo.exercise) {
  882. isExercise = true;
  883. }
  884. return (
  885. <div>
  886. {sentence.code && <div className="sentence-code">CODE: {sentence.code}</div>}
  887. {sentenceTrail && (
  888. <div className="sentence-code">
  889. CODE: <a href={sentenceInfo.link} target="_blank">去获取</a>
  890. <a
  891. onClick={() => {
  892. this.setState({ sentenceModel: true });
  893. }}
  894. >
  895. 输入
  896. </a>
  897. </div>
  898. )}
  899. <Module>
  900. <Step
  901. list={chapterSteps}
  902. step={chapterStep}
  903. onClick={step => {
  904. this.setState({ chapterStep: step });
  905. }}
  906. message="请购买后访问"
  907. maxStep={maxStep}
  908. />
  909. </Module>
  910. {/* 正常前言 */}
  911. {sentence.code && chapter === 0 && (
  912. <List
  913. // title={chapterInfo.title}
  914. list={[introduction]}
  915. onClick={() => {
  916. this.sentenceRead();
  917. }}
  918. />
  919. )}
  920. {/* 正常文章 */}
  921. {sentence.code && chapter > 0 && !isExercise && (
  922. <List
  923. position={`Chapter${chapter}`}
  924. title={chapterInfo.title}
  925. list={articleMap[chapter]}
  926. onClick={part => {
  927. this.sentenceRead(part);
  928. }}
  929. />
  930. )}
  931. {/* 正常练习 */}
  932. {sentence.code && isExercise && (
  933. <ListTable
  934. position={`Chapter${chapter}`}
  935. title={chapterInfo.title}
  936. filters={[
  937. {
  938. type: 'radio',
  939. checked: paperChecked,
  940. list: [{ key: 0, title: '未完成' }, { key: 1, title: '已完成' }],
  941. onChange: item => {
  942. this.sentenceFilter(item.key);
  943. },
  944. },
  945. ]}
  946. data={paperFilterList}
  947. columns={this.sentenceColums}
  948. />
  949. )}
  950. {/* 试读文章 */}
  951. {sentenceTrail &&
  952. trailArticles.map(info => {
  953. return (
  954. <List
  955. position={info.value ? `Chapter${info.value}` : null}
  956. title={info.title}
  957. list={info.articles}
  958. onClick={part => {
  959. this.sentenceRead(part);
  960. }}
  961. />
  962. );
  963. })}
  964. {/* 试练 */}
  965. {sentenceTrail && (
  966. <ListTable
  967. position={`Chapter${exerciseChapter.value}`}
  968. title={exerciseChapter.title}
  969. data={paperList}
  970. columns={this.sentenceColums}
  971. />
  972. )}
  973. </div>
  974. );
  975. }
  976. renderInputCode() {
  977. const { sentenceError, sentenceInfo = {} } = this.state;
  978. return (
  979. <Module className="code-module">
  980. <div className="title">输入《千行GMAT长难句》专属 Code,解锁在线练习功能。</div>
  981. <div className="input-block">
  982. <Input
  983. size="lager"
  984. placeholder="请输入CODE"
  985. onChange={value => {
  986. this.code = value;
  987. }}
  988. />
  989. <Button
  990. size="lager"
  991. onClick={() => {
  992. this.activeSentence();
  993. }}
  994. >
  995. 解锁
  996. </Button>
  997. {sentenceError && <div className="error">{sentenceError}</div>}
  998. </div>
  999. <div className="tip">
  1000. {/* <Link to="/" className="left link">
  1001. 什么是CODE?
  1002. </Link> */}
  1003. <span>没有 CODE?</span>
  1004. <a href={sentenceInfo.link} target="_blank" className="theme">
  1005. 去获取 >
  1006. </a>
  1007. <span> 或 </span>
  1008. <a
  1009. onClick={() => {
  1010. this.trailSentence();
  1011. }}
  1012. className="theme"
  1013. >
  1014. 试用 >
  1015. </a>
  1016. </div>
  1017. </Module>
  1018. );
  1019. }
  1020. renderInputCodeModel() {
  1021. const { sentenceError } = this.state;
  1022. return (
  1023. <Modal visible closable={false} footer={false} title={false}>
  1024. <div className="code-module-modal">
  1025. <div className="title">请输入CODE</div>
  1026. <div className="desc">
  1027. <Input
  1028. onChange={value => {
  1029. this.code = value;
  1030. }}
  1031. />
  1032. {sentenceError && <div className="error">{sentenceError}</div>}
  1033. <div className="tip">
  1034. <Link to="/" className="right link">
  1035. 什么是CODE?
  1036. </Link>
  1037. </div>
  1038. </div>
  1039. <div className="btn-list">
  1040. <AnswerButton size="lager" theme="confirm" width={150} onClick={() => this.activeSentence()}>
  1041. 确认
  1042. </AnswerButton>
  1043. <AnswerButton
  1044. size="lager"
  1045. theme="cancel"
  1046. width={150}
  1047. onClick={() => this.setState({ sentenceModel: false })}
  1048. >
  1049. 取消
  1050. </AnswerButton>
  1051. </div>
  1052. </div>
  1053. </Modal>
  1054. );
  1055. }
  1056. renderExercise() {
  1057. const { exerciseProgress = [] } = this.state;
  1058. return (
  1059. <div>
  1060. <Division col={2}>
  1061. {(exerciseProgress || []).map(struct => {
  1062. const [first] = struct.children;
  1063. let col = 3;
  1064. if (first && first.type === 'paper') {
  1065. col = 5;
  1066. }
  1067. return (
  1068. <Panel
  1069. title={struct.titleEn}
  1070. message={struct.description}
  1071. data={struct}
  1072. col={col}
  1073. onClick={item => {
  1074. User.needLogin()
  1075. .then(() => {
  1076. if (item.type === 'paper') {
  1077. if (item.progress === 0) {
  1078. Question.startLink('exercise', item);
  1079. } else if (item.progress === 100) {
  1080. Question.startLink('exercise', item);
  1081. } else {
  1082. Question.continueLink('exercise', item);
  1083. }
  1084. } else {
  1085. this.exerciseList(item);
  1086. }
  1087. });
  1088. }}
  1089. />
  1090. );
  1091. })}
  1092. </Division>
  1093. </div>
  1094. );
  1095. }
  1096. }