page.js 19 KB

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