page.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import React, { Component } from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import { Icon } from 'antd';
  5. import Page from '@src/containers/Page';
  6. import { formatDate, getMap } from '@src/services/Tools';
  7. import Modal from '../../../components/Modal';
  8. import UserAction from '../../../components/UserAction';
  9. import UserPagination from '../../../components/UserPagination';
  10. import { RealAuth } from '../../../components/OtherModal';
  11. import Examination from '../../../components/Examination';
  12. import VipRenew from '../../../components/VipRenew';
  13. import CheckboxItem from '../../../components/CheckboxItem';
  14. import { Course } from '../../../stores/course';
  15. import { My } from '../../../stores/my';
  16. export default class extends Page {
  17. initState() {
  18. return {
  19. filterMap: {},
  20. sortMap: {},
  21. // list: [
  22. // {
  23. // title: '比较对象对等问题',
  24. // content:
  25. // '从比较对象和句子结构我们能把DE排除掉,D选项中dffat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livest。ock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较?对象和句子结构我们能把?DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结。构我们能把DE排除掉,D选项中fat和livestock不是比较对象.',
  26. // },
  27. // {
  28. // title: '比较对象对等问题',
  29. // content:
  30. // '从比较对象和句子结构我们能把DE排除掉,D选项中dffat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livest。ock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较?对象和句子结构我们能把?DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结。构我们能把DE排除掉,D选项中fat和livestock不是比较对象.',
  31. // },
  32. // {
  33. // title: '比较对象对等问题',
  34. // content:
  35. // '从比较对象和句子结构我们能把DE排除掉,D选项中dffat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livest。ock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结构我们能把DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较?对象和句子结构我们能把?DE排除掉,D选项中fat和livestock不是比较对象,E选项中and 后面的句子太凌乱is of a kind ….is…结构出现了重大问题?从比较对象和句子结。构我们能把DE排除掉,D选项中fat和livestock不是比较对象.',
  36. // },
  37. // ],
  38. selectList: [],
  39. allChecked: false,
  40. showDetail: false,
  41. defaultSortMap: {
  42. },
  43. };
  44. }
  45. init() {
  46. const { id } = this.params;
  47. Course.get(id)
  48. .then(result => {
  49. const courseNoMap = getMap(result.courseNos, 'id');
  50. this.setState({ course: result, courseNoMap });
  51. });
  52. }
  53. initData() {
  54. const { id } = this.params;
  55. const data = Object.assign(this.state, this.state.search);
  56. data.filterMap = this.state.search;
  57. if (data.order) {
  58. data.sortMap = { [data.order]: data.direction };
  59. } else if (data.direction == null || data.direction === '') {
  60. data.sortMap = Object.assign({}, this.state.defaultSortMap);
  61. }
  62. this.setState(data);
  63. My.listCourseNote(Object.assign({ courseId: id }, this.state.search, {
  64. order: Object.keys(data.sortMap)
  65. .map(key => {
  66. return `${key} ${data.sortMap[key]}`;
  67. })
  68. .join(','),
  69. }))
  70. .then(result => {
  71. result.list = result.list.map(row => {
  72. row.key = row.courseNoId;
  73. return row;
  74. });
  75. this.setState({ list: result.list, total: result.total });
  76. });
  77. }
  78. onFilter(value) {
  79. this.search(value, false);
  80. this.initData();
  81. }
  82. onSearch(value) {
  83. this.search({ page: 1, keyword: value }, false);
  84. this.initData();
  85. }
  86. onSort(value) {
  87. const keys = Object.keys(value);
  88. const { sortMap, defaultSortMap } = this.state;
  89. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  90. let order = keys.length && value[keys[index]] ? keys[index] : null;
  91. let direction = keys.length ? value[keys[index]] : null;
  92. if (order == null) {
  93. const [prevOrder] = Object.keys(sortMap);
  94. if (!defaultSortMap[prevOrder]) {
  95. const k = Object.keys(defaultSortMap);
  96. if (k.length > 0) {
  97. [order] = Object.keys(defaultSortMap);
  98. direction = defaultSortMap[order];
  99. }
  100. }
  101. }
  102. this.search({ order, direction }, false);
  103. this.initData();
  104. }
  105. onChangePage(page) {
  106. this.search({ page }, false);
  107. this.initData();
  108. }
  109. onAll(checked) {
  110. const { selectList } = this.state;
  111. const { list = [] } = this.state;
  112. if (checked) {
  113. list.forEach(item => {
  114. if (selectList.indexOf(item.key) >= 0) return;
  115. selectList.push(item.key);
  116. });
  117. } else {
  118. list.forEach(item => {
  119. const index = selectList.indexOf(item.key);
  120. if (index < 0) return;
  121. selectList.splice(index, 1);
  122. });
  123. }
  124. this.setState({ selectList, allChecked: checked });
  125. }
  126. onSelect(selectList) {
  127. this.setState({ selectList, allCheckbox: false });
  128. }
  129. onAction(key) {
  130. const { info } = this.props.user;
  131. const { selectList } = this.state;
  132. switch (key) {
  133. case 'help':
  134. this.setState({ showTips: true });
  135. return;
  136. case 'clear':
  137. if (selectList.length === 0) {
  138. this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1篇,请重新选择' } });
  139. return;
  140. }
  141. this.setState({ showClearConfirm: true, clearInfo: { courseNoIds: selectList } });
  142. break;
  143. case 'export':
  144. if (!info.vip) {
  145. this.setState({ showVip: true });
  146. return;
  147. }
  148. if (selectList.length < 1) {
  149. this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于1篇,请重新选择' } });
  150. return;
  151. }
  152. this.setState({ showExportConfirm: true, exportInfo: { courseNoIds: selectList } });
  153. break;
  154. default:
  155. }
  156. }
  157. clearNote() {
  158. const { exportInfo } = this.state;
  159. My.clearCourseNote(exportInfo.courseNoIds)
  160. .then(() => {
  161. this.refresh();
  162. })
  163. .then(e => {
  164. this.setState({ warn: { title: '移除', content: e.message }, showClearConfirm: false });
  165. });
  166. }
  167. export() {
  168. const { exportInfo } = this.state;
  169. this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
  170. My.exportNoteCourse(exportInfo)
  171. .then((result) => {
  172. openLink(`/export/${result}`);
  173. this.setState({ showExportWait: false });
  174. })
  175. .catch(e => {
  176. this.setState({ warn: { title: '导出', content: e.message }, showExportWait: false });
  177. });
  178. }
  179. prevArticle() {
  180. const { article, list } = this.state;
  181. let index = 0;
  182. list.forEach((row, i) => {
  183. if (article.key === row.key) index = i;
  184. });
  185. index -= 1;
  186. if (index < 0) {
  187. index = list.length + index;
  188. }
  189. this.setState({ article: list[index] });
  190. }
  191. nextArticle() {
  192. const { article, list } = this.state;
  193. let index = 0;
  194. list.forEach((row, i) => {
  195. if (article.key === row.key) index = i;
  196. });
  197. index += 1;
  198. if (index >= list.length) {
  199. index -= list.length;
  200. }
  201. this.setState({ article: list[index] });
  202. }
  203. renderView() {
  204. const { course = {}, courseNoMap = {}, list = [], selectList = [], sortMap, filterMap, allChecked, total, page } = this.state;
  205. const {
  206. user: { info },
  207. } = this.props;
  208. return (
  209. <div>
  210. <div className="top content t-8">
  211. <Link to="/course">千行课堂</Link> > <Link to="/course/online?tab=single">全部课程</Link> > <Link to={`/course/detail/${course.id}`}>{course.title}</Link> > <span className="t-1">我的笔记</span>
  212. <div className="f-r" onClick={() => linkTo(`/course/detail/${course.id}`)}>返回课程</div>
  213. </div>
  214. <div className="center content">
  215. <div className="t-1 t-s-20 m-b-2">{course.title}</div>
  216. <UserAction
  217. allCheckbox
  218. allChecked={allChecked}
  219. search
  220. defaultSearch={filterMap.keyword}
  221. btnList={[
  222. { title: '删除', key: 'delete' },
  223. { title: '导出', key: 'export', tag: 'vip', disabled: !info.vip },
  224. ]}
  225. sortList={[
  226. { right: true, label: '课时', key: 'no', fixed: true },
  227. { right: true, label: '更新时间', key: 'update_time', fixed: true },
  228. ]}
  229. sortMap={sortMap}
  230. filterMap={filterMap}
  231. onFilter={value => this.onFilter(value)}
  232. onSearch={value => this.onSearch(value)}
  233. onSort={value => this.onSort(value)}
  234. onAll={checked => this.onAll(checked)}
  235. onAction={key => this.onAction(key)}
  236. />
  237. <div className="list">
  238. {list.map(item => {
  239. return <Note data={item} selectList={selectList} courseNoMap={courseNoMap} onSelect={(value) => this.onSelect(value)} onClick={() => this.setState({ showDetail: true, article: item })} />;
  240. })}
  241. </div>
  242. {total > 0 && list.length > 0 && (
  243. <UserPagination total={total} current={page} pageSize={this.state.search.size} onChange={p => this.onChangePage(p)} />
  244. )}
  245. </div>
  246. {this.renderModal()}
  247. </div>
  248. );
  249. }
  250. renderModal() {
  251. const { showWarn, warn = {}, showClearConfirm, clearInfo = {}, showVip, showExamination, showReal, showExportWait, showExportConfirm, exportInfo = {} } = this.state;
  252. const { info } = this.props.user;
  253. const { article = {} } = this.state;
  254. return [
  255. <NoteDetail
  256. show={this.state.showDetail}
  257. data={article}
  258. onClose={() => this.setState({ showDetail: false })}
  259. onPrev={() => this.prevArticle()}
  260. onNext={() => this.nextArticle()}
  261. />,
  262. <Modal show={showWarn} title={warn.title} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showWarn: false })}>
  263. <div className="t-2 t-s-18">{warn.content}</div>
  264. </Modal>,
  265. <Modal show={showClearConfirm} title="移出" onConfirm={() => this.clearNote()} onCancel={() => this.setState({ showClearConfirm: false })}>
  266. <div className="t-2 t-s-18">
  267. 当前选中的 <span className="t-4">{clearInfo.courseNoIds ? clearInfo.courseNoIds.length : 0}</span> 篇即将被移出笔记,移出后无法恢复,是否继续?
  268. </div>
  269. </Modal>,
  270. <Modal show={showExportConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
  271. <div className="t-2 t-s-18 m-b-5">
  272. 当前共选中 <span className="t-4">{exportInfo.courseNoIds ? exportInfo.courseNoIds.length : 0}</span> 篇笔记,是否开始导出:
  273. </div>
  274. </Modal>,
  275. <Modal show={showExportWait} title="导出" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showExportWait: false })}>
  276. <div className="t-2 t-s-18">正在导出中,请不要关闭当前页面!</div>
  277. </Modal>,
  278. <Examination
  279. show={showExamination}
  280. data={info}
  281. onConfirm={() => this.setState({ showExamination: false })}
  282. onCancel={() => this.setState({ showExamination: false })}
  283. onClose={() => this.setState({ showExamination: false })}
  284. />,
  285. <RealAuth show={showReal} data={info} onConfirm={() => this.setState({ showReal: false })} />,
  286. <VipRenew
  287. show={showVip}
  288. data={info}
  289. onReal={() => this.setState({ showVip: false, showReal: true })}
  290. onPrepare={() => this.setState({ showVip: false, showExamination: true })}
  291. onClose={(result) => {
  292. if (result) {
  293. this.refresh();
  294. } else {
  295. this.setState({ showVip: false });
  296. }
  297. }}
  298. />,
  299. ];
  300. }
  301. }
  302. class NoteDetail extends Component {
  303. render() {
  304. const { show, data, onClose, onPrev, onNext } = this.props;
  305. return (
  306. <Modal
  307. className="note-detail-modal"
  308. body={false}
  309. show={show}
  310. width={720}
  311. maskClosable
  312. close={false}
  313. onClose={onClose}
  314. title={data.title}
  315. center
  316. >
  317. <Icon type="left" className="prev" onClick={() => onPrev && onPrev()} />
  318. <Icon type="right" className="next" onClick={() => onNext && onNext()} />
  319. <div className="t-2 t-s-18 detail" dangerouslySetInnerHTML={{ __html: data.content }} />
  320. </Modal>
  321. );
  322. }
  323. }
  324. class Note extends Component {
  325. onSelect() {
  326. const { data, onSelect, selectList } = this.props;
  327. const index = selectList.indexOf(data.key);
  328. if (index >= 0) {
  329. selectList.splice(index, 1);
  330. } else {
  331. selectList.push(data.key);
  332. }
  333. onSelect(selectList);
  334. }
  335. render() {
  336. const { data, selectList, onClick, courseNoMap = {} } = this.props;
  337. return (
  338. <div className="note-item p-t-2 b-b">
  339. <div className="t-1 t-s-14 f-w-b m-b-5">
  340. <CheckboxItem theme="white" checked={selectList.indexOf(data.key) >= 0} onClick={() => this.onSelect()} />
  341. <span className="t-2 m-l-5 m-r-5" onClick={() => onClick && onClick()}>课时{(courseNoMap[data.key] || {}).no}</span>
  342. <span onClick={() => onClick && onClick()}>{(courseNoMap[data.key] || {}).title}</span>
  343. <div className="f-r t-3 t-s-12 f-w-d">
  344. <span>{formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')}</span>
  345. </div>
  346. </div>
  347. <div className="t-2 m-b-2 detail" dangerouslySetInnerHTML={{ __html: data.content }} />
  348. </div>
  349. );
  350. }
  351. }