page.js 19 KB

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