_mock.ts 3.26 KB
Newer Older
1
import moment from 'moment';
陈帅's avatar
陈帅 committed
2
import { IVisitData, IRadarData, IAnalysisData } from './data';
3 4

// mock data
陈帅's avatar
陈帅 committed
5
const visitData: IVisitData[] = [];
6
const beginDay = new Date().getTime();
afc163's avatar
afc163 committed
7 8 9

const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
for (let i = 0; i < fakeY.length; i += 1) {
10
  visitData.push({
jim's avatar
jim committed
11
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
afc163's avatar
afc163 committed
12 13 14 15 16 17 18 19
    y: fakeY[i],
  });
}

const visitData2 = [];
const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
for (let i = 0; i < fakeY2.length; i += 1) {
  visitData2.push({
jim's avatar
jim committed
20
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
afc163's avatar
afc163 committed
21
    y: fakeY2[i],
22 23
  });
}
afc163's avatar
afc163 committed
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
const salesData = [];
for (let i = 0; i < 12; i += 1) {
  salesData.push({
    x: `${i + 1}月`,
    y: Math.floor(Math.random() * 1000) + 200,
  });
}
const searchData = [];
for (let i = 0; i < 50; i += 1) {
  searchData.push({
    index: i + 1,
    keyword: `搜索关键词-${i}`,
    count: Math.floor(Math.random() * 1000),
    range: Math.floor(Math.random() * 100),
    status: Math.floor((Math.random() * 10) % 2),
  });
}
const salesTypeData = [
  {
陈帅's avatar
陈帅 committed
44
    x: '家用电器',
45 46 47
    y: 4544,
  },
  {
陈帅's avatar
陈帅 committed
48
    x: '食用酒水',
49 50 51
    y: 3321,
  },
  {
陈帅's avatar
陈帅 committed
52
    x: '个护健康',
53 54 55
    y: 3113,
  },
  {
陈帅's avatar
陈帅 committed
56
    x: '服饰箱包',
57 58 59
    y: 2341,
  },
  {
陈帅's avatar
陈帅 committed
60
    x: '母婴产品',
61 62 63
    y: 1231,
  },
  {
陈帅's avatar
陈帅 committed
64
    x: '其他',
65 66 67 68 69 70
    y: 1231,
  },
];

const salesTypeDataOnline = [
  {
陈帅's avatar
陈帅 committed
71
    x: '家用电器',
72 73 74
    y: 244,
  },
  {
陈帅's avatar
陈帅 committed
75
    x: '食用酒水',
76 77 78
    y: 321,
  },
  {
陈帅's avatar
陈帅 committed
79
    x: '个护健康',
80 81 82
    y: 311,
  },
  {
陈帅's avatar
陈帅 committed
83
    x: '服饰箱包',
84 85 86
    y: 41,
  },
  {
陈帅's avatar
陈帅 committed
87
    x: '母婴产品',
88 89 90
    y: 121,
  },
  {
陈帅's avatar
陈帅 committed
91
    x: '其他',
92 93 94 95 96 97
    y: 111,
  },
];

const salesTypeDataOffline = [
  {
陈帅's avatar
陈帅 committed
98
    x: '家用电器',
99 100 101
    y: 99,
  },
  {
陈帅's avatar
陈帅 committed
102
    x: '食用酒水',
103 104 105
    y: 188,
  },
  {
陈帅's avatar
陈帅 committed
106
    x: '个护健康',
107 108 109
    y: 344,
  },
  {
陈帅's avatar
陈帅 committed
110
    x: '服饰箱包',
111 112 113
    y: 255,
  },
  {
陈帅's avatar
陈帅 committed
114
    x: '其他',
115 116 117 118 119 120 121
    y: 65,
  },
];

const offlineData = [];
for (let i = 0; i < 10; i += 1) {
  offlineData.push({
陈帅's avatar
陈帅 committed
122
    name: `Stores ${i}`,
123 124 125 126 127 128
    cvr: Math.ceil(Math.random() * 9) / 10,
  });
}
const offlineChartData = [];
for (let i = 0; i < 20; i += 1) {
  offlineChartData.push({
jim's avatar
jim committed
129
    x: new Date().getTime() + 1000 * 60 * 30 * i,
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    y1: Math.floor(Math.random() * 100) + 10,
    y2: Math.floor(Math.random() * 100) + 10,
  });
}

const radarOriginData = [
  {
    name: '个人',
    ref: 10,
    koubei: 8,
    output: 4,
    contribute: 5,
    hot: 7,
  },
  {
    name: '团队',
    ref: 3,
    koubei: 9,
    output: 6,
    contribute: 3,
    hot: 1,
  },
  {
    name: '部门',
    ref: 4,
    koubei: 1,
    output: 6,
    contribute: 5,
    hot: 7,
  },
];

陈帅's avatar
陈帅 committed
162
const radarData: IRadarData[] = [];
163 164 165 166 167 168 169
const radarTitleMap = {
  ref: '引用',
  koubei: '口碑',
  output: '产量',
  contribute: '贡献',
  hot: '热度',
};
jim's avatar
jim committed
170 171
radarOriginData.forEach(item => {
  Object.keys(item).forEach(key => {
172 173 174 175 176 177 178 179 180 181
    if (key !== 'name') {
      radarData.push({
        name: item.name,
        label: radarTitleMap[key],
        value: item[key],
      });
    }
  });
});

陈帅's avatar
陈帅 committed
182
const getFakeChartData: IAnalysisData = {
183
  visitData,
afc163's avatar
afc163 committed
184
  visitData2,
185 186 187 188 189 190 191 192 193 194 195
  salesData,
  searchData,
  offlineData,
  offlineChartData,
  salesTypeData,
  salesTypeDataOnline,
  salesTypeDataOffline,
  radarData,
};

export default {
196
  'GET /api/BLOCK_NAME/fake_chart_data': getFakeChartData,
197
};