62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
export default OakComponent({
|
|
isList: false,
|
|
data: {
|
|
error: '',
|
|
loading: false,
|
|
},
|
|
lifetimes: {
|
|
attached() {
|
|
// if (process.env.OAK_PLATFORM === 'web') {
|
|
//处理微信授权登录
|
|
this.login();
|
|
// }
|
|
},
|
|
},
|
|
methods: {
|
|
async login() {
|
|
this.setState({
|
|
loading: true,
|
|
});
|
|
const url = window.location.href;
|
|
const urlParse = new URL(url);
|
|
//格式 xx?code=xx&state=/xx/xx?d=xx
|
|
const code = urlParse?.searchParams?.get('code');
|
|
const state = urlParse?.searchParams?.get('state');
|
|
const wechatLoginId = urlParse?.searchParams?.get('wechatLoginId');
|
|
if (!code) {
|
|
this.setState({
|
|
error: '缺少code参数',
|
|
loading: false,
|
|
});
|
|
return;
|
|
}
|
|
try {
|
|
// web微信扫码跟公众号授权
|
|
await this.features.token.loginWechat(code, {
|
|
wechatLoginId,
|
|
});
|
|
this.setState({
|
|
loading: false,
|
|
});
|
|
this.go(state);
|
|
}
|
|
catch (err) {
|
|
this.setState({
|
|
error: '微信登录失败',
|
|
loading: false,
|
|
});
|
|
throw err;
|
|
}
|
|
},
|
|
go(state) {
|
|
if (!state) {
|
|
this.navigateBack();
|
|
return;
|
|
}
|
|
this.redirectTo({
|
|
url: state,
|
|
});
|
|
},
|
|
},
|
|
});
|