page.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 = [];
  182. if (checked) {
  183. const { list = [] } = this.state;
  184. list.forEach(item => {
  185. if (selectList.indexOf(item.key) >= 0) return;
  186. selectList.push(item.key);
  187. });
  188. }
  189. this.setState({ selectList, allChecked: checked });
  190. }
  191. onSelect(selectList) {
  192. this.setState({ selectList });
  193. }
  194. onAction(key) {
  195. const { info } = this.props.user;
  196. const { selectList } = this.state;
  197. switch (key) {
  198. case 'help':
  199. this.setState({ showTips: true });
  200. return;
  201. case 'clear':
  202. if (selectList.length === 0) {
  203. this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1题,请重新选择' } });
  204. return;
  205. }
  206. this.setState({ showClearCollectConfirm: true, clearInfo: { questionNoIds: selectList } });
  207. break;
  208. case 'group':
  209. if (!info.vip) {
  210. this.setState({ showVip: true });
  211. return;
  212. }
  213. if (selectList.length < 0) {
  214. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可小于10题,请重新选择' } });
  215. return;
  216. }
  217. if (selectList.length > 50) {
  218. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可多余50题,请重新选择' } });
  219. return;
  220. }
  221. if (selectList.length === 0) {
  222. this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可同时选中语文题和数学题,请重新选择。' } });
  223. return;
  224. }
  225. this.setState({ showGroupConfirm: true, groupInfo: { questionNoIds: selectList } });
  226. break;
  227. case 'export':
  228. if (!info.vip) {
  229. this.setState({ showVip: true });
  230. return;
  231. }
  232. if (selectList.length < 0) {
  233. this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于10题,请重新选择' } });
  234. return;
  235. }
  236. if (selectList.length > 100) {
  237. this.setState({ showWarn: true, warn: { title: '导出', content: '不可多余100题,请重新选择' } });
  238. return;
  239. }
  240. if (info.bindReal) {
  241. this.setState({ showExportConfirm: true, exportInfo: { info: exportType.map(row => row.key), questionNoIds: selectList } });
  242. } else {
  243. this.setState({ showExportAuthConfirm: true, exportInfo: { info: exportType.filter(row => !row.auth).map(row => row.key), questionNoIds: selectList } });
  244. }
  245. break;
  246. default:
  247. }
  248. }
  249. clearErrorQuestion() {
  250. const { clearInfo } = this.state;
  251. My.clearError(clearInfo.questionNoIds)
  252. .then(() => {
  253. this.refresh();
  254. })
  255. .catch(e => {
  256. this.setState({ warn: { title: '移除', content: e.message }, showClearCollectConfirm: false });
  257. });
  258. }
  259. group() {
  260. const { groupInfo } = this.state;
  261. My.groupQuestionCollect(groupInfo)
  262. .then((result) => {
  263. Question.startLink('error', result);
  264. this.setState({ showGroupConfirm: false });
  265. })
  266. .catch(e => {
  267. this.setState({ warn: { title: '组卷练习', content: e.message }, showGroupConfirm: false });
  268. });
  269. }
  270. export() {
  271. const { exportInfo } = this.state;
  272. this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
  273. My.exportQuestion(exportInfo)
  274. .then((result) => {
  275. openLink(`/export/${result.id}`);
  276. this.setState({ showExportWait: false });
  277. })
  278. .catch(e => {
  279. this.setState({ warn: { title: '导出', content: e.message }, showExportWait: false });
  280. });
  281. }
  282. remove(report) {
  283. My.removeError(report.id)
  284. .then(() => {
  285. this.refresh();
  286. });
  287. }
  288. clearErrorReport() {
  289. My.clearLatestError()
  290. .then(() => {
  291. this.setState({ latest: null });
  292. });
  293. }
  294. renderView() {
  295. const { config } = this.props;
  296. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  297. }
  298. renderTable() {
  299. const {
  300. tab,
  301. questionSubjectSelect,
  302. questionSubjectMap = {},
  303. oneSelect,
  304. twoSelectMap = {},
  305. filterMap = {},
  306. sortMap = {},
  307. list = [],
  308. latest,
  309. } = this.state;
  310. const { selectList = [], allChecked, page, total } = this.state;
  311. const { info } = this.props.user;
  312. return (
  313. <div className="table-layout">
  314. <Tabs
  315. border
  316. type="division"
  317. theme="theme"
  318. size="small"
  319. space={2.5}
  320. width={100}
  321. active={tab}
  322. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  323. onChange={key => this.onTabChange(key)}
  324. />
  325. <UserAction
  326. search
  327. defaultSearch={filterMap.keyword}
  328. selectList={[
  329. {
  330. children: [
  331. {
  332. key: 'subject',
  333. placeholder: '学科',
  334. select: questionSubjectSelect,
  335. },
  336. {
  337. placeholder: '题型',
  338. key: 'questionType',
  339. be: 'subject',
  340. selectMap: questionSubjectMap,
  341. },
  342. ],
  343. },
  344. {
  345. label: '范围',
  346. children: [
  347. {
  348. key: 'one',
  349. placeholder: '全部',
  350. select: oneSelect,
  351. },
  352. {
  353. key: 'two',
  354. be: 'one',
  355. placeholder: '全部',
  356. selectMap: twoSelectMap,
  357. },
  358. ],
  359. },
  360. {
  361. right: true,
  362. key: 'timerange',
  363. select: TimeRange,
  364. },
  365. ]}
  366. filterMap={filterMap}
  367. onFilter={value => this.onFilter(value)}
  368. onSearch={value => this.onSearch(value)}
  369. />
  370. <UserAction
  371. allCheckbox
  372. allChecked={allChecked}
  373. help
  374. btnList={[
  375. { title: '移除', key: 'clear' },
  376. { title: '组卷', key: 'group', tag: 'vip', disabled: !info.vip },
  377. { title: '导出', key: 'export', tag: 'vip', disabled: !info.vip },
  378. ]}
  379. right={
  380. latest && <div className="tip">
  381. {formatDate(latest.updateTime, 'YYYY-MM-DD HH:mm')} 组卷{latest.questionNumber}题,做对{latest.userCorrect}题。<span onClick={() => {
  382. this.remove(latest);
  383. }}>移除正确题目</span>
  384. <Icon type="close-circle" theme="filled" onClick={() => {
  385. this.clearErrorReport();
  386. }} />
  387. </div>
  388. }
  389. onAll={checked => this.onAll(checked)}
  390. onAction={key => this.onAction(key)}
  391. />
  392. <UserTable
  393. select
  394. columns={columns}
  395. sortMap={sortMap}
  396. data={list}
  397. current={page}
  398. total={total}
  399. pageSize={this.state.search.size}
  400. selectList={selectList}
  401. onSelect={l => this.onSelect(l)}
  402. onSort={v => this.onSort(v)}
  403. onChange={p => this.onChangePage(p)}
  404. />
  405. {this.renderModal()}
  406. </div>
  407. );
  408. }
  409. renderModal() {
  410. const { showTips, showWarn, warn = {}, showClearCollectConfirm, clearInfo = {}, showGroupConfirm, groupInfo = {}, showExportConfirm, showExportAuthConfirm, exportInfo = {}, showExportWait, showExamination, showVip, showReal } = this.state;
  411. const { info } = this.props.user;
  412. return [
  413. <Modal show={showTips} title="操作提示" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showTips: false })}>
  414. <div className="flex-layout m-b-2">
  415. <div className="flex-block">
  416. <div className="t-1 t-s-18">组卷功能</div>
  417. <div className="t-2">操作数量:10-50;</div>
  418. <div className="t-2">注意事项:可跨题型、不可跨学科。</div>
  419. </div>
  420. <div className="flex-block">
  421. <div className="t-1 t-s-18">导出功能</div>
  422. <div className="t-2">操作数量:1-100;</div>
  423. <div className="t-2">注意事项:“综合推理IR”暂时无法导出。</div>
  424. </div>
  425. </div>
  426. <div className="t-3">
  427. *您可点击
  428. <Icon type="question-circle" theme="filled" />
  429. 查阅以上信息。
  430. </div>
  431. </Modal>,
  432. <Modal show={showWarn} title={warn.title} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showWarn: false })}>
  433. <div className="t-2 t-s-18">{warn.content}</div>
  434. </Modal>,
  435. <Modal show={showGroupConfirm} title="组卷练习" confirmText="开始练习" onConfirm={() => this.group()} onCancel={() => this.setState({ showGroupConfirm: false })}>
  436. <div className="t-2 t-s-18">
  437. 您共选择了 <span className="t-4">{groupInfo.questionNoIds ? groupInfo.questionNoIds.length : 0}</span> 道题目,是否开始练习?</div>
  438. <div className="t-2 t-s-16">
  439. <Checkbox checked className="m-r-5" />
  440. 剔除已组卷练习 <Select
  441. theme="white"
  442. value={groupInfo.filterTimes}
  443. list={[{ key: 2, title: '2' }, { key: 3, title: '3' }]}
  444. onChange={(key) => {
  445. groupInfo.filterTimes = key;
  446. this.setState({ groupInfo });
  447. }}
  448. />{' '}
  449. 次以上的错题
  450. </div>
  451. </Modal>,
  452. <Modal show={showClearCollectConfirm} title="移出" onConfirm={() => this.clearErrorQuestion()} onCancel={() => this.setState({ showClearCollectConfirm: false })}>
  453. <div className="t-2 t-s-18">
  454. 当前选中的 <span className="t-4">{clearInfo.questionNoIds ? clearInfo.questionNoIds.length : 0}</span> 道题即将被移出错题本,移出后无法恢复,是否继续?
  455. </div>
  456. </Modal>,
  457. <Modal show={showExportWait} title="导出" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showExportWait: false })}>
  458. <div className="t-2 t-s-18">正在下载中,请不要关闭当前页面!</div>
  459. </Modal>,
  460. <Modal show={showExportConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
  461. <div className="t-2 t-s-18 m-b-5">
  462. 当前共选中 <span className="t-4">{exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0}</span> 道题,请确认需要导出的内容:
  463. </div>
  464. <div className="t-2 t-s-16">
  465. {exportType.map(item => {
  466. return (
  467. <div className="d-i-b m-b-5" style={{ width: 135 }}>
  468. <Checkbox checked={exportInfo.info ? exportInfo.info.indexOf(item.key) >= 0 : false} className="m-r-5" onChange={() => {
  469. exportInfo.info.push(item.key);
  470. this.setState({ exportInfo });
  471. }} />
  472. {item.title}
  473. </div>
  474. );
  475. })}
  476. </div>
  477. </Modal>,
  478. <Modal show={showExportAuthConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportAuthConfirm: false })}>
  479. <div className="t-2 t-s-18 m-b-5">
  480. 当前共选中 <span className="t-4">{exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0}</span> 道题,请确认需要导出的内容:
  481. </div>
  482. <div className="t-2 t-s-16 m-b-2">
  483. {exportType
  484. .filter(item => !item.auth)
  485. .map(item => {
  486. return (
  487. <div className="d-i-b m-b-2" style={{ width: 135 }}>
  488. <Checkbox checked={exportInfo.info ? exportInfo.info.indexOf(item.key) >= 0 : false} className="m-r-5" onChange={() => {
  489. exportInfo.info.push(item.key);
  490. this.setState({ exportInfo });
  491. }} />
  492. {item.title}
  493. </div>
  494. );
  495. })}
  496. </div>
  497. <div className="b-b m-b-2 m-t-2" />
  498. <div className="t-3 m-b-1">
  499. 以下内容需实名认证后才可导出: <a className="f-r" onClick={() => this.setState({ showExportAuthConfirm: false, showReal: true })}>去认证 ></a>
  500. </div>
  501. <div className="t-2 t-s-16 m-b-2">
  502. {exportType
  503. .filter(item => item.auth)
  504. .map(item => {
  505. return (
  506. <div className="d-i-b" style={{ width: 135 }}>
  507. <Checkbox disabled className="m-r-5" />
  508. {item.title}
  509. </div>
  510. );
  511. })}
  512. </div>
  513. </Modal>,
  514. <Examination
  515. show={showExamination}
  516. data={info}
  517. onConfirm={() => this.setState({ showExamination: false })}
  518. onCancel={() => this.setState({ showExamination: false })}
  519. onClose={() => this.setState({ showExamination: false })}
  520. />,
  521. <RealAuth show={showReal} data={info} onConfirm={() => this.setState({ showReal: false })} />,
  522. <VipRenew
  523. show={showVip}
  524. data={info}
  525. onReal={() => this.setState({ showVip: false, showReal: true })}
  526. onPrepare={() => this.setState({ showVip: false, showExamination: true })}
  527. onClose={() => this.setState({ showVip: false })}
  528. />,
  529. ];
  530. }
  531. }