wechatuser/login 适配

This commit is contained in:
wkj 2024-05-23 01:02:24 +08:00
parent 5cc5ee9922
commit 06541a0ab0
2 changed files with 26 additions and 47 deletions

View File

@ -17,7 +17,6 @@ export default OakComponent({
this.setState({
loading: true,
});
const token = this.features.token.getToken(true);
const url = window.location.href;
const urlParse = new URL(url);
//格式 xx?code=xx&state=/xx/xx?d=xx
@ -26,41 +25,32 @@ export default OakComponent({
const wechatLoginId = urlParse?.searchParams?.get('wechatLoginId');
if (!code) {
this.setState({
error: this.t('missingCodeParameter'),
error: '缺少code参数',
loading: false,
});
return;
}
if (process.env.NODE_ENV === 'production' &&
token?.ableState === 'enabled') {
try {
// web微信扫码跟公众号授权
await this.features.token.loginWechat(code, {
wechatLoginId,
});
this.setState({
loading: false,
});
this.go(state);
}
else {
try {
// web微信扫码跟公众号授权
await this.features.token.loginWechat(code, {
wechatLoginId,
});
this.setState({
loading: false,
});
this.go(state);
}
catch (err) {
this.setState({
error: this.t('weChatLoginFailed'),
loading: false,
});
throw err;
}
catch (err) {
this.setState({
error: '微信登录失败',
loading: false,
});
throw err;
}
},
go(state) {
if (!state) {
this.navigateBack(2);
this.navigateBack();
return;
}
this.redirectTo({

View File

@ -18,7 +18,6 @@ export default OakComponent({
this.setState({
loading: true,
});
const token = this.features.token.getToken(true);
const url = window.location.href;
const urlParse = new URL(url);
//格式 xx?code=xx&state=/xx/xx?d=xx
@ -27,42 +26,32 @@ export default OakComponent({
const wechatLoginId = urlParse?.searchParams?.get('wechatLoginId') as string;
if (!code) {
this.setState({
error: this.t('missingCodeParameter'),
error: '缺少code参数',
loading: false,
});
return;
}
if (
process.env.NODE_ENV === 'production' &&
token?.ableState === 'enabled'
) {
try {
// web微信扫码跟公众号授权
await this.features.token.loginWechat(code, {
wechatLoginId,
});
this.setState({
loading: false,
});
this.go(state);
} else {
try {
// web微信扫码跟公众号授权
await this.features.token.loginWechat(code, {
wechatLoginId,
});
this.setState({
loading: false,
});
this.go(state);
} catch (err) {
this.setState({
error: this.t('weChatLoginFailed'),
loading: false,
});
throw err;
}
} catch (err) {
this.setState({
error: '微信登录失败',
loading: false,
});
throw err;
}
},
go(state?: string) {
if (!state) {
this.navigateBack(2);
this.navigateBack();
return;
}
this.redirectTo({