page.js 22 KB

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