page.js 18 KB

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