page.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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({ page: 1, 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 && value[keys[index]] ? 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 } = this.state;
  88. const { list = [] } = this.state;
  89. if (checked) {
  90. list.forEach(item => {
  91. if (selectList.indexOf(item.key) >= 0) return;
  92. selectList.push(item.key);
  93. });
  94. } else {
  95. list.forEach(item => {
  96. const index = selectList.indexOf(item.key);
  97. if (index < 0) return;
  98. selectList.splice(index, 1);
  99. });
  100. }
  101. this.setState({ selectList, allChecked: checked });
  102. }
  103. onSelect(selectList) {
  104. this.setState({ selectList, allCheckbox: false });
  105. }
  106. onAction(key) {
  107. const { info } = this.props.user;
  108. const { selectList } = this.state;
  109. switch (key) {
  110. case 'help':
  111. this.setState({ showTips: true });
  112. return;
  113. case 'clear':
  114. if (selectList.length === 0) {
  115. this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1篇,请重新选择' } });
  116. return;
  117. }
  118. this.setState({ showClearConfirm: true, clearInfo: { courseNoIds: selectList } });
  119. break;
  120. case 'export':
  121. if (!info.vip) {
  122. this.setState({ showVip: true });
  123. return;
  124. }
  125. if (selectList.length < 1) {
  126. this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于1篇,请重新选择' } });
  127. return;
  128. }
  129. this.setState({ showExportConfirm: true, exportInfo: { courseNoIds: selectList } });
  130. break;
  131. default:
  132. }
  133. }
  134. clearNote() {
  135. const { exportInfo } = this.state;
  136. My.clearCourseNote(exportInfo.courseNoIds)
  137. .then(() => {
  138. this.refresh();
  139. })
  140. .then(e => {
  141. this.setState({ warn: { title: '移除', content: e.message }, showClearConfirm: false });
  142. });
  143. }
  144. export() {
  145. const { exportInfo } = this.state;
  146. this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
  147. My.exportNoteCourse(exportInfo)
  148. .then((result) => {
  149. openLink(`/export/${result}`);
  150. this.setState({ showExportWait: false });
  151. })
  152. .catch(e => {
  153. this.setState({ warn: { title: '导出', content: e.message }, showExportWait: false });
  154. });
  155. }
  156. prevArticle() {
  157. const { article, list } = this.state;
  158. let index = 0;
  159. list.forEach((row, i) => {
  160. if (article.key === row.key) index = i;
  161. });
  162. index -= 1;
  163. if (index < 0) {
  164. index = list.length + index;
  165. }
  166. this.setState({ article: list[index] });
  167. }
  168. nextArticle() {
  169. const { article, list } = this.state;
  170. let index = 0;
  171. list.forEach((row, i) => {
  172. if (article.key === row.key) index = i;
  173. });
  174. index += 1;
  175. if (index >= list.length) {
  176. index -= list.length;
  177. }
  178. this.setState({ article: list[index] });
  179. }
  180. renderView() {
  181. const { course = {}, courseNoMap = {}, list = [], selectList = [], sortMap, filterMap, allChecked, total, page } = this.state;
  182. const {
  183. user: { info },
  184. } = this.props;
  185. return (
  186. <div>
  187. <div className="top content t-8">
  188. 千行课堂 > 全部课程 > {course.title} > <span className="t-1">我的笔记</span>
  189. <div className="f-r" onClick={() => linkTo(`/course/detail/${course.id}`)}>返回课程</div>
  190. </div>
  191. <div className="center content">
  192. <div className="t-1 t-s-20 m-b-2">{course.title}</div>
  193. <UserAction
  194. allCheckbox
  195. allChecked={allChecked}
  196. search
  197. defaultSearch={filterMap.keyword}
  198. btnList={[
  199. { title: '删除', key: 'delete' },
  200. { title: '导出', key: 'export', tag: 'vip', disabled: !info.vip },
  201. ]}
  202. sortList={[
  203. { right: true, label: '课时', key: 'courseNoId', fixed: true },
  204. { right: true, label: '更新时间', key: 'updateTime', fixed: true },
  205. ]}
  206. sortMap={sortMap}
  207. filterMap={filterMap}
  208. onFilter={value => this.onFilter(value)}
  209. onSearch={value => this.onSearch(value)}
  210. onSort={value => this.onSort(value)}
  211. onAll={checked => this.onAll(checked)}
  212. onAction={key => this.onAction(key)}
  213. />
  214. <div className="list">
  215. {list.map(item => {
  216. return <Note data={item} selectList={selectList} courseNoMap={courseNoMap} onSelect={(value) => this.onSelect(value)} onClick={() => this.setState({ showDetail: true, article: item })} />;
  217. })}
  218. </div>
  219. {total > 0 && list.length > 0 && (
  220. <UserPagination total={total} current={page} pageSize={this.state.search.size} onChange={p => this.onChangePage(p)} />
  221. )}
  222. </div>
  223. {this.renderModal()}
  224. </div>
  225. );
  226. }
  227. renderModal() {
  228. const { showWarn, warn = {}, showClearConfirm, clearInfo = {}, showVip, showExamination, showReal, showExportWait, showExportConfirm, exportInfo = {} } = this.state;
  229. const { info } = this.props.user;
  230. const { article = {} } = this.state;
  231. return [
  232. <NoteDetail
  233. show={this.state.showDetail}
  234. data={article}
  235. onClose={() => this.setState({ showDetail: false })}
  236. onPrev={() => this.prevArticle()}
  237. onNext={() => this.nextArticle()}
  238. />,
  239. <Modal show={showWarn} title={warn.title} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showWarn: false })}>
  240. <div className="t-2 t-s-18">{warn.content}</div>
  241. </Modal>,
  242. <Modal show={showClearConfirm} title="移出" onConfirm={() => this.clearNote()} onCancel={() => this.setState({ showClearConfirm: false })}>
  243. <div className="t-2 t-s-18">
  244. 当前选中的 <span className="t-4">{clearInfo.courseNoIds ? clearInfo.courseNoIds.length : 0}</span> 篇即将被移出笔记,移出后无法恢复,是否继续?
  245. </div>
  246. </Modal>,
  247. <Modal show={showExportConfirm} title="导出" confirmText="导出" onConfirm={() => this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
  248. <div className="t-2 t-s-18 m-b-5">
  249. 当前共选中 <span className="t-4">{exportInfo.courseNoIds ? exportInfo.courseNoIds.length : 0}</span> 篇笔记,是否开始导出:
  250. </div>
  251. </Modal>,
  252. <Modal show={showExportWait} title="导出" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showExportWait: false })}>
  253. <div className="t-2 t-s-18">正在下载中,请不要关闭当前页面!</div>
  254. </Modal>,
  255. <Examination
  256. show={showExamination}
  257. data={info}
  258. onConfirm={() => this.setState({ showExamination: false })}
  259. onCancel={() => this.setState({ showExamination: false })}
  260. onClose={() => this.setState({ showExamination: false })}
  261. />,
  262. <RealAuth show={showReal} data={info} onConfirm={() => this.setState({ showReal: false })} />,
  263. <VipRenew
  264. show={showVip}
  265. data={info}
  266. onReal={() => this.setState({ showVip: false, showReal: true })}
  267. onPrepare={() => this.setState({ showVip: false, showExamination: true })}
  268. onClose={(result) => {
  269. if (result) {
  270. this.refresh();
  271. } else {
  272. this.setState({ showVip: false });
  273. }
  274. }}
  275. />,
  276. ];
  277. }
  278. }
  279. class NoteDetail extends Component {
  280. render() {
  281. const { show, data, onClose, onPrev, onNext } = this.props;
  282. return (
  283. <Modal
  284. className="note-detail-modal"
  285. body={false}
  286. show={show}
  287. width={720}
  288. maskClosable
  289. close={false}
  290. onClose={onClose}
  291. title={data.title}
  292. center
  293. >
  294. <Icon type="left" className="prev" onClick={() => onPrev && onPrev()} />
  295. <Icon type="right" className="next" onClick={() => onNext && onNext()} />
  296. <div className="t-2 t-s-18 detail" dangerouslySetInnerHTML={{ __html: data.content }} />
  297. </Modal>
  298. );
  299. }
  300. }
  301. class Note extends Component {
  302. onSelect() {
  303. const { data, onSelect, selectList } = this.props;
  304. const index = selectList.indexOf(data.key);
  305. if (index >= 0) {
  306. selectList.splice(index, 1);
  307. } else {
  308. selectList.push(data.key);
  309. }
  310. onSelect(selectList);
  311. }
  312. render() {
  313. const { data, selectList, onClick, courseNoMap = {} } = this.props;
  314. return (
  315. <div className="note-item p-t-2 b-b">
  316. <div className="t-1 t-s-14 f-w-b m-b-5">
  317. <CheckboxItem theme="white" checked={selectList.indexOf(data.key) >= 0} onClick={() => this.onSelect()} />
  318. <span className="t-2 m-l-5 m-r-5" onClick={() => onClick && onClick()}>课时{(courseNoMap[data.key] || {}).no}</span>
  319. <span onClick={() => onClick && onClick()}>{(courseNoMap[data.key] || {}).title}</span>
  320. <div className="f-r t-3 t-s-12 f-w-d">
  321. <span>{formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')}</span>
  322. </div>
  323. </div>
  324. <div className="t-2 m-b-2 detail" dangerouslySetInnerHTML={{ __html: data.content }} />
  325. </div>
  326. );
  327. }
  328. }