_chart.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { format } from 'date-fns';
  17. import * as Mock from 'mockjs';
  18. // region: mock data
  19. const visitData: any[] = [];
  20. const beginDay = new Date().getTime();
  21. const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
  22. for (let i = 0; i < fakeY.length; i += 1) {
  23. visitData.push({
  24. x: format(new Date(beginDay + 1000 * 60 * 60 * 24 * i), 'yyyy-MM-dd'),
  25. y: fakeY[i]
  26. });
  27. }
  28. const visitData2: any[] = [];
  29. const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
  30. for (let i = 0; i < fakeY2.length; i += 1) {
  31. visitData2.push({
  32. x: format(new Date(beginDay + 1000 * 60 * 60 * 24 * i), 'yyyy-MM-dd'),
  33. y: fakeY2[i]
  34. });
  35. }
  36. const salesData: any[] = [];
  37. for (let i = 0; i < 12; i += 1) {
  38. salesData.push({
  39. x: `${i + 1}月`,
  40. y: Math.floor(Math.random() * 1000) + 200
  41. });
  42. }
  43. const searchData: any[] = [];
  44. for (let i = 0; i < 50; i += 1) {
  45. searchData.push({
  46. index: i + 1,
  47. keyword: `搜索关键词-${i}`,
  48. count: Math.floor(Math.random() * 1000),
  49. range: Math.floor(Math.random() * 100),
  50. status: Math.floor((Math.random() * 10) % 2)
  51. });
  52. }
  53. const salesTypeData = [
  54. {
  55. x: '家用电器',
  56. y: 4544
  57. },
  58. {
  59. x: '食用酒水',
  60. y: 3321
  61. },
  62. {
  63. x: '个护健康',
  64. y: 3113
  65. },
  66. {
  67. x: '服饰箱包',
  68. y: 2341
  69. },
  70. {
  71. x: '母婴产品',
  72. y: 1231
  73. },
  74. {
  75. x: '其他',
  76. y: 1231
  77. }
  78. ];
  79. const salesTypeDataOnline = [
  80. {
  81. x: '家用电器',
  82. y: 244
  83. },
  84. {
  85. x: '食用酒水',
  86. y: 321
  87. },
  88. {
  89. x: '个护健康',
  90. y: 311
  91. },
  92. {
  93. x: '服饰箱包',
  94. y: 41
  95. },
  96. {
  97. x: '母婴产品',
  98. y: 121
  99. },
  100. {
  101. x: '其他',
  102. y: 111
  103. }
  104. ];
  105. const salesTypeDataOffline = [
  106. {
  107. x: '家用电器',
  108. y: 99
  109. },
  110. {
  111. x: '个护健康',
  112. y: 188
  113. },
  114. {
  115. x: '服饰箱包',
  116. y: 344
  117. },
  118. {
  119. x: '母婴产品',
  120. y: 255
  121. },
  122. {
  123. x: '其他',
  124. y: 65
  125. }
  126. ];
  127. const offlineData: any[] = [];
  128. for (let i = 0; i < 10; i += 1) {
  129. offlineData.push({
  130. name: `门店${i}`,
  131. cvr: Math.ceil(Math.random() * 9) / 10
  132. });
  133. }
  134. const offlineChartData: any[] = [];
  135. for (let i = 0; i < 20; i += 1) {
  136. offlineChartData.push({
  137. time: new Date().getTime() + 1000 * 60 * 30 * i,
  138. y1: Math.floor(Math.random() * 100) + 10,
  139. y2: Math.floor(Math.random() * 100) + 10
  140. });
  141. }
  142. const radarOriginData = [
  143. {
  144. name: '个人',
  145. ref: 10,
  146. koubei: 8,
  147. output: 4,
  148. contribute: 5,
  149. hot: 7
  150. },
  151. {
  152. name: '团队',
  153. ref: 3,
  154. koubei: 9,
  155. output: 6,
  156. contribute: 3,
  157. hot: 1
  158. },
  159. {
  160. name: '部门',
  161. ref: 4,
  162. koubei: 1,
  163. output: 6,
  164. contribute: 5,
  165. hot: 7
  166. }
  167. ];
  168. //
  169. const radarData: any[] = [];
  170. const radarTitleMap: any = {
  171. ref: '引用',
  172. koubei: '口碑',
  173. output: '产量',
  174. contribute: '贡献',
  175. hot: '热度'
  176. };
  177. radarOriginData.forEach((item: any) => {
  178. Object.keys(item).forEach(key => {
  179. if (key !== 'name') {
  180. radarData.push({
  181. name: item.name,
  182. label: radarTitleMap[key],
  183. value: item[key]
  184. });
  185. }
  186. });
  187. });
  188. // endregion
  189. export const CHARTS = {
  190. '/chart': JSON.parse(
  191. JSON.stringify({
  192. visitData,
  193. visitData2,
  194. salesData,
  195. searchData,
  196. offlineData,
  197. offlineChartData,
  198. salesTypeData,
  199. salesTypeDataOnline,
  200. salesTypeDataOffline,
  201. radarData
  202. })
  203. ),
  204. '/chart/visit': JSON.parse(JSON.stringify(visitData)),
  205. '/chart/tags': Mock.mock({
  206. 'list|100': [{ name: '@city', 'value|1-100': 150 }]
  207. })
  208. };