page.js 19 KB

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