page.js 14 KB

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