page.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. import React from 'react';
  2. import './index.less';
  3. import { Icon, Checkbox } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { timeRange, formatDate, getMap, formatSeconds, formatPercent } from '@src/services/Tools';
  7. import UserLayout from '../../../layouts/User';
  8. import UserTable from '../../../components/UserTable';
  9. import UserAction from '../../../components/UserAction';
  10. import { RealAuth, QuestionNoteModal } from '../../../components/OtherModal';
  11. import Examination from '../../../components/Examination';
  12. import VipRenew from '../../../components/VipRenew';
  13. import menu, { refreshQuestionType, refreshStruct } from '../index';
  14. import Tabs from '../../../components/Tabs';
  15. import Modal from '../../../components/Modal';
  16. import Select from '../../../components/Select';
  17. import GIcon from '../../../components/Icon';
  18. import { TimeRange, QuestionType } from '../../../../Constant';
  19. import { My } from '../../../stores/my';
  20. import { Question } from '../../../stores/question';
  21. import { User } from '../../../stores/user';
  22. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  23. const exportType = [
  24. { key: 'question', title: '题目' },
  25. { key: 'official', title: '官方解析' },
  26. { key: 'note', title: '我的笔记' },
  27. { key: 'qx', title: '千行解析', auth: true },
  28. { key: 'association', title: '题源联想', auth: true },
  29. { key: 'qa', title: '相关问答', auth: true },
  30. ];
  31. export default class extends Page {
  32. constructor(props) {
  33. props.size = 10;
  34. super(props);
  35. }
  36. initState() {
  37. return {
  38. tab: 'exercise',
  39. timerange: 'today',
  40. filterMap: {},
  41. sortMap: {},
  42. data: [{}, {}],
  43. selectList: [],
  44. allChecked: false,
  45. };
  46. }
  47. init() {
  48. this.columns = [
  49. {
  50. key: 'question_type',
  51. title: '题型',
  52. render: (text, record) => {
  53. return QuestionTypeMap[record.questionType];
  54. },
  55. fixSort: true,
  56. },
  57. {
  58. key: 'title',
  59. title: '题目ID',
  60. fixSort: true,
  61. },
  62. {
  63. key: 'description',
  64. title: '内容',
  65. },
  66. {
  67. key: 'time',
  68. title: '耗时',
  69. sort: true,
  70. render: (text, record) => {
  71. const user = record.stat.userTime / record.stat.userNumber;
  72. const all = record.questionNo.totalTime / record.questionNo.totalNumber;
  73. return <div className="sub">
  74. <div className="t-2 t-s-12">{formatSeconds(user)}<Assets height={10} width={10} name={user > all ? 'up' : 'down'} /></div>
  75. <div className="t-6 t-s-12">全站{formatSeconds(all)}</div>
  76. </div>;
  77. },
  78. },
  79. {
  80. key: 'correct',
  81. title: '错误率',
  82. sort: true,
  83. render: (text, record) => {
  84. return <div className="sub">
  85. <div className="t-2 t-s-12">{formatPercent(record.stat.userNumber - record.stat.userCorrect, record.stat.userNumber, false)}</div>
  86. <div className="t-6 t-s-12">{record.stat.userNumber - record.stat.userCorrect}/{record.stat.userNumber}</div>
  87. </div>;
  88. },
  89. },
  90. {
  91. key: 'latest_time',
  92. title: '最近做题',
  93. render: (text) => {
  94. return <div className="sub">
  95. <div className="t-2 t-s-12">{text.split(' ')[0]}</div>
  96. <div className="t-6 t-s-12">{text.split(' ')[1]}</div>
  97. </div>;
  98. },
  99. },
  100. {
  101. key: '',
  102. title: '',
  103. render: (text, record, index) => {
  104. return <div><GIcon name="star" active={record.collect} className="m-r-5" onClick={() => this.toggleCollect(index)} /><GIcon name="note" active={record.note} onClick={() => this.note(index)} /></div>;
  105. },
  106. },
  107. ];
  108. }
  109. initData() {
  110. const data = Object.assign(this.state, this.state.search);
  111. data.filterMap = this.state.search;
  112. if (data.order) {
  113. data.sortMap = { [data.order]: data.direction };
  114. }
  115. if (data.timerange) {
  116. data.filterMap.timerange = data.timerange;
  117. }
  118. const { info = {} } = this.props.user;
  119. if (info.latestExercise) {
  120. // 获取最后一次错题记录
  121. Question.baseReport(info.latestError).then(result => {
  122. this.setState({ latest: result });
  123. });
  124. }
  125. const [startTime, endTime] = timeRange(data.timerange);
  126. refreshQuestionType(this, data.subject, data.questionType, {
  127. all: true,
  128. needSentence: true,
  129. allSubject: true,
  130. }).then(({ questionTypes }) => {
  131. return refreshStruct(this, data.tab, data.one, data.two, {
  132. all: true,
  133. needPreview: false,
  134. needTextbook: true,
  135. }).then(({ structIds, latest, year }) => {
  136. My.listError(
  137. Object.assign(
  138. { module: data.tab, questionTypes, structIds, latest, year, startTime, endTime },
  139. this.state.search,
  140. {
  141. order: Object.keys(data.sortMap)
  142. .map(key => {
  143. if (key === 'title') return 'pid desc, no desc';
  144. return `${key} ${data.sortMap[key]}`;
  145. })
  146. .join(','),
  147. },
  148. ),
  149. ).then(result => {
  150. result.list = result.list.map(row => {
  151. row.key = row.questionNoId;
  152. return row;
  153. });
  154. this.setState({ list: result.list, total: result.total });
  155. });
  156. });
  157. });
  158. }
  159. toggleCollect(index) {
  160. const { list } = this.props;
  161. const userQuestion = list[index];
  162. if (!userQuestion.collect) {
  163. My.addQuestionCollect(userQuestion.questionNo.id).then(() => {
  164. userQuestion.collect = true;
  165. this.setState({ list });
  166. });
  167. } else {
  168. My.delQuestionCollect(userQuestion.questionNo.id).then(() => {
  169. userQuestion.collect = false;
  170. this.setState({ list });
  171. });
  172. }
  173. }
  174. note(index) {
  175. const { list } = this.props;
  176. const userQuestion = list[index];
  177. const { questionNo } = userQuestion;
  178. My.getQuestionNote(questionNo.id)
  179. .then(result => {
  180. this.setState({ questionNo, note: result || {}, showNote: true, index });
  181. });
  182. }
  183. onTabChange(tab) {
  184. const data = { tab };
  185. this.refreshQuery(data);
  186. }
  187. onFilter(value) {
  188. this.search(value, false);
  189. this.initData();
  190. }
  191. onSearch(value) {
  192. this.search({ keyword: value }, false);
  193. this.initData();
  194. }
  195. onSort(value) {
  196. const keys = Object.keys(value);
  197. // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
  198. const { sortMap } = this.state;
  199. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  200. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false);
  201. this.initData();
  202. }
  203. onChangePage(page) {
  204. this.search({ page }, false);
  205. this.initData();
  206. }
  207. onAll(checked) {
  208. const { selectList } = this.state;
  209. const { list = [] } = this.state;
  210. if (checked) {
  211. list.forEach(item => {
  212. if (selectList.indexOf(item.key) >= 0) return;
  213. selectList.push(item.key);
  214. });
  215. } else {
  216. list.forEach(item => {
  217. const index = selectList.indexOf(item.key);
  218. if (index < 0) return;
  219. selectList.splice(index, 1);
  220. });
  221. }
  222. this.setState({ selectList, allChecked: checked });
  223. }
  224. onSelect(selectList) {
  225. this.setState({ selectList, allCheckbox: false });
  226. }
  227. onAction(key) {
  228. const { info } = this.props.user;
  229. const { selectList } = this.state;
  230. switch (key) {
  231. case 'help':
  232. this.setState({ showTips: true });
  233. return;
  234. case 'clear':
  235. if (selectList.length === 0) {
  236. this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1题,请重新选择' } });
  237. return;
  238. }
  239. this.setState({ showClearConfirm: true, clearInfo: { questionNoIds: selectList } });
  240. break;
  241. case 'group':
  242. if (!info.vip) {
  243. this.setState({ showVip: true });
  244. return;
  245. }
  246. if (selectList.length < 10) {
  247. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可小于10题,请重新选择' } });
  248. return;
  249. }
  250. if (selectList.length > 50) {
  251. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可多余50题,请重新选择' } });
  252. return;
  253. }
  254. if (selectList.length === 0) {
  255. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可同时选中语文题和数学题,请重新选择。' } });
  256. return;
  257. }
  258. this.setState({ showGroupConfirm: true, groupInfo: { questionNoIds: selectList, filterTimes: 2 } });
  259. break;
  260. case 'export':
  261. if (!info.vip) {
  262. this.setState({ showVip: true });
  263. return;
  264. }
  265. if (selectList.length < 1) {
  266. this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于1题,请重新选择' } });
  267. return;
  268. }
  269. if (selectList.length > 100) {
  270. this.setState({ showWarn: true, warn: { title: '导出', content: '不可多余100题,请重新选择' } });
  271. return;
  272. }
  273. if (info.bindReal) {
  274. this.setState({ showExportConfirm: true, exportInfo: { include: exportType.map(row => row.key), questionNoIds: selectList, answer: true } });
  275. } else {
  276. this.setState({ showExportAuthConfirm: true, exportInfo: { include: exportType.filter(row => !row.auth).map(row => row.key), questionNoIds: selectList, answer: true } });
  277. }
  278. break;
  279. default:
  280. }
  281. }
  282. clearErrorQuestion() {
  283. const { clearInfo } = this.state;
  284. My.clearError(clearInfo.questionNoIds)
  285. .then(() => {
  286. this.refresh();
  287. })
  288. .catch(e => {
  289. this.setState({ showWarn: true, warn: { title: '移除', content: e.message }, showClearConfirm: false });
  290. });
  291. }
  292. group() {
  293. const { groupInfo } = this.state;
  294. My.groupQuestionCollect(groupInfo)
  295. .then((result) => {
  296. Question.startLink('error', result);
  297. this.setState({ showGroupConfirm: false });
  298. })
  299. .catch(e => {
  300. this.setState({ showWarn: true, warn: { title: '组卷练习', content: e.message }, showGroupConfirm: false });
  301. });
  302. }
  303. export() {
  304. const { exportInfo } = this.state;
  305. this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
  306. My.exportQuestionError(exportInfo)
  307. .then((result) => {
  308. openLink(`/export/${result}`);
  309. this.setState({ showExportWait: false });
  310. })
  311. .catch(e => {
  312. this.setState({ showWarn: true, warn: { title: '导出', content: e.message }, showExportWait: false });
  313. });
  314. }
  315. remove(report) {
  316. My.removeError(report.id)
  317. .then(() => {
  318. this.refresh();
  319. });
  320. }
  321. clearErrorReport() {
  322. My.clearLatestError()
  323. .then(() => {
  324. const { info } = this.props.user;
  325. info.latestError = 0;
  326. User.infoHandle(info);
  327. });
  328. this.setState({ latest: null });
  329. }
  330. renderView() {
  331. const { config } = this.props;
  332. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  333. }
  334. renderTable() {
  335. const {
  336. tab,
  337. questionSubjectSelect,
  338. questionSubjectMap = {},
  339. oneSelect,
  340. twoSelectMap = {},
  341. filterMap = {},
  342. sortMap = {},
  343. list = [],
  344. latest,
  345. } = this.state;
  346. const { selectList = [], allChecked, page, total } = this.state;
  347. const { info } = this.props.user;
  348. return (
  349. <div className="table-layout">
  350. <Tabs
  351. border
  352. type="division"
  353. theme="theme"
  354. size="small"
  355. space={2.5}
  356. width={100}
  357. active={tab}
  358. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  359. onChange={key => this.onTabChange(key)}
  360. />
  361. <UserAction
  362. search
  363. defaultSearch={filterMap.keyword}
  364. selectList={[
  365. {
  366. children: [
  367. {
  368. key: 'subject',
  369. placeholder: '学科',
  370. select: questionSubjectSelect,
  371. },
  372. {
  373. placeholder: '题型',
  374. key: 'questionType',
  375. be: 'subject',
  376. selectMap: questionSubjectMap,
  377. },
  378. ],
  379. },
  380. {
  381. label: '范围',
  382. children: [
  383. {
  384. key: 'one',
  385. placeholder: '全部',
  386. select: oneSelect,
  387. },
  388. {
  389. key: 'two',
  390. be: 'one',
  391. placeholder: '全部',
  392. selectMap: twoSelectMap,
  393. },
  394. ],
  395. },
  396. {
  397. right: true,
  398. key: 'timerange',
  399. select: TimeRange,
  400. },
  401. ]}
  402. filterMap={filterMap}
  403. onFilter={value => this.onFilter(value)}
  404. onSearch={value => this.onSearch(value)}
  405. />
  406. <UserAction
  407. allCheckbox
  408. allChecked={allChecked}
  409. help
  410. btnList={[
  411. { title: '移除', key: 'clear' },
  412. { title: '组卷', key: 'group', tag: 'vip', disabled: !info.vip },
  413. { title: '导出', key: 'export', tag: 'vip', disabled: !info.vip },
  414. ]}
  415. right={
  416. latest && <div className="tip">
  417. {formatDate(latest.updateTime, 'YYYY-MM-DD HH:mm')} 组卷{latest.questionNumber}题,做对{latest.userCorrect}题。<span onClick={() => {
  418. this.remove(latest);
  419. }}>移除正确题目</span>
  420. <Icon type="close-circle" theme="filled" onClick={() => {
  421. this.clearErrorReport();
  422. }} />
  423. </div>
  424. }
  425. onAll={checked => this.onAll(checked)}
  426. onAction={key => this.onAction(key)}
  427. />
  428. <UserTable
  429. select
  430. columns={this.columns}
  431. sortMap={sortMap}
  432. data={list}
  433. current={page}
  434. total={total}
  435. pageSize={this.state.search.size}
  436. selectList={selectList}
  437. onSelect={l => this.onSelect(l)}
  438. onSort={v => this.onSort(v)}
  439. onChange={p => this.onChangePage(p)}
  440. />
  441. {this.renderModal()}
  442. </div>
  443. );
  444. }
  445. renderModal() {
  446. const { showTips, showWarn, warn = {}, showClearConfirm, clearInfo = {}, showGroupConfirm, groupInfo = {}, showExportConfirm, showExportAuthConfirm, exportInfo = {}, showExportWait, showExamination, showVip, showReal, showNote, note = {}, questionNo = {}, list } = this.state;
  447. const { info } = this.props.user;
  448. return [
  449. <Modal show={showTips} title="操作提示" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showTips: false })}>
  450. <div className="flex-layout m-b-2">
  451. <div className="flex-block">
  452. <div className="t-1 t-s-18">组卷功能</div>
  453. <div className="t-2">操作数量:10-50;</div>
  454. <div className="t-2">注意事项:可跨题型、不可跨学科。</div>
  455. </div>
  456. <div className="flex-block">
  457. <div className="t-1 t-s-18">导出功能</div>
  458. <div className="t-2">操作数量:1-100;</div>
  459. <div className="t-2">注意事项:“综合推理IR”暂时无法导出。</div>
  460. </div>
  461. </div>
  462. <div className="t-3">
  463. *您可点击
  464. <Icon type="question-circle" theme="filled" />
  465. 查阅以上信息。
  466. </div>
  467. </Modal>,
  468. <Modal show={showWarn} title={warn.title} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showWarn: false })}>
  469. <div className="t-2 t-s-18">{warn.content}</div>
  470. </Modal>,
  471. <Modal show={showGroupConfirm} title="组卷练习" confirmText="开始练习" onConfirm={() => this.group()} onCancel={() => this.setState({ showGroupConfirm: false })}>
  472. <div className="t-2 t-s-18">
  473. 您共选择了 <span className="t-4">{groupInfo.questionNoIds ? groupInfo.questionNoIds.length : 0}</span> 道题目,是否开始练习?</div>
  474. <div className="t-2 t-s-16">
  475. <Checkbox checked className="m-r-5" />
  476. 剔除已组卷练习 <Select
  477. theme="white"
  478. value={groupInfo.filterTimes}
  479. list={[{ key: 2, title: '2' }, { key: 3, title: '3' }]}
  480. onChange={({ key }) => {
  481. groupInfo.filterTimes = key;
  482. this.setState({ groupInfo });
  483. }}
  484. />{' '}
  485. 次以上的错题
  486. </div>
  487. </Modal>,
  488. <Modal show={showClearConfirm} title="移出" onConfirm={() => this.clearErrorQuestion()} onCancel={() => this.setState({ showClearConfirm: false })}>
  489. <div className="t-2 t-s-18">
  490. 当前选中的 <span className="t-4">{clearInfo.questionNoIds ? clearInfo.questionNoIds.length : 0}</span> 道题即将被移出错题本,移出后无法恢复,是否继续?
  491. </div>
  492. </Modal>,
  493. <Modal show={showExportWait} title="导出" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showExportWait: false })}>
  494. <div className="t-2 t-s-18">正在下载中,请不要关闭当前页面!</div>
  495. </Modal>,
  496. <Modal show={showExportConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
  497. <div className="t-2 t-s-18 m-b-5">
  498. 当前共选中 <span className="t-4">{exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0}</span> 道题,请确认需要导出的内容:
  499. </div>
  500. <div className="t-2 t-s-16">
  501. {exportType.map(item => {
  502. return (
  503. <div className="d-i-b m-b-5" style={{ width: 135 }}>
  504. <Checkbox checked={exportInfo.include ? exportInfo.include.indexOf(item.key) >= 0 : false} className="m-r-5" onChange={() => {
  505. exportInfo.include.push(item.key);
  506. this.setState({ exportInfo });
  507. }} />
  508. {item.title}
  509. </div>
  510. );
  511. })}
  512. </div>
  513. </Modal>,
  514. <Modal show={showExportAuthConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportAuthConfirm: false })}>
  515. <div className="t-2 t-s-18 m-b-5">
  516. 当前共选中 <span className="t-4">{exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0}</span> 道题,请确认需要导出的内容:
  517. </div>
  518. <div className="t-2 t-s-16 m-b-2">
  519. {exportType
  520. .filter(item => !item.auth)
  521. .map(item => {
  522. return (
  523. <div className="d-i-b m-b-2" style={{ width: 135 }}>
  524. <Checkbox checked={exportInfo.include ? exportInfo.include.indexOf(item.key) >= 0 : false} className="m-r-5" onChange={() => {
  525. exportInfo.include.push(item.key);
  526. this.setState({ exportInfo });
  527. }} />
  528. {item.title}
  529. </div>
  530. );
  531. })}
  532. </div>
  533. <div className="b-b m-b-2 m-t-2" />
  534. <div className="t-3 m-b-1">
  535. 以下内容需实名认证后才可导出: <a className="f-r" onClick={() => this.setState({ showExportAuthConfirm: false, showReal: true })}>去认证 ></a>
  536. </div>
  537. <div className="t-2 t-s-16 m-b-2">
  538. {exportType
  539. .filter(item => item.auth)
  540. .map(item => {
  541. return (
  542. <div className="d-i-b" style={{ width: 135 }}>
  543. <Checkbox disabled className="m-r-5" />
  544. {item.title}
  545. </div>
  546. );
  547. })}
  548. </div>
  549. </Modal>,
  550. <Examination
  551. show={showExamination}
  552. data={info}
  553. onConfirm={() => this.setState({ showExamination: false })}
  554. onCancel={() => this.setState({ showExamination: false })}
  555. onClose={() => this.setState({ showExamination: false })}
  556. />,
  557. <RealAuth show={showReal} data={info} onConfirm={() => this.setState({ showReal: false })} />,
  558. <VipRenew
  559. show={showVip}
  560. data={info}
  561. onReal={() => this.setState({ showVip: false, showReal: true })}
  562. onPrepare={() => this.setState({ showVip: false, showExamination: true })}
  563. onClose={(result) => {
  564. if (result) {
  565. this.refresh();
  566. } else {
  567. this.setState({ showVip: false });
  568. }
  569. }}
  570. />,
  571. <QuestionNoteModal show={showNote} defaultData={note} questionNo={questionNo} onConfirm={() => {
  572. list[this.state.index].note = true;
  573. this.setState({ showNote: false, list });
  574. }} onCancel={() => this.setState({ showNote: false })} />,
  575. ];
  576. }
  577. }