...
|
...
|
@@ -9,6 +9,19 @@ const USER_LOGIN_SUCCESS = 'user-login-success'; |
|
|
const MY_USER_LOGIN_SUCCESS = 'my-user-login-success';
|
|
|
const USER_CHANGE_LOGIN_STATUS = 'change-login-status';
|
|
|
|
|
|
const reportAnalytics = (report_key, monitor_id, error) => {
|
|
|
try {
|
|
|
const analytics = global.analytics;
|
|
|
wx.reportMonitor(monitor_id, 1);
|
|
|
analytics.report(report_key, {
|
|
|
error: (error && error.message) || (error && error.errMsg),
|
|
|
monitor_id
|
|
|
});
|
|
|
} catch(err) {
|
|
|
console.error(err);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export const loginAction = (callBack, isReject) => {
|
|
|
return wx.login({
|
|
|
success(res) {
|
...
|
...
|
@@ -24,11 +37,23 @@ export const loginAction = (callBack, isReject) => { |
|
|
if (callBack) {
|
|
|
callBack(error);
|
|
|
}
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.WX_LOGIN_ERROR, '0', error);
|
|
|
});
|
|
|
} else {
|
|
|
if (callBack) {
|
|
|
callBack(res);
|
|
|
}
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.WX_LOGIN_ERROR, '0', res);
|
|
|
}
|
|
|
},
|
|
|
fail(error) {
|
|
|
callBack(error);
|
|
|
if (callBack) {
|
|
|
callBack(error);
|
|
|
}
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.WX_LOGIN_ERROR, '0', error);
|
|
|
}
|
|
|
})
|
|
|
};
|
...
|
...
|
@@ -83,8 +108,8 @@ export const decodeUnionId = (srd_session, result) => { |
|
|
// 网络上传头像,union_id,昵称
|
|
|
login.sendWeChatUserDataWithUnionId(data.union_id, nickName, avatarUrl).catch(error => {
|
|
|
});
|
|
|
return {
|
|
|
union_id: union_id,
|
|
|
return {
|
|
|
union_id: union_id,
|
|
|
userInfo: res.userInfo
|
|
|
};
|
|
|
});
|
...
|
...
|
@@ -158,11 +183,16 @@ export const wechatUserIsBind = (union_id, userInfo = {}) => { |
|
|
});
|
|
|
} else {
|
|
|
console.log('login ------------ globalData: ', globalData);
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.SIGNIN_BY_OPENID_ERROR, '3', { message: 'is_bind is N' });
|
|
|
return Promise.resolve({
|
|
|
code: 10004,
|
|
|
message: '微信用户未绑定手机号'
|
|
|
});
|
|
|
}
|
|
|
}).catch(error => {
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.SIGNIN_BY_OPENID_ERROR, '3', error);
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -185,7 +215,7 @@ const getStorageWithValueForKey = (key) => { |
|
|
wx.getStorage({
|
|
|
key: key,
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
|
},
|
|
|
})
|
|
|
}
|
...
|
...
|
@@ -222,8 +252,8 @@ export const getUserInfo = (e) => { |
|
|
const fromPage = e.currentTarget.dataset.from;
|
|
|
if (e.detail.errMsg === 'getUserInfo:ok') {
|
|
|
loginAction((error, loginData) => {
|
|
|
if (error) {
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message);
|
|
|
if (error) {
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message || error.errMsg);
|
|
|
return;
|
|
|
}
|
|
|
console.log('loginData: ', loginData);
|
...
|
...
|
@@ -260,6 +290,8 @@ export const getUserInfo = (e) => { |
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message);
|
|
|
});
|
|
|
}).catch(error => {
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.DECODE_USERINFO_ERROR, '4', error);
|
|
|
event.emit(checkEventName(USER_LOGIN_CALLBACK, fromPage), error);
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message);
|
|
|
});
|
...
|
...
|
@@ -291,6 +323,8 @@ export const getUserInfo = (e) => { |
|
|
}
|
|
|
event.emit(checkEventName(USER_LOGIN_CALLBACK, fromPage), message);
|
|
|
}).catch(error => {
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.GET_USER_INFO_ERROR, '1', error);
|
|
|
event.emit(checkEventName(USER_LOGIN_CALLBACK, fromPage), error);
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message);
|
|
|
});
|
...
|
...
|
@@ -298,10 +332,12 @@ export const getUserInfo = (e) => { |
|
|
}, true);
|
|
|
} else {
|
|
|
loginAction((error, loginAction) => {
|
|
|
let errMsg = error.message;
|
|
|
let errMsg = e.detail.errMsg;
|
|
|
if (e.detail.errMsg === 'getUserInfo:fail auth deny') {
|
|
|
errMsg = '获取用户授权失败,请使用手机号登录';
|
|
|
}
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.GET_USER_INFO_ERROR, '1', e.detail);
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), errMsg);
|
|
|
}, false);
|
|
|
}
|
...
|
...
|
@@ -324,6 +360,9 @@ export const getPhoneNumber = (e) => { |
|
|
}
|
|
|
throw new Error('手机号获取失败,请重新获取');
|
|
|
}).then(result => {
|
|
|
if(result.nFlag === 'Y') {
|
|
|
event.emit('report-new-user-created');
|
|
|
}
|
|
|
if (result.is_register !== undefined && result.is_register === 0) {
|
|
|
const newUserInfo = {
|
|
|
is_bind: result.is_bind,
|
...
|
...
|
@@ -372,8 +411,12 @@ export const getPhoneNumber = (e) => { |
|
|
}
|
|
|
}).catch(error => {
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), error.message);
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.DECODE_USERINFO_ERROR, '5', error);
|
|
|
});
|
|
|
} else {
|
|
|
const analytics = global.analytics;
|
|
|
reportAnalytics(analytics.keys.GET_PHONENUMBER_ERROR, '2', e.detail);
|
|
|
event.emit(checkEventName(USER_GET_PHONENUMBER_ERROR, fromPage), e.detail.errMsg);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -414,4 +457,4 @@ const getStorageUserInfo = () => { |
|
|
|
|
|
export const getCountryArea = () => {
|
|
|
return login.getCountryArea();
|
|
|
} |
|
|
\ No newline at end of file |
|
|
} |
...
|
...
|
|