page.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React from 'react';
  2. import './index.less';
  3. import { Tabs } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import { formatDate } from '@src/services/Tools';
  6. import Button from '../../../components/Button';
  7. import { Textbook } from '../../../stores/textbook';
  8. import { TextbookSubject } from '../../../../Constant';
  9. const TextbookSubjectTabs = TextbookSubject.map(row => {
  10. return {
  11. title: row.label,
  12. key: row.value,
  13. };
  14. });
  15. export default class extends Page {
  16. initState() {
  17. return {
  18. tab: TextbookSubjectTabs[0],
  19. day: 0,
  20. };
  21. }
  22. initData() {
  23. Textbook.getInfo()
  24. .then(result => {
  25. result.day = parseInt((new Date().getTime() - new Date(result.latest.startDate).getTime()) / 86400000, 10);
  26. this.setState(result);
  27. });
  28. this.refreshTab(this.state.tab);
  29. }
  30. refreshTab(tab) {
  31. this.setState({ tab });
  32. Textbook.allHistory(tab.key).then(result => {
  33. result = result.map(row => {
  34. row.version = row[`${tab.key}Version`];
  35. row.content = row[`${tab.key}Content`];
  36. row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
  37. return row;
  38. });
  39. this.setState({ list: result });
  40. });
  41. }
  42. renderView() {
  43. const { latest = {}, hasService, tab, day } = this.state;
  44. return (
  45. <div>
  46. <div className="tip">最近换库时间:{latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''},已换库{day}天。</div>
  47. <Tabs page={tab.key} tabs={TextbookSubjectTabs} onChange={(v) => {
  48. this.refreshTab(v);
  49. }} />
  50. <div>{hasService ? this.renderList() : this.renderEmpty()}</div>
  51. <div className="fixed">
  52. <Button block disabled={!hasService} size="lager" onClick={() => {
  53. linkTo(`/textbook/detail/${tab.key}`);
  54. }}>
  55. 查阅机经
  56. </Button>
  57. </div>
  58. </div>
  59. );
  60. }
  61. renderList() {
  62. const { list = [] } = this.state;
  63. return (
  64. <div className="list">
  65. <div className="log-title">更新日志</div>
  66. {list.map(row => {
  67. return <div className="item">
  68. <div className="title">
  69. 版本{row.version}<span className="date">{row.createTime}</span>
  70. </div>
  71. <div className="desc" >{row.content}</div>
  72. </div>;
  73. })}
  74. </div>
  75. );
  76. }
  77. renderEmpty() {
  78. const { unUseRecord } = this.state;
  79. if (unUseRecord) {
  80. return <div className="empty">
  81. <div className="text">
  82. 还未开通本月机经。 <br />
  83. 您可至千行网站「我的-工具」查看往期机经。
  84. </div>
  85. <Button block width={120} radius onClick={() => {
  86. linkTo(`/open/${unUseRecord.id}`);
  87. }}>
  88. 去开通
  89. </Button>
  90. </div>;
  91. }
  92. return (
  93. <div className="empty">
  94. <div className="text">
  95. 还未购买本月机经。 <br />
  96. 您可至千行网站「我的-工具」查看往期机经。
  97. </div>
  98. <Button block width={120} radius onClick={() => {
  99. linkTo('/product/service/textbook');
  100. }}>
  101. 去购买
  102. </Button>
  103. </div>
  104. );
  105. }
  106. }