|
|
import qs from 'yoho-qs';
|
|
|
import cookie from 'yoho-cookie';
|
|
|
import jsonp from 'jsonp';
|
|
|
import 'whatwg-fetch';
|
|
|
|
|
|
const uid = qs.yh_uid;
|
...
|
...
|
@@ -10,7 +12,27 @@ if (process.env.NODE_ENV === 'production') { |
|
|
baseUrl = 'http://localhost:6006';
|
|
|
}
|
|
|
|
|
|
const loginLog = userId => {
|
|
|
if (!cookie.get('_loginLog')) {
|
|
|
fetch(`${baseUrl}/user/loginLog`, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json'
|
|
|
},
|
|
|
body: JSON.stringify({
|
|
|
uid: userId
|
|
|
})
|
|
|
}).then(res => {
|
|
|
if (res.ok) {
|
|
|
cookie.set('_loginLog', true);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (!uid) {
|
|
|
jsonp('http://m.yohobuy.com/passport/login/user', {}, (errMsg, userRes) => {
|
|
|
if (userRes.code !== 200) {
|
|
|
fetch(`${baseUrl}/user/getLoginUrl?url=${window.location.href}`).then(res => {
|
|
|
if (res.ok) {
|
|
|
res.json().then(data => {
|
...
|
...
|
@@ -18,14 +40,10 @@ if (!uid) { |
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
fetch(`${baseUrl}/user/loginLog`, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json'
|
|
|
},
|
|
|
body: JSON.stringify({
|
|
|
uid
|
|
|
})
|
|
|
} else {
|
|
|
loginLog(userRes.data);
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
loginLog(uid);
|
|
|
} |
...
|
...
|
|