|
@@ -18,36 +18,42 @@ export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
|
|
|
})
|
|
|
const urlParams = getUrlParams() as any;
|
|
|
const code = urlParams["code"];
|
|
|
-
|
|
|
- if (!code) {
|
|
|
- const loading = await loadingController.create({
|
|
|
- cssClass: 'my-custom-class',
|
|
|
- message: '微信授权中,请稍等...',
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
- await loading.present();
|
|
|
- getOAuthUrl(encodeURIComponent(redirectUrl)).then((res: any) => {
|
|
|
- if (res) {
|
|
|
- window.location.replace(res);
|
|
|
- } else {
|
|
|
- presentAlert("微信授权失败!");
|
|
|
- }
|
|
|
- });
|
|
|
+ const openId = urlParams["openId"];
|
|
|
+ if (openId) {
|
|
|
+ userStore.setOpenId(openId);
|
|
|
} else {
|
|
|
- const loading = await loadingController.create({
|
|
|
- cssClass: 'my-custom-class',
|
|
|
- message: '微信授权成功,请稍等...',
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
- await loading.present();
|
|
|
- await getWxOpenId(code).then((res: any) => {
|
|
|
- userStore.setOpenId(res);
|
|
|
- });
|
|
|
+ if (!code) {
|
|
|
+ const loading = await loadingController.create({
|
|
|
+ cssClass: 'my-custom-class',
|
|
|
+ message: '微信授权中,请稍等...',
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ await loading.present();
|
|
|
+ getOAuthUrl(encodeURIComponent(redirectUrl)).then((res: any) => {
|
|
|
+ if (res) {
|
|
|
+ window.location.replace(res);
|
|
|
+ } else {
|
|
|
+ presentAlert("微信授权失败!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const loading = await loadingController.create({
|
|
|
+ cssClass: 'my-custom-class',
|
|
|
+ message: '微信授权成功,请稍等...',
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ await loading.present();
|
|
|
+ await getWxOpenId(code).then((res: any) => {
|
|
|
+ userStore.setOpenId(res);
|
|
|
+
|
|
|
+ /*const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
|
|
|
+ window.location.replace(currentUrl);*/
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return "";
|
|
|
- }
|
|
|
- catch (e){
|
|
|
+ } catch (e) {
|
|
|
return Promise.reject(null);
|
|
|
}
|
|
|
}
|