47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
export default OakComponent({
|
|
entity: 'wechatLogin',
|
|
projection: {
|
|
id: 1,
|
|
expired: 1,
|
|
expiresAt: 1,
|
|
userId: 1,
|
|
type: 1,
|
|
qrCodeType: 1,
|
|
successed: 1,
|
|
},
|
|
isList: false,
|
|
properties: {
|
|
wechatLoginResultPage: '/wechatLogin/confirm',
|
|
wechatUserLoginPage: '/wechatUser/login',
|
|
},
|
|
formData({ data: wechatLogin, features }) {
|
|
const loginUserId = features.token.getUserId(true);
|
|
const user = wechatLogin?.user;
|
|
const userId = wechatLogin?.userId;
|
|
const type = wechatLogin?.type;
|
|
const application = features.application.getApplication();
|
|
const appId = application?.config?.appId;
|
|
return {
|
|
type,
|
|
userId,
|
|
expired: wechatLogin?.expired,
|
|
expiresAt: wechatLogin?.expiresAt,
|
|
successed: wechatLogin?.successed,
|
|
loginUserId,
|
|
appId,
|
|
};
|
|
},
|
|
methods: {
|
|
getCodeAndRedirect() {
|
|
const { wechatLoginConfirmPage, wechatUserLoginPage } = this.props;
|
|
const wechatLoginId = this.props.oakId;
|
|
const state = encodeURIComponent(`${wechatLoginConfirmPage}?oakId=${wechatLoginId}`);
|
|
const { appId } = this.state;
|
|
const host = window.location.host;
|
|
const protocol = window.location.protocol === 'https:' ? 'https' : 'http';
|
|
const redirectUri = encodeURIComponent(`${protocol}://${host}${wechatUserLoginPage}?wechatLoginId=${wechatLoginId}`);
|
|
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
|
|
}
|
|
},
|
|
});
|