@dcloudio/uni-stat 0.0.1-nvue3.3030820220125001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,949 @@
1
+ var version = "0.0.1-nvue3.3030820220125001";
2
+
3
+ const STAT_VERSION = version;
4
+ const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
5
+ const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
6
+ const PAGE_PVER_TIME = 1800;
7
+ const APP_PVER_TIME = 300;
8
+ const OPERATING_TIME = 10;
9
+ const DIFF_TIME = 60 * 1000 * 60 * 24;
10
+
11
+ const statConfig$1 = {
12
+ appid: process.env.UNI_APP_ID,
13
+ };
14
+ const UUID_KEY = '__DC_STAT_UUID';
15
+ const UUID_VALUE = '__DC_UUID_VALUE';
16
+
17
+ function getUuid() {
18
+ let uuid = '';
19
+ if (getPlatformName() === 'n') {
20
+ try {
21
+ uuid = plus.runtime.getDCloudId();
22
+ } catch (e) {
23
+ uuid = '';
24
+ }
25
+ return uuid
26
+ }
27
+
28
+ try {
29
+ uuid = uni.getStorageSync(UUID_KEY);
30
+ } catch (e) {
31
+ uuid = UUID_VALUE;
32
+ }
33
+
34
+ if (!uuid) {
35
+ uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
36
+ try {
37
+ uni.setStorageSync(UUID_KEY, uuid);
38
+ } catch (e) {
39
+ uni.setStorageSync(UUID_KEY, UUID_VALUE);
40
+ }
41
+ }
42
+ return uuid
43
+ }
44
+
45
+ const getSgin = (statData) => {
46
+ let arr = Object.keys(statData);
47
+ let sortArr = arr.sort();
48
+ let sgin = {};
49
+ let sginStr = '';
50
+ for (var i in sortArr) {
51
+ sgin[sortArr[i]] = statData[sortArr[i]];
52
+ sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&';
53
+ }
54
+ // const options = sginStr.substr(0, sginStr.length - 1)
55
+ // sginStr = sginStr.substr(0, sginStr.length - 1) + '&key=' + STAT_KEY;
56
+ // const si = crypto.createHash('md5').update(sginStr).digest('hex');
57
+ return {
58
+ sign: '',
59
+ options: sginStr.substr(0, sginStr.length - 1),
60
+ }
61
+ };
62
+
63
+ const getSplicing = (data) => {
64
+ let str = '';
65
+ for (var i in data) {
66
+ str += i + '=' + data[i] + '&';
67
+ }
68
+ return str.substr(0, str.length - 1)
69
+ };
70
+
71
+ const getTime = () => {
72
+ return parseInt(new Date().getTime() / 1000)
73
+ };
74
+
75
+ const getPlatformName = () => {
76
+ const aliArr = ['y', 'a', 'p', 'mp-ali'];
77
+ const platformList = {
78
+ 'app-plus': 'n',
79
+ h5: 'h5',
80
+ 'mp-weixin': 'wx',
81
+ [aliArr.reverse().join('')]: 'ali',
82
+ 'mp-baidu': 'bd',
83
+ 'mp-toutiao': 'tt',
84
+ 'mp-qq': 'qq',
85
+ 'quickapp-native': 'qn',
86
+ 'mp-kuaishou': 'ks',
87
+ };
88
+ return platformList[process.env.VUE_APP_PLATFORM]
89
+ };
90
+
91
+ const getPackName = () => {
92
+ let packName = '';
93
+ if (getPlatformName() === 'wx' || getPlatformName() === 'qq') {
94
+ // 兼容微信小程序低版本基础库
95
+ if (uni.canIUse('getAccountInfoSync')) {
96
+ packName = uni.getAccountInfoSync().miniProgram.appId || '';
97
+ }
98
+ }
99
+ return packName
100
+ };
101
+
102
+ const getVersion = () => {
103
+ return getPlatformName() === 'n' ? plus.runtime.version : ''
104
+ };
105
+
106
+ const getChannel = () => {
107
+ const platformName = getPlatformName();
108
+ let channel = '';
109
+ if (platformName === 'n') {
110
+ channel = plus.runtime.channel;
111
+ }
112
+ return channel
113
+ };
114
+
115
+ const getScene = (options) => {
116
+ const platformName = getPlatformName();
117
+ let scene = '';
118
+ if (options) {
119
+ return options
120
+ }
121
+ if (platformName === 'wx') {
122
+ scene = uni.getLaunchOptionsSync().scene;
123
+ }
124
+ return scene
125
+ };
126
+ const First__Visit__Time__KEY = 'First__Visit__Time';
127
+ const Last__Visit__Time__KEY = 'Last__Visit__Time';
128
+
129
+ const getFirstVisitTime = () => {
130
+ const timeStorge = uni.getStorageSync(First__Visit__Time__KEY);
131
+ let time = 0;
132
+ if (timeStorge) {
133
+ time = timeStorge;
134
+ } else {
135
+ time = getTime();
136
+ uni.setStorageSync(First__Visit__Time__KEY, time);
137
+ uni.removeStorageSync(Last__Visit__Time__KEY);
138
+ }
139
+ return time
140
+ };
141
+
142
+ const getLastVisitTime = () => {
143
+ const timeStorge = uni.getStorageSync(Last__Visit__Time__KEY);
144
+ let time = 0;
145
+ if (timeStorge) {
146
+ time = timeStorge;
147
+ } else {
148
+ time = '';
149
+ }
150
+ uni.setStorageSync(Last__Visit__Time__KEY, getTime());
151
+ return time
152
+ };
153
+
154
+ const PAGE_RESIDENCE_TIME = '__page__residence__time';
155
+ let First_Page_residence_time = 0;
156
+ let Last_Page_residence_time = 0;
157
+
158
+ const setPageResidenceTime = () => {
159
+ First_Page_residence_time = getTime();
160
+ if (getPlatformName() === 'n') {
161
+ uni.setStorageSync(PAGE_RESIDENCE_TIME, getTime());
162
+ }
163
+ return First_Page_residence_time
164
+ };
165
+
166
+ const getPageResidenceTime = () => {
167
+ Last_Page_residence_time = getTime();
168
+ if (getPlatformName() === 'n') {
169
+ First_Page_residence_time = uni.getStorageSync(PAGE_RESIDENCE_TIME);
170
+ }
171
+ return Last_Page_residence_time - First_Page_residence_time
172
+ };
173
+ const TOTAL__VISIT__COUNT = 'Total__Visit__Count';
174
+ const getTotalVisitCount = () => {
175
+ const timeStorge = uni.getStorageSync(TOTAL__VISIT__COUNT);
176
+ let count = 1;
177
+ if (timeStorge) {
178
+ count = timeStorge;
179
+ count++;
180
+ }
181
+ uni.setStorageSync(TOTAL__VISIT__COUNT, count);
182
+ return count
183
+ };
184
+
185
+ const GetEncodeURIComponentOptions = (statData) => {
186
+ let data = {};
187
+ for (let prop in statData) {
188
+ data[prop] = encodeURIComponent(statData[prop]);
189
+ }
190
+ return data
191
+ };
192
+
193
+ let Set__First__Time = 0;
194
+ let Set__Last__Time = 0;
195
+
196
+ const getFirstTime = () => {
197
+ let time = new Date().getTime();
198
+ Set__First__Time = time;
199
+ Set__Last__Time = 0;
200
+ return time
201
+ };
202
+
203
+ const getLastTime = () => {
204
+ let time = new Date().getTime();
205
+ Set__Last__Time = time;
206
+ return time
207
+ };
208
+
209
+ const getResidenceTime = (type) => {
210
+ let residenceTime = 0;
211
+ if (Set__First__Time !== 0) {
212
+ residenceTime = Set__Last__Time - Set__First__Time;
213
+ }
214
+
215
+ residenceTime = parseInt(residenceTime / 1000);
216
+ residenceTime = residenceTime < 1 ? 1 : residenceTime;
217
+ if (type === 'app') {
218
+ let overtime = residenceTime > APP_PVER_TIME ? true : false;
219
+ return {
220
+ residenceTime,
221
+ overtime,
222
+ }
223
+ }
224
+ if (type === 'page') {
225
+ let overtime = residenceTime > PAGE_PVER_TIME ? true : false;
226
+ return {
227
+ residenceTime,
228
+ overtime,
229
+ }
230
+ }
231
+
232
+ return {
233
+ residenceTime,
234
+ }
235
+ };
236
+
237
+ const getRoute = () => {
238
+ var pages = getCurrentPages();
239
+ var page = pages[pages.length - 1];
240
+ if (!page) return ''
241
+ // TODO 需要确认如果不用 $vm ,其他平台会不会出错
242
+ let _self = page.$vm;
243
+
244
+ if (getPlatformName() === 'bd') {
245
+ return _self.$mp && _self.$mp.page.is
246
+ } else {
247
+ return _self.route || (_self.$scope && _self.$scope.route)
248
+ }
249
+ };
250
+
251
+ const getPageRoute = (_this) => {
252
+ let pageVm = _this.self;
253
+ let page = pageVm.$page || pageVm.$scope.$page;
254
+ return page.fullPath === '/' ? page.route : page.fullPath
255
+ };
256
+
257
+ const getPageTypes = (self) => {
258
+ if (
259
+ self.$mpType === 'page' ||
260
+ (self.$mp && self.$mp.mpType === 'page') ||
261
+ self.$options.mpType === 'page'
262
+ ) {
263
+ return true
264
+ }
265
+ return false
266
+ };
267
+
268
+ const calibration = (eventName, options) => {
269
+ // login 、 share 、pay_success 、pay_fail 、register 、title
270
+ if (!eventName) {
271
+ console.error(`uni.report 缺少 [eventName] 参数`);
272
+ return true
273
+ }
274
+ if (typeof eventName !== 'string') {
275
+ console.error(`uni.report [eventName] 参数类型错误,只能为 String 类型`);
276
+ return true
277
+ }
278
+ if (eventName.length > 255) {
279
+ console.error(`uni.report [eventName] 参数长度不能大于 255`);
280
+ return true
281
+ }
282
+
283
+ if (typeof options !== 'string' && typeof options !== 'object') {
284
+ console.error(
285
+ `uni.report [options] 参数类型错误,只能为 String 或 Object 类型`
286
+ );
287
+ return true
288
+ }
289
+
290
+ if (typeof options === 'string' && options.length > 255) {
291
+ console.error(`uni.report [options] 参数长度不能大于 255`);
292
+ return true
293
+ }
294
+
295
+ if (eventName === 'title' && typeof options !== 'string') {
296
+ console.error(
297
+ 'uni.report [eventName] 参数为 title 时,[options] 参数只能为 String 类型'
298
+ );
299
+ return true
300
+ }
301
+ };
302
+
303
+ const Report_Data_Time = 'Report_Data_Time';
304
+ const Report_Status = 'Report_Status';
305
+ const isReportData = () => {
306
+ return new Promise((resolve, reject) => {
307
+ let start_time = '';
308
+ let end_time = new Date().getTime();
309
+ let diff_time = DIFF_TIME;
310
+ let report_status = 1;
311
+ try {
312
+ start_time = uni.getStorageSync(Report_Data_Time);
313
+ report_status = uni.getStorageSync(Report_Status);
314
+ } catch (e) {
315
+ start_time = '';
316
+ report_status = 1;
317
+ }
318
+
319
+ if (report_status === '') {
320
+ requestData(({ enable }) => {
321
+ uni.setStorageSync(Report_Data_Time, end_time);
322
+ uni.setStorageSync(Report_Status, enable);
323
+ if (enable === 1) {
324
+ resolve();
325
+ }
326
+ });
327
+ return
328
+ }
329
+
330
+ if (report_status === 1) {
331
+ resolve();
332
+ }
333
+
334
+ if (!start_time) {
335
+ uni.setStorageSync(Report_Data_Time, end_time);
336
+ start_time = end_time;
337
+ }
338
+
339
+ if (end_time - start_time > diff_time) {
340
+ requestData(({ enable }) => {
341
+ uni.setStorageSync(Report_Data_Time, end_time);
342
+ uni.setStorageSync(Report_Status, enable);
343
+ });
344
+ }
345
+ })
346
+ };
347
+
348
+ const requestData = (done) => {
349
+ let formData = {
350
+ usv: STAT_VERSION,
351
+ conf: JSON.stringify({
352
+ ak: statConfig$1.appid,
353
+ }),
354
+ };
355
+ uni.request({
356
+ url: STAT_URL,
357
+ method: 'GET',
358
+ data: formData,
359
+ success: (res) => {
360
+ const { data } = res;
361
+ if (data.ret === 0) {
362
+ typeof done === 'function' &&
363
+ done({
364
+ enable: data.enable,
365
+ });
366
+ }
367
+ },
368
+ fail: (e) => {
369
+ let report_status_code = 1;
370
+ try {
371
+ report_status_code = uni.getStorageSync(Report_Status);
372
+ } catch (e) {
373
+ report_status_code = 1;
374
+ }
375
+ if (report_status_code === '') {
376
+ report_status_code = 1;
377
+ }
378
+ typeof done === 'function' &&
379
+ done({
380
+ enable: report_status_code,
381
+ });
382
+ },
383
+ });
384
+ };
385
+
386
+ const titleJsons = process.env.UNI_STAT_TITLE_JSON;
387
+
388
+ const statConfig = {
389
+ appid: process.env.UNI_APP_ID,
390
+ };
391
+ const resultOptions = uni.getSystemInfoSync();
392
+
393
+ class Util {
394
+ constructor() {
395
+ this.self = '';
396
+ this._retry = 0;
397
+ this._platform = '';
398
+ this._query = {};
399
+ this._navigationBarTitle = {
400
+ config: '',
401
+ page: '',
402
+ report: '',
403
+ lt: '',
404
+ };
405
+ this._operatingTime = 0;
406
+ this._reportingRequestData = {
407
+ 1: [],
408
+ 11: [],
409
+ };
410
+ this.__prevent_triggering = false;
411
+
412
+ this.__licationHide = false;
413
+ this.__licationShow = false;
414
+ this._lastPageRoute = '';
415
+ this.statData = {
416
+ uuid: getUuid(),
417
+ ut: getPlatformName(),
418
+ mpn: getPackName(),
419
+ ak: statConfig.appid,
420
+ usv: STAT_VERSION,
421
+ v: getVersion(),
422
+ ch: getChannel(),
423
+ cn: '',
424
+ pn: '',
425
+ ct: '',
426
+ t: getTime(),
427
+ tt: '',
428
+ p: resultOptions.platform === 'android' ? 'a' : 'i',
429
+ brand: resultOptions.brand || '',
430
+ md: resultOptions.model,
431
+ sv: resultOptions.system.replace(/(Android|iOS)\s/, ''),
432
+ mpsdk: resultOptions.SDKVersion || '',
433
+ mpv: resultOptions.version || '',
434
+ lang: resultOptions.language,
435
+ pr: resultOptions.pixelRatio,
436
+ ww: resultOptions.windowWidth,
437
+ wh: resultOptions.windowHeight,
438
+ sw: resultOptions.screenWidth,
439
+ sh: resultOptions.screenHeight,
440
+ };
441
+ // 注册拦截器
442
+ let registerInterceptor =
443
+ typeof uni.addInterceptor === 'function' &&
444
+ process.env.NODE_ENV !== 'development';
445
+ if (registerInterceptor) {
446
+ this.addInterceptorInit();
447
+ this.interceptLogin();
448
+ this.interceptShare(true);
449
+ this.interceptRequestPayment();
450
+ }
451
+ }
452
+
453
+ addInterceptorInit() {
454
+ let self = this;
455
+ uni.addInterceptor('setNavigationBarTitle', {
456
+ invoke(args) {
457
+ self._navigationBarTitle.page = args.title;
458
+ },
459
+ });
460
+ }
461
+
462
+ interceptLogin() {
463
+ let self = this;
464
+ uni.addInterceptor('login', {
465
+ complete() {
466
+ self._login();
467
+ },
468
+ });
469
+ }
470
+
471
+ interceptShare(type) {
472
+ let self = this;
473
+ if (!type) {
474
+ self._share();
475
+ return
476
+ }
477
+ uni.addInterceptor('share', {
478
+ success() {
479
+ self._share();
480
+ },
481
+ fail() {
482
+ self._share();
483
+ },
484
+ });
485
+ }
486
+
487
+ interceptRequestPayment() {
488
+ let self = this;
489
+ uni.addInterceptor('requestPayment', {
490
+ success() {
491
+ self._payment('pay_success');
492
+ },
493
+ fail() {
494
+ self._payment('pay_fail');
495
+ },
496
+ });
497
+ }
498
+
499
+ getIsReportData() {
500
+ return isReportData()
501
+ }
502
+
503
+ _applicationShow() {
504
+ if (this.__licationHide) {
505
+ getLastTime();
506
+ const time = getResidenceTime('app');
507
+ if (time.overtime) {
508
+ let options = {
509
+ path: this._lastPageRoute,
510
+ scene: this.statData.sc,
511
+ };
512
+ this._sendReportRequest(options);
513
+ }
514
+ this.__licationHide = false;
515
+ }
516
+ }
517
+
518
+ _applicationHide(self, type) {
519
+ this.__licationHide = true;
520
+ getLastTime();
521
+ const time = getResidenceTime();
522
+ getFirstTime();
523
+ const route = getPageRoute(this);
524
+ this._sendHideRequest(
525
+ {
526
+ urlref: route,
527
+ urlref_ts: time.residenceTime,
528
+ },
529
+ type
530
+ );
531
+ }
532
+
533
+ _pageShow() {
534
+ const route = getPageRoute(this);
535
+ const routepath = getRoute();
536
+ this._navigationBarTitle.config =
537
+ (titleJsons && titleJsons[routepath]) || '';
538
+ if (this.__licationShow) {
539
+ getFirstTime();
540
+ this.__licationShow = false;
541
+ this._lastPageRoute = route;
542
+ return
543
+ }
544
+
545
+ getLastTime();
546
+ const time = getResidenceTime('page');
547
+ // 停留时间
548
+ if (time.overtime) {
549
+ let options = {
550
+ path: route,
551
+ scene: this.statData.sc,
552
+ };
553
+ this._sendReportRequest(options);
554
+ }
555
+ getFirstTime();
556
+ }
557
+
558
+ _pageHide() {
559
+ if (!this.__licationHide) {
560
+ getLastTime();
561
+ const time = getResidenceTime('page');
562
+ let route = getPageRoute(this);
563
+ if (!this._lastPageRoute) {
564
+ this._lastPageRoute = route;
565
+ }
566
+ this._sendPageRequest({
567
+ url: route,
568
+ urlref: this._lastPageRoute,
569
+ urlref_ts: time.residenceTime,
570
+ });
571
+ this._lastPageRoute = route;
572
+ this._navigationBarTitle = {
573
+ config: '',
574
+ page: '',
575
+ report: '',
576
+ lt: '',
577
+ };
578
+ return
579
+ }
580
+ }
581
+
582
+ _login() {
583
+ this._sendEventRequest(
584
+ {
585
+ key: 'login',
586
+ },
587
+ 0
588
+ );
589
+ }
590
+
591
+ _share() {
592
+ this._sendEventRequest(
593
+ {
594
+ key: 'share',
595
+ },
596
+ 0
597
+ );
598
+ }
599
+ _payment(key) {
600
+ this._sendEventRequest(
601
+ {
602
+ key,
603
+ },
604
+ 0
605
+ );
606
+ }
607
+ _sendReportRequest(options) {
608
+ this._navigationBarTitle.lt = '1';
609
+ this._navigationBarTitle.config =
610
+ (titleJsons && titleJsons[options.path]) || '';
611
+ let query =
612
+ options.query && JSON.stringify(options.query) !== '{}'
613
+ ? '?' + JSON.stringify(options.query)
614
+ : '';
615
+ this.statData.lt = '1';
616
+ this.statData.url = options.path + query || '';
617
+ this.statData.t = getTime();
618
+ this.statData.sc = getScene(options.scene);
619
+ this.statData.fvts = getFirstVisitTime();
620
+ this.statData.lvts = getLastVisitTime();
621
+ this.statData.tvc = getTotalVisitCount();
622
+ if (getPlatformName() === 'n') {
623
+ this.getProperty();
624
+ } else {
625
+ this.getNetworkInfo();
626
+ }
627
+ }
628
+
629
+ _sendPageRequest(opt) {
630
+ let { url, urlref, urlref_ts } = opt;
631
+ this._navigationBarTitle.lt = '11';
632
+ let options = {
633
+ ak: this.statData.ak,
634
+ uuid: this.statData.uuid,
635
+ lt: '11',
636
+ ut: this.statData.ut,
637
+ url,
638
+ tt: this.statData.tt,
639
+ urlref,
640
+ urlref_ts,
641
+ ch: this.statData.ch,
642
+ usv: this.statData.usv,
643
+ t: getTime(),
644
+ p: this.statData.p,
645
+ };
646
+ this.request(options);
647
+ }
648
+
649
+ _sendHideRequest(opt, type) {
650
+ let { urlref, urlref_ts } = opt;
651
+ let options = {
652
+ ak: this.statData.ak,
653
+ uuid: this.statData.uuid,
654
+ lt: '3',
655
+ ut: this.statData.ut,
656
+ urlref,
657
+ urlref_ts,
658
+ ch: this.statData.ch,
659
+ usv: this.statData.usv,
660
+ t: getTime(),
661
+ p: this.statData.p,
662
+ };
663
+ this.request(options, type);
664
+ }
665
+ _sendEventRequest({ key = '', value = '' } = {}) {
666
+ const route = this._lastPageRoute;
667
+ let options = {
668
+ ak: this.statData.ak,
669
+ uuid: this.statData.uuid,
670
+ lt: '21',
671
+ ut: this.statData.ut,
672
+ url: route,
673
+ ch: this.statData.ch,
674
+ e_n: key,
675
+ e_v: typeof value === 'object' ? JSON.stringify(value) : value.toString(),
676
+ usv: this.statData.usv,
677
+ t: getTime(),
678
+ p: this.statData.p,
679
+ };
680
+ this.request(options);
681
+ }
682
+
683
+ getNetworkInfo() {
684
+ uni.getNetworkType({
685
+ success: (result) => {
686
+ this.statData.net = result.networkType;
687
+ this.getLocation();
688
+ },
689
+ });
690
+ }
691
+
692
+ getProperty() {
693
+ plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
694
+ this.statData.v = wgtinfo.version || '';
695
+ this.getNetworkInfo();
696
+ });
697
+ }
698
+
699
+ getLocation() {
700
+ {
701
+ this.statData.lat = 0;
702
+ this.statData.lng = 0;
703
+ this.request(this.statData);
704
+ }
705
+ }
706
+
707
+ request(data, type) {
708
+ let time = getTime();
709
+ const title = this._navigationBarTitle;
710
+ data.ttn = title.page;
711
+ data.ttpj = title.config;
712
+ data.ttc = title.report;
713
+ let requestData = this._reportingRequestData;
714
+ if (getPlatformName() === 'n') {
715
+ requestData = uni.getStorageSync('__UNI__STAT__DATA') || {};
716
+ }
717
+ if (!requestData[data.lt]) {
718
+ requestData[data.lt] = [];
719
+ }
720
+ requestData[data.lt].push(data);
721
+ if (getPlatformName() === 'n') {
722
+ uni.setStorageSync('__UNI__STAT__DATA', requestData);
723
+ }
724
+ if (getPageResidenceTime() < OPERATING_TIME && !type) {
725
+ return
726
+ }
727
+ let uniStatData = this._reportingRequestData;
728
+ if (getPlatformName() === 'n') {
729
+ uniStatData = uni.getStorageSync('__UNI__STAT__DATA');
730
+ }
731
+ // 时间超过,重新获取时间戳
732
+ setPageResidenceTime();
733
+ let firstArr = [];
734
+ let contentArr = [];
735
+ let lastArr = [];
736
+
737
+ for (let i in uniStatData) {
738
+ const rd = uniStatData[i];
739
+ rd.forEach((elm) => {
740
+ const newData = getSplicing(elm);
741
+ if (i === 0) {
742
+ firstArr.push(newData);
743
+ } else if (i === 3) {
744
+ lastArr.push(newData);
745
+ } else {
746
+ contentArr.push(newData);
747
+ }
748
+ });
749
+ }
750
+
751
+ firstArr.push(...contentArr, ...lastArr);
752
+ let optionsData = {
753
+ usv: STAT_VERSION, //统计 SDK 版本号
754
+ t: time, //发送请求时的时间戮
755
+ requests: JSON.stringify(firstArr),
756
+ };
757
+
758
+ this._reportingRequestData = {};
759
+ if (getPlatformName() === 'n') {
760
+ uni.removeStorageSync('__UNI__STAT__DATA');
761
+ }
762
+
763
+ if (data.ut === 'h5') {
764
+ this.imageRequest(optionsData);
765
+ return
766
+ }
767
+
768
+ if (getPlatformName() === 'n' && this.statData.p === 'a') {
769
+ setTimeout(() => {
770
+ this._sendRequest(optionsData);
771
+ }, 200);
772
+ return
773
+ }
774
+ this._sendRequest(optionsData);
775
+ }
776
+ _sendRequest(optionsData) {
777
+ this.getIsReportData().then(() => {
778
+ uni.request({
779
+ url: STAT_URL,
780
+ method: 'POST',
781
+ data: optionsData,
782
+ success: () => {},
783
+ fail: (e) => {
784
+ if (++this._retry < 3) {
785
+ setTimeout(() => {
786
+ this._sendRequest(optionsData);
787
+ }, 1000);
788
+ }
789
+ },
790
+ });
791
+ });
792
+ }
793
+ /**
794
+ * h5 请求
795
+ */
796
+ imageRequest(data) {
797
+ this.getIsReportData().then(() => {
798
+ let image = new Image();
799
+ let options = getSgin(GetEncodeURIComponentOptions(data)).options;
800
+ image.src = STAT_H5_URL + '?' + options;
801
+ });
802
+ }
803
+
804
+ sendEvent(key, value) {
805
+ // 校验 type 参数
806
+ if (calibration(key, value)) return
807
+
808
+ if (key === 'title') {
809
+ this._navigationBarTitle.report = value;
810
+ return
811
+ }
812
+ this._sendEventRequest(
813
+ {
814
+ key,
815
+ value: typeof value === 'object' ? JSON.stringify(value) : value,
816
+ },
817
+ 1
818
+ );
819
+ }
820
+ }
821
+
822
+ class Stat extends Util {
823
+ static getInstance() {
824
+ if (!this.instance) {
825
+ this.instance = new Stat();
826
+ }
827
+ return this.instance
828
+ }
829
+ constructor() {
830
+ super();
831
+ this.instance = null;
832
+ }
833
+
834
+ report(options, self) {
835
+ // TODO 需要确认如果不用 $vm ,其他平台会不会出错
836
+ setPageResidenceTime();
837
+ this.__licationShow = true;
838
+ this._sendReportRequest(options, true);
839
+ }
840
+
841
+ load(options, self) {
842
+ this.self = self;
843
+ this._query = options;
844
+ }
845
+
846
+ show(self) {
847
+ this.self = self;
848
+ if (getPageTypes(self)) {
849
+ this._pageShow(self);
850
+ } else {
851
+ this._applicationShow(self);
852
+ }
853
+ }
854
+ ready(self) {}
855
+ hide(self) {
856
+ this.self = self;
857
+ if (getPageTypes(self)) {
858
+ this._pageHide(self);
859
+ } else {
860
+ this._applicationHide(self, true);
861
+ }
862
+ }
863
+ error(em) {
864
+ if (this._platform === 'devtools') {
865
+ if (process.env.NODE_ENV === 'development') {
866
+ console.info('当前运行环境为开发者工具,不上报数据。');
867
+ }
868
+ }
869
+ let emVal = '';
870
+ if (!em.message) {
871
+ emVal = JSON.stringify(em);
872
+ } else {
873
+ emVal = em.stack;
874
+ }
875
+ let options = {
876
+ ak: this.statData.ak,
877
+ uuid: this.statData.uuid,
878
+ lt: '31',
879
+ ut: this.statData.ut,
880
+ ch: this.statData.ch,
881
+ mpsdk: this.statData.mpsdk,
882
+ mpv: this.statData.mpv,
883
+ v: this.statData.v,
884
+ em: emVal,
885
+ usv: this.statData.usv,
886
+ t: getTime(),
887
+ p: this.statData.p,
888
+ };
889
+ this.request(options);
890
+ }
891
+ }
892
+ var Stat$1 = Stat;
893
+
894
+ const stat = Stat$1.getInstance();
895
+ let isHide = false;
896
+ const lifecycle = {
897
+ onLaunch(options) {
898
+ stat.report(options, this);
899
+ },
900
+ onReady() {
901
+ stat.ready(this);
902
+ },
903
+ onLoad(options) {
904
+ stat.load(options, this);
905
+ // 重写分享,获取分享上报事件
906
+ if (this.$scope && this.$scope.onShareAppMessage) {
907
+ let oldShareAppMessage = this.$scope.onShareAppMessage;
908
+ this.$scope.onShareAppMessage = function (options) {
909
+ stat.interceptShare(false);
910
+ return oldShareAppMessage.call(this, options)
911
+ };
912
+ }
913
+ },
914
+ onShow() {
915
+ isHide = false;
916
+ stat.show(this);
917
+ },
918
+ onHide() {
919
+ isHide = true;
920
+ stat.hide(this);
921
+ },
922
+ onUnload() {
923
+ if (isHide) {
924
+ isHide = false;
925
+ return
926
+ }
927
+ stat.hide(this);
928
+ },
929
+ onError(e) {
930
+ stat.error(e);
931
+ },
932
+ };
933
+
934
+ function main() {
935
+ if (process.env.NODE_ENV === 'development') {
936
+ uni.report = function (type, options) {};
937
+ } else {
938
+ uni.onAppLaunch((options) => {
939
+ stat.report(options);
940
+ // 小程序平台此时也无法获取getApp,统一在options中传递一个app mixin对象
941
+ options.app.mixin(lifecycle);
942
+ uni.report = function (type, options) {
943
+ stat.sendEvent(type, options);
944
+ };
945
+ });
946
+ }
947
+ }
948
+
949
+ main();