page.js 18 KB

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