page.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import React from 'react';
  2. import './index.less';
  3. import LineChart from '@src/components/LineChart';
  4. import BarChart from '@src/components/BarChart';
  5. import PieChart from '@src/components/PieChart';
  6. import Page from '@src/containers/Page';
  7. import { Question } from '../../../stores/question';
  8. const lineOption = {
  9. title: {
  10. text: '每题用时情况',
  11. textStyle: { fontSize: 24, fontWeight: 'normal', color: '#5e677b' },
  12. },
  13. tooltip: {
  14. trigger: 'axis',
  15. },
  16. legend: {
  17. data: ['我的', '全站'],
  18. right: 20,
  19. orient: 'vertical',
  20. },
  21. xAxis: {
  22. type: 'category',
  23. },
  24. yAxis: {
  25. type: 'value',
  26. min: 0,
  27. },
  28. dataset: {
  29. source: [['type', '我的', '全站'], ['1', 43.3, 85.8], ['2', 43.1, 73.4], ['3', 56.4, 65.2]],
  30. },
  31. series: [
  32. {
  33. type: 'line',
  34. smooth: true,
  35. color: '#8684df',
  36. },
  37. {
  38. type: 'line',
  39. smooth: true,
  40. color: '#5195e5',
  41. },
  42. ],
  43. };
  44. const barOption = {
  45. title: {
  46. text: '正确率',
  47. textStyle: { fontSize: 24, fontWeight: 'normal', color: '#5e677b' },
  48. },
  49. tooltip: {
  50. trigger: 'axis',
  51. },
  52. legend: {
  53. data: ['我的', '全站'],
  54. right: 20,
  55. orient: 'vertical',
  56. },
  57. dataset: {
  58. source: [['type', '我的', '全站'], ['Easy', 43.3, 85.8], ['Medium', 43.1, 73.4], ['Hard', 56.4, 65.2]],
  59. },
  60. xAxis: { type: 'category', boundaryGap: true },
  61. yAxis: {
  62. min: 0,
  63. max: 100,
  64. },
  65. series: [{ type: 'bar', barWidth: 40, color: '#8684df' }, { type: 'bar', barWidth: 40, color: '#5195e5' }],
  66. };
  67. const bar1Option = {
  68. title: {
  69. text: '用时',
  70. textStyle: { fontSize: 24, fontWeight: 'normal', color: '#5e677b' },
  71. },
  72. dataset: {
  73. source: [['type', 'text'], ['Avg Time Total', 43.3], ['Avg Time Correct', 43.1], ['Avg Time Incorrect', 56.4]],
  74. },
  75. xAxis: { type: 'category', axisTick: { show: false }, axisLine: { show: false }, splitLine: { show: false } },
  76. yAxis: {
  77. show: false,
  78. min: 0,
  79. max: 100,
  80. axisTick: { show: false },
  81. axisLine: { show: false },
  82. splitLine: { show: false },
  83. },
  84. series: [{ type: 'bar', barWidth: 40, color: '#8684df' }],
  85. };
  86. const bar2Option = {
  87. title: {
  88. text: '正确率',
  89. textStyle: { fontSize: 18, fontWeight: 'normal', color: '#5e677b' },
  90. left: 240,
  91. },
  92. dataset: {
  93. source: [['type', '我的'], ['Avg Time Total', 43.3], ['Avg Time Correct', 43.1], ['Avg Time Incorrect', 56.4]],
  94. },
  95. grid: { left: 240 },
  96. xAxis: {
  97. show: false,
  98. axisTick: { show: false },
  99. axisLine: { show: false },
  100. splitLine: { show: false },
  101. },
  102. yAxis: {
  103. type: 'category',
  104. show: true,
  105. axisTick: { show: false },
  106. axisLine: { show: false },
  107. splitLine: { show: false },
  108. axisLabel: { fontSize: 18, fontWeight: 'normal', color: '#5e677b' },
  109. offset: 36,
  110. },
  111. series: [
  112. {
  113. type: 'bar',
  114. barWidth: 40,
  115. color: '#8684df',
  116. label: {
  117. normal: {
  118. show: true,
  119. position: 'insideLeft',
  120. distance: 15,
  121. },
  122. },
  123. },
  124. ],
  125. };
  126. const bar3Option = {
  127. title: {
  128. text: '平均用时',
  129. textStyle: { fontSize: 18, fontWeight: 'normal', color: '#5e677b' },
  130. left: '10%',
  131. },
  132. dataset: {
  133. source: [['type', '我的'], ['Avg Time Total', 43.3], ['Avg Time Correct', 43.1], ['Avg Time Incorrect', 56.4]],
  134. },
  135. xAxis: {
  136. show: false,
  137. axisTick: { show: false },
  138. axisLine: { show: false },
  139. splitLine: { show: false },
  140. },
  141. yAxis: {
  142. type: 'category',
  143. show: true,
  144. axisTick: { show: false },
  145. axisLine: { show: false },
  146. splitLine: { show: false },
  147. axisLabel: { show: false },
  148. },
  149. series: [
  150. {
  151. type: 'bar',
  152. barWidth: 40,
  153. color: '#8684df',
  154. label: {
  155. normal: {
  156. show: true,
  157. position: 'insideLeft',
  158. distance: 15,
  159. },
  160. },
  161. },
  162. ],
  163. };
  164. const pieOption = {
  165. visualMap: {
  166. show: false,
  167. min: 0,
  168. max: 800,
  169. inRange: {
  170. colorLightness: [1, 0],
  171. },
  172. },
  173. series: [
  174. {
  175. name: '访问来源',
  176. type: 'pie',
  177. radius: '55%',
  178. center: ['50%', '50%'],
  179. roseType: 'radius',
  180. label: {
  181. normal: {
  182. fontSize: 18,
  183. position: 'inside',
  184. },
  185. },
  186. itemStyle: {
  187. normal: {
  188. color: '#5195e5',
  189. shadowBlur: 40,
  190. shadowColor: 'rgba(0, 0, 0, 0.2)',
  191. },
  192. },
  193. animationType: 'scale',
  194. animationEasing: 'elasticOut',
  195. animationDelay: () => {
  196. return Math.random() * 200;
  197. },
  198. data: [{ value: 335, name: '直接访问' }, { value: 310, name: '邮件营销' }, { value: 274, name: '联盟广告' }].sort(
  199. (a, b) => {
  200. return a.value - b.value;
  201. },
  202. ),
  203. },
  204. ],
  205. };
  206. export default class extends Page {
  207. initData() {
  208. const { id } = this.params;
  209. Question.detailReport(id).then(result => {
  210. switch (result.paperModule) {
  211. case 'sentence':
  212. this.refreshSentence(result);
  213. break;
  214. case 'textbook':
  215. this.refreshTextbook(result);
  216. break;
  217. case 'exercise':
  218. this.refreshExercise(result);
  219. break;
  220. case 'examination':
  221. this.refreshExamination(result);
  222. break;
  223. default:
  224. }
  225. this.setState({ report: result });
  226. });
  227. }
  228. refreshSentence() {
  229. }
  230. refreshTextbook() {
  231. }
  232. refreshExamination() {
  233. }
  234. refreshExercise() {
  235. }
  236. renderView() {
  237. const { report = {} } = this.state;
  238. switch (report.paperModule) {
  239. case 'sentence':
  240. return this.renderSentence();
  241. case 'textbook':
  242. return this.renderTextbook();
  243. case 'exercise':
  244. return this.renderExercise();
  245. case 'examination':
  246. return this.renderExamination();
  247. default:
  248. return <div />;
  249. }
  250. }
  251. renderSentence() {
  252. return <div />;
  253. }
  254. renderTextbook() {
  255. return <div />;
  256. }
  257. renderExercise() {
  258. return (
  259. <div>
  260. <div className="content">
  261. <LineChart option={lineOption} />
  262. <BarChart option={bar1Option} />
  263. <BarChart option={bar2Option} />
  264. <BarChart option={bar3Option} />
  265. <BarChart option={barOption} />
  266. <PieChart option={pieOption} />
  267. </div>
  268. </div>
  269. );
  270. }
  271. renderExamination() {
  272. return <div />;
  273. }
  274. }