index.js
11.2 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
import {
getBindtapData
} from '../../utils/util'
let interstitialAd = null
let app = getApp();
Page({
data: {
isOverShare: true,
authorizeVisible: false,
total: 0,
page: 1,
size: 10,
dataList: [],
tabList: [], // 标签列表
listType: 2, // 拜年模块 0是普通视频列表 1是推荐 2是祝福语 非2就是普通视频
bannerList: [],
curTab: {},
queueCode: "", // 队列标识,每次请求,会返回一个队列标识,用户加载更多时候请携带queueCode参数
active: 0,
curBanner: {},
blessContent: [{
type: "text",
content: "文本内容",
color: "0xffffff",
size: "26"
},
{
type: "image",
content: "url",
},
],
adConfigure: {}, //广告位配置
options: {},
},
onShareAppMessage(res) {
if (res.from === 'button') {
// 来自页面内转发按钮
} else {
// 打点
app.stat({
classify: "share",
action: "list_page_share",
primaryCode: this.data.curTab.tabCode,
});
}
if (app.globalData.adConfigure && app.globalData.adConfigure.ad_config_01 == 1) {
this.showInterstitialAd();
}
},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {
this.setData({
options
})
wx.aldstat.sendEvent('进入页面', {
'页面名字': '首页'
});
this.queryAdConfigure().then((result) => {
this.initData();
this.addInterstitialAd();
if (app.globalData.adConfigure && app.globalData.adConfigure.ad_config_02 == 1) {
this.showInterstitialAd();
}
if (app.globalData.adConfigure && app.globalData.adConfigure.ad_config_01 == 1) {
this.addInterstitialAd();
}
});
},
addInterstitialAd() {
if (wx.createInterstitialAd) {
interstitialAd = wx.createInterstitialAd({
adUnitId: 'adunit-1ffb5a60bc3f7f55'
})
interstitialAd.onLoad(() => {})
interstitialAd.onError((err) => {})
interstitialAd.onClose(() => {})
}
},
showInterstitialAd() {
if (interstitialAd) {
interstitialAd.show().catch((err) => {
console.error(err)
})
}
},
initData() {
this.queryAdConfigure().then((result) => {
this.queryTabList().then((result) => {
let {
options,
tabList
} = this.data;
if (options.t == "bless") {
let tabIndex = 0;
tabList.forEach((element, idx) => {
if (element.type == 2) {
tabIndex = idx;
}
});
this.setData({
curTab: tabList[tabIndex],
active: tabIndex
})
} else {
this.setData({
curTab: tabList[0]
})
}
this.resetPage();
this.queryBannerList();
this.queryVideoList();
});
});
},
/**
* 到达底部
* 做加载更多操作
*/
onReachBottom() {
if (this.data.dataList.length < this.data.total) {
this.setData({
page: this.data.page + 1
});
this.queryVideoList();
}
},
// 重置页面列表 点击搜索条件时需要
resetPage() {
this.setData({
page: 1,
dataList: [],
queueCode: "",
})
},
// 点击tabs
onVanTabsHandler(event) {
let {
index,
title
} = event.detail;
if (this.data.tabList && this.data.tabList.length > 0) {
this.setData({
curTab: this.data.tabList[event.detail.index]
})
this.resetPage();
this.queryBannerList();
this.queryVideoList();
}
},
/**
* 点击禁用的tab
*/
onClickDisabled(event) {
this.openBlessWxApp();
},
// 打开微信小程序app
openBlessWxApp() {
wx.navigateToMiniProgram({
appId: "wx00d6285885e17324", // 要跳转的小程序的appid
path: "pages/index/index?t=bless", // 跳转的目标页面
extarData: {
open: ''
},
success(res) {
// 打开成功
},
fail(err) {
}
})
},
/**
* banner切换
*/
onBannerChangeHandler(e) {
let index = e.detail.current;
this.setBannerIndex(index);
},
setBannerIndex(idx) {
let bannerList = this.data.bannerList;
if (bannerList && bannerList.length > 0) {
let curBanner = bannerList[idx] || {}
this.setData({
curBanner: curBanner
})
}
},
/**
* 点击item详情
* @param {*} evt
*/
onDetailHandler(evt) {
let curItem = getBindtapData(evt);
let listType = this.data.listType;
if (listType == 2) {
let blessCode = curItem.blessCode || "";
if (blessCode) {
app.router.push({
path: "blessing",
query: {
c: blessCode
}
})
}
} else {
let videoCode = curItem.videoCode || "";
if (videoCode) {
app.router.push({
path: "detail",
query: {
c: videoCode
}
})
}
}
},
/**
* 点击banner详情
* @param {*} evt
*/
onBannerHandler(evt) {
let curItem = getBindtapData(evt);
console.log("curItem:", curItem);
let {
bannerCode,
bannerType,
videoCode,
bigImage,
gzhArticle
} = curItem;
// 打点
app.stat({
classify: "banner",
action: "banner_click",
primaryCode: bannerCode,
});
switch (bannerType) {
case "video":
if (videoCode) {
app.router.push({
path: "detail",
query: {
c: videoCode
}
})
}
break;
case "image":
if (bigImage) {
let current = bigImage;
let urls = [bigImage];
wx.previewImage({
current: current,
urls: urls
})
}
break;
case "article":
if (gzhArticle) {
app.router.push({
path: "webview",
query: {
url: gzhArticle,
}
})
}
break;
default:
break;
}
},
onShareItem(evt) {
let curItem = getBindtapData(evt);
app.stat({
classify: "share",
action: "list_page_button_share",
primaryCode: curItem.videoCode
});
},
/**
* 到个人列表页面
*/
toPersonalList(evt) {
let detailData = getBindtapData(evt);
if (detailData && detailData.accountCode) {
detailData.c = detailData.accountCode;
app.router.push({
path: "personalList",
query: detailData
})
}
},
/**广告配置 */
queryAdConfigure() {
return new Promise((resolve, reject) => {
app.post({
sid: false,
url: app.api.adConfigure,
data: {}
}).then((result) => {
this.setData({
adConfigure: result
})
app.globalData.adConfigure = result;
resolve(result);
}).catch((err) => {
reject(err)
});
});
},
/**
* 获取tab列表
*/
queryTabList() {
return new Promise((resolve, reject) => {
app.post({
sid: false,
url: app.api.tabList,
data: {}
}).then((result) => {
// result.push({
// type: 2,
// tabName:"组团拜年"
// })
this.setData({
tabList: result
})
resolve(result);
}).catch((err) => {
reject(err)
});
});
},
/**
* 获取banner列表
*/
queryBannerList() {
return new Promise((resolve, reject) => {
app.post({
sid: false,
url: app.api.bannerList,
data: {
tabCode: this.data.curTab.tabCode || "",
}
}).then((result) => {
this.setData({
bannerList: result
})
this.setBannerIndex(0);
resolve(result);
}).catch((err) => {
reject(err)
});
});
},
/**
* 获取视频列表
*/
queryVideoList() {
return new Promise((resolve, reject) => {
app.post({
sid: false,
url: app.api.videoList,
data: {
page: this.data.page,
size: this.data.size,
queueCode: this.data.queueCode,
tabCode: this.data.curTab.tabCode || "",
}
}).then((result) => {
let {
adConfigure,
} = this.data;
let listType = result.type;
let dataList = result.list;
dataList = this.data.dataList.concat(dataList);
// 带广告的格式
let dataListResult = [];
// 广告步进
let adStep = adConfigure.configureM || 0;
// 视频广告第一次出现条目
let firstAdIndex = adConfigure.configureX || 0;
// 视频广告第一条是否已经出现
let isFirstAdshow = false;
// 祝福广告第一次出现条目
let firstAdIndexBless = adConfigure.configureB || 0;
// 祝福广告第一条是否已经出现
let isFirstAdBlessShow = false;
// console.log("firstAdIndexBless:", firstAdIndexBless);
// 广告步数
let adStepIndex = 0;
// 洗列表格式
dataList.forEach((element, idx) => {
if (listType == 2) {
// 拜年祝福
if (isFirstAdBlessShow) {
} else {
if (adStepIndex == firstAdIndexBless && firstAdIndexBless > 0) {
isFirstAdBlessShow = true;
adStepIndex = 0;
dataListResult.push({
type: "ad",
adType: "banner"
})
}
}
} else {
// 视频祝福
if (isFirstAdshow) {
// 第一个视频出现过
if (adStepIndex > adStep && adStep != 0) {
adStepIndex = 0;
dataListResult.push({
type: "ad",
adType: "banner"
})
}
} else {
// 第一个视频出现
if (adStepIndex == firstAdIndex && firstAdIndex > 0) {
isFirstAdshow = true;
adStepIndex = 0;
dataListResult.push({
type: "ad",
adType: "video"
})
}
}
}
adStepIndex++;
dataListResult.push(element);
// console.log("dataListResult:", dataListResult);
});
this.setData({
dataList: dataList,
dataListResult: dataListResult,
total: result.total,
queueCode: result.queueCode,
listType: result.type
})
resolve(result);
}).catch((err) => {
reject(err)
});
});
},
/**
* 隐藏蒙层
*/
hideMask() {
this.setData({
productDetailVisible: false,
authorizeVisible: false,
})
},
/**
* 子组件事件
* @param {*} evt
*/
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
// 隐藏蒙层
case "_evt_hide_mask":
this.hideMask();
break;
/**
* 重拉数据已在
*/
case "_evt_auth_complete":
// this.initData();
this.hideMask();
break;
default:
break;
}
},
})