base.js
3.01 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
import jsonp from "../utils/jsonp";
import cookies from '../utils/cookie';
import {getQueryObj} from '../utils/common'
const parseUrl = (url) => {
let query = {},
hashs,
hash,
i;
url = (url || '').split('?');
hashs = (url[1] || '').split('&');
if (hashs && hashs.length) {
for (i = 0; i < hashs.length; i++) {
hash = hashs[i].split('=');
query[hash[0]] = hash[1];
}
}
return {
path: url[0],
query: query
};
}
let env = ''
export default {
//evn
env: function () {
let envFlag = window.__wxjs_environment;
if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
document.addEventListener('deviceready', function () {
});
env = 'app';
} else if ((!envFlag && navigator.userAgent.match(/miniProgram/i)) || (envFlag == 'miniprogram')) {
env = 'miniprogram';
} else if (location.origin === 'https://www.yohobuy.com') {
env = 'pc'
}else{
env = 'h5'
}
return env
},
//url
loginUrl: function () {
let url, refer = location.href.split('?')[0];
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
if (env === 'app') {
refer = parseUrl(refer);
if (/Android/i.test(navigator.userAgent || '')) {
if (url.indexOf('?') < 0) {
url += '?appLogin=1';
}
if (location.href.indexOf('&openby') >= 0) {
url = url.substring(0, url.indexOf('&openby'));
}
url += '&';
} else {
if (location.href.indexOf('#openby') >= 0) {
url = url.substring(0, url.indexOf('#openby'));
}
url += '#';
}
url += 'openby:yohobuy=' + JSON.stringify({
action: 'go.weblogin',
params: {
priority: 'N',
jumpurl: {
url: refer.path,
param: refer.query
},
needlogout: 'Y'
}
});
}else if(env === 'pc'){
url = 'https://www.yoho/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + refer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
return url;
},
//uid
uid: async function () {
let result = await jsonp('https://m.yohobuy.com/passport/login/user');
if (result.code === 200)
return Number(result.data);
else if (env === 'app' || env === 'miniprogram')
return Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
else
return 0;
},
geAppUid: Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0
}