page.js 14 KB

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