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

View File

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