init-client.js
1.97 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
import Vue from 'vue';
import cookie from 'yoho-cookie';
import yoho from 'common/yoho';
import version from 'utils/version';
export default store => {
window.onresize = () => {
const {clientWidth, clientHeight} = document.body;
store.commit('SET_WINDOW_SIZE', {clientWidth, clientHeight});
setStatusBar(clientWidth, clientHeight);
};
const {clientWidth, clientHeight} = document.body;
store.commit('SET_WINDOW_SIZE', {clientWidth, clientHeight});
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});
store.commit('SET_ENV', {
env: {
isApp: yoho.isApp,
isiOS: yoho.isiOS,
isAndroid: yoho.isAndroid,
isYohoBuy: yoho.isYohoBuy,
}
});
function setStatusBar(width, height) {
// 仅支持ios
if (yoho.isYohoBuy && yoho.isiOS) {
store.commit('SET_STATUS_BAR_HEIGHT', {
height: (height / width) > 2.1 ? 44 : 22
});
if (version(cookie.get('app_version'),' 6.9.2') >= 0) {
store.commit('SET_STATUS_BAR_STATUS', {status: true});
}
}
}
setStatusBar(clientWidth, clientHeight);
if (/yoho/i.test(navigator.userAgent) && /supportWebp/i.test(navigator.userAgent)) {
store.commit('SET_SUPPORT_WEBP', {supportWebp: true});
}
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';
Vue.$sdk.getUser().then(user => {
if (user && user.uid) {
store.commit('SET_LOGIN_INFO', user);
}
});
Vue.$yoho.ready(() => {
Vue.$yoho.setWebview({
bounces: false,
clearCacheWhenDestroy: false
});
});
};