_mock.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import moment from 'moment';
  2. import { IVisitData, IRadarData, IAnalysisData } from './data';
  3. // mock data
  4. const visitData: IVisitData[] = [];
  5. const beginDay = new Date().getTime();
  6. const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
  7. for (let i = 0; i < fakeY.length; i += 1) {
  8. visitData.push({
  9. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
  10. y: fakeY[i],
  11. });
  12. }
  13. const visitData2 = [];
  14. const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
  15. for (let i = 0; i < fakeY2.length; i += 1) {
  16. visitData2.push({
  17. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
  18. y: fakeY2[i],
  19. });
  20. }
  21. const salesData = [];
  22. for (let i = 0; i < 12; i += 1) {
  23. salesData.push({
  24. x: `${i + 1}月`,
  25. y: Math.floor(Math.random() * 1000) + 200,
  26. });
  27. }
  28. const searchData = [];
  29. for (let i = 0; i < 50; i += 1) {
  30. searchData.push({
  31. index: i + 1,
  32. keyword: `搜索关键词-${i}`,
  33. count: Math.floor(Math.random() * 1000),
  34. range: Math.floor(Math.random() * 100),
  35. status: Math.floor((Math.random() * 10) % 2),
  36. });
  37. }
  38. const salesTypeData = [
  39. {
  40. x: '家用电器',
  41. y: 4544,
  42. },
  43. {
  44. x: '食用酒水',
  45. y: 3321,
  46. },
  47. {
  48. x: '个护健康',
  49. y: 3113,
  50. },
  51. {
  52. x: '服饰箱包',
  53. y: 2341,
  54. },
  55. {
  56. x: '母婴产品',
  57. y: 1231,
  58. },
  59. {
  60. x: '其他',
  61. y: 1231,
  62. },
  63. ];
  64. const salesTypeDataOnline = [
  65. {
  66. x: '家用电器',
  67. y: 244,
  68. },
  69. {
  70. x: '食用酒水',
  71. y: 321,
  72. },
  73. {
  74. x: '个护健康',
  75. y: 311,
  76. },
  77. {
  78. x: '服饰箱包',
  79. y: 41,
  80. },
  81. {
  82. x: '母婴产品',
  83. y: 121,
  84. },
  85. {
  86. x: '其他',
  87. y: 111,
  88. },
  89. ];
  90. const salesTypeDataOffline = [
  91. {
  92. x: '家用电器',
  93. y: 99,
  94. },
  95. {
  96. x: '食用酒水',
  97. y: 188,
  98. },
  99. {
  100. x: '个护健康',
  101. y: 344,
  102. },
  103. {
  104. x: '服饰箱包',
  105. y: 255,
  106. },
  107. {
  108. x: '其他',
  109. y: 65,
  110. },
  111. ];
  112. const offlineData = [];
  113. for (let i = 0; i < 10; i += 1) {
  114. offlineData.push({
  115. name: `Stores ${i}`,
  116. cvr: Math.ceil(Math.random() * 9) / 10,
  117. });
  118. }
  119. const offlineChartData = [];
  120. for (let i = 0; i < 20; i += 1) {
  121. offlineChartData.push({
  122. x: new Date().getTime() + 1000 * 60 * 30 * i,
  123. y1: Math.floor(Math.random() * 100) + 10,
  124. y2: Math.floor(Math.random() * 100) + 10,
  125. });
  126. }
  127. const radarOriginData = [
  128. {
  129. name: '个人',
  130. ref: 10,
  131. koubei: 8,
  132. output: 4,
  133. contribute: 5,
  134. hot: 7,
  135. },
  136. {
  137. name: '团队',
  138. ref: 3,
  139. koubei: 9,
  140. output: 6,
  141. contribute: 3,
  142. hot: 1,
  143. },
  144. {
  145. name: '部门',
  146. ref: 4,
  147. koubei: 1,
  148. output: 6,
  149. contribute: 5,
  150. hot: 7,
  151. },
  152. ];
  153. const radarData: IRadarData[] = [];
  154. const radarTitleMap = {
  155. ref: '引用',
  156. koubei: '口碑',
  157. output: '产量',
  158. contribute: '贡献',
  159. hot: '热度',
  160. };
  161. radarOriginData.forEach(item => {
  162. Object.keys(item).forEach(key => {
  163. if (key !== 'name') {
  164. radarData.push({
  165. name: item.name,
  166. label: radarTitleMap[key],
  167. value: item[key],
  168. });
  169. }
  170. });
  171. });
  172. const getFakeChartData: IAnalysisData = {
  173. visitData,
  174. visitData2,
  175. salesData,
  176. searchData,
  177. offlineData,
  178. offlineChartData,
  179. salesTypeData,
  180. salesTypeDataOnline,
  181. salesTypeDataOffline,
  182. radarData,
  183. };
  184. export default {
  185. 'GET /api/analysis/fake_chart_data': getFakeChartData,
  186. };