init-client.js
2.35 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
import Vue from 'vue';
import cookie from 'yoho-cookie';
import xianyu from '../common/xianyu';
import './yas/ya';
import reportError from 'report-error';
const setWindowSize = (store) => {
const { clientWidth, clientHeight } = document.body;
store.commit('SET_WINDOW_SIZE', { clientWidth, clientHeight });
};
const initClient = (store) => {
setWindowSize(store);
window.onresize = () => {
setWindowSize(store);
};
let supportsPassive = false;
try {
const opts = Object.defineProperty({}, 'passive', {
get() {
supportsPassive = true;
return true;
}
});
window.addEventListener('test', null, opts);
} catch (e) { } //eslint-disable-line
store.commit('SET_SUPPORT_PASSIVE', { supportsPassive });
let img = new Image();
img.onload = () => {
if (img.width > 0 && img.height > 0) {
store.commit('SET_SUPPORT_WEBP', { supportWebp: true });
}
};
img.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
};
function getUdid() {
return cookie.get('udid') || '';
}
function getUid() {
return (cookie.get('_UID') || '').split('::')[1] || '';
}
window.indx = 1;
function initBaseLogs() {
if (!(window._yas && window._yas.sendAppLogs)) {
reportError({ tp: 'yas_err' });
(function(w, d, s, j, f) {
var a = d.createElement(s);
var m = d.getElementsByTagName(s)[0];
w.YohoAcquisitionObject = f;
w[f] = function() {
w[f].p = arguments;
};
a.async = 1;
a.src = j;
m.parentNode.insertBefore(a, m);
}(window, document, 'script', (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//cdn.yoho.cn/yas-jssdk/2.4.18/yas.js', '_yas'));
}
window.appBaseLogs = {
status: [
{
ca: '',
lo: '',
cy: 'CN',
av: '',
udid: getUdid(),
ln: '',
ab: '',
sid: '',
net: '',
la: ''
}
],
device: {
res: '',
ifa: '',
mac: '',
osv: '',
ifv: '',
ps: '',
os: xianyu.isiOS ? 'ios' : 'android',
ak: 'yoho_xianyu_' + (xianyu.isiOS ? 'ios' : 'android'),
sv: '',
ch: '',
dm: '',
tdid: '',
afp: '',
udid: getUdid()
},
events: [{
sid: '',
uid: getUid()
}]
};
}
initBaseLogs();
export {
initClient,
initBaseLogs
};