-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
286 lines (263 loc) · 8.57 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
Bmob.initialize("1f83c3fb0dd43f84fb2e7c5b659c3d26", "e48ecaadf867fcf9dc94340b6dcf22aa");
var $http = axios.create({
baseURL: 'https://mmmm.gaoding.com/api/',
});
function $timeConvert(time, type = 'Y/M/D h:m', zero = true) {
let result = '';
const now = new Date(time);
const weekCn = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
const getWeekCn = (week) => weekCn[week];
const nowArray = [
{
name: 'Y',
val: now.getFullYear(),
},
{
name: 'M',
val: now.getMonth() + 1,
},
{
name: 'D',
val: now.getDate(),
},
{
name: 'h',
val: now.getHours(),
},
{
name: 'm',
val: now.getMinutes(),
},
{
name: 's',
val: now.getSeconds(),
},
{
name: 'W',
val: getWeekCn(now.getDay())
},
];
if (zero) {
// 补0
nowArray.map(it => {
it.val = it.val < 10 ? '0' + it.val : it.val;
});
}
let timeArray = type.split('');
for (let i = 0; i < timeArray.length; i += 1) {
for (let j = 0; j < nowArray.length; j += 1) {
if (timeArray[i] === nowArray[j].name) {
timeArray[i] = nowArray[j].val;
result += timeArray[i];
break;
} else if (j === (nowArray.length - 1)) {
result += timeArray[i];
}
}
}
return result;
};
//返回的是对象形式的参数
function getDate() {
const nowDate = new Date();
let startDate = null;
let endDate = null;
const query = location.search.substring(1);//获取查询串
if (!query) {
startDate = new Date(
nowDate.getFullYear(),
nowDate.getMonth(),
nowDate.getDate(),
).getTime();
window.location.href = window.location.href + `?date=${$timeConvert(startDate, type = 'Y-M-D')}`
endDate = dateEnd(nowDate);
} else {
const pairs = query.split("=");
if (pairs[1] === 'all') {
startDate = 1000000000000;
endDate = dateEnd(2000000000000);
} else {
const date = pairs[1].replace(/-/g, '/');
startDate = new Date(date).getTime();
endDate = dateEnd(date);
}
}
return {
startDate: Number(startDate.toString().substring(0, 10)),
endDate: Number(endDate.toString().substring(0, 10)),
};
}
function dateEnd(date) {
let dateEnd = new Date(date);
dateEnd.setDate(dateEnd.getDate() + 1);
return dateEnd.getTime();
}
// 计算出最多的模板
function getCount(arr, rank, ranktype) {
var obj = {}, k, arr1 = [];
for (var i = 0, len = arr.length; i < len; i++) {
k = arr[i];
if (obj[k])
obj[k]++;
else
obj[k] = 1;
}
//保存结果{el-'元素',count-出现次数}
for (var o in obj) {
arr1.push({ el: o, count: obj[o] });
}
//排序(降序)
arr1.sort(function (n1, n2) {
return n2.count - n1.count
});
//如果ranktype为1,则为升序,反转数组
if (ranktype === 1) {
arr1 = arr1.reverse();
}
var rank1 = rank || arr1.length;
return arr1.slice(0, rank1);
}
window.app = new Vue({
el: '#app',
data: {
message: '123',
list: [],
ztList: [],
bannerList: [],
stList: [],
ctList: [],
sjList: [],
ewmList: [],
max3: [],
max1List: [],
max2List: [],
max3List: [],
max4List: [],
pageDate: '2018-01-01',
updateTime: '',
updateBtn: {
disable: false,
text: '更新数据'
},
},
methods: {
setDateTip: function () {
alert('将网址中"date="后面的日期改为需要搜索的日期 \n 设置"all"则显示所有日期')
},
update: function () {
this.updateBtn = {
disable: true,
text: '更新中'
}
$http.get('https://apiab.zuolem.com/api/gaoDing/getHistory').then(({ data }) => {
console.log(data)
if (data.data.stdout === '') {
alert('暂无更新')
} else {
location.reload();
}
this.updateBtn = {
disable: false,
text: '获取更新'
}
});
}
},
computed: {
pageDateVal: function () {
const date = location.search.substring(1).split('=')[1];
return date === 'all' ? '全部' : date;
}
},
watch: {
list: function () {
if (!this.list.length) return;
const maxArr = [];
this.maxArr = [];
this.max1List = [];
this.max2List = [];
this.max3List = [];
this.max4List = [];
this.ztList = [];
this.bannerList = [];
this.bannerList = [];
this.stList = [];
this.ctList = [];
this.ctList = [];
this.sjList = [];
this.ewmList = [];
this.updateTime = $timeConvert(Number(this.list[(this.list.length - 1)]['attributes']['created_at'] + '000'), 'Y/M/D h:m');
list = JSON.parse(JSON.stringify(this.list)).reverse();
list.map((attributes, idx) => {
attributes.updated_at = $timeConvert(Number(attributes.updated_at + '000'), 'h:m');
// 统计平台和分类
if (attributes.platform_id === 32) {
if (attributes.categories === 1) {
this.ztList.push(attributes);
} else if (attributes.categories === 4) {
this.bannerList.push(attributes);
}
} else {
if (attributes.categories === 1) {
this.stList.push(attributes);
} else if (attributes.categories === 2) {
this.ctList.push(attributes);
} else if (attributes.categories === 4) {
this.sjList.push(attributes);
} else {
this.ewmList.push(attributes);
}
}
// 统计最多的模板ID
if (attributes.source_id) maxArr.push(attributes.source_id);
});
this.max3 = getCount(maxArr, 5);
list.map((attributes, idx) => {
// 统计平台和分类
if (this.max3.length > 0 && attributes.source_id.toString() === this.max3[0].el) {
this.max1List.push(attributes);
} else if (this.max3.length > 1 && attributes.source_id.toString() === this.max3[1].el) {
this.max2List.push(attributes);
} else if (this.max3.length > 2 && attributes.source_id.toString() === this.max3[2].el) {
this.max3List.push(attributes);
} else if (this.max3.length > 3 && attributes.source_id.toString() === this.max3[3].el) {
this.max4List.push(attributes);
}
});
}
},
created: function () {
const { startDate, endDate } = getDate();
const HistoryScore = Bmob.Object.extend("history");
const query = new Bmob.Query(HistoryScore);
let list = [];
query.greaterThan("created_at", startDate);
query.lessThan("created_at", endDate);
query.limit(500);
query.count({
success: (count) => {
// 查询成功,返回记录数量
console.log("共有 " + count + " 条记录");
if (count > 500) {
for (var i = 0; i < Math.ceil(count / 500); i++) {
query.skip(i * 500)
query.find({
success: (results) => {
list.push.apply(list, results);
this.list = list;
}
});
}
}
query.find({
success: (results) => {
this.list = results;
}
});
},
error: (error) => {
// 查询失败
}
});
}
})