|
@@ -10,27 +10,18 @@ export function isWechat() {
|
|
|
/* return true;*/
|
|
|
}
|
|
|
|
|
|
-export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
|
|
|
- /*alert("22redirectUrl:" + decodeURIComponent(redirectUrl));*/
|
|
|
- redirectUrl = decodeURIComponent(redirectUrl)
|
|
|
+export const wxAuth = async <Object>(routePath: string): Promise<string> => {
|
|
|
try {
|
|
|
const userStore = useUserStore();
|
|
|
- let oAuthUrl_redirectUrl = "";
|
|
|
const router = useRouter();
|
|
|
+ const urlParams = getUrlParams() as any;
|
|
|
+ const openId = urlParams["openId"] || userStore.getOpenId;
|
|
|
+ const code = urlParams["code"];
|
|
|
|
|
|
- if (isWechat() && !userStore.getOpenId) {
|
|
|
- await getConfig().then((data: any) => {
|
|
|
- oAuthUrl_redirectUrl = data.webSiteUrl + "?redirectUrl=" + redirectUrl;
|
|
|
- })
|
|
|
- const urlParams = getUrlParams() as any;
|
|
|
- const code = urlParams["code"];
|
|
|
- const openId = urlParams["openId"];
|
|
|
+ if (isWechat()) {
|
|
|
if (openId) {
|
|
|
userStore.setOpenId(openId);
|
|
|
- /*alert("22redirectUrl:" + decodeURIComponent(redirectUrl));*/
|
|
|
- router.push(redirectUrl);
|
|
|
} else {
|
|
|
- /* alert("33redirectUrl:" + decodeURIComponent(redirectUrl));*/
|
|
|
if (!code) {
|
|
|
const loading = await loadingController.create({
|
|
|
cssClass: 'my-custom-class',
|
|
@@ -39,6 +30,11 @@ export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
|
|
|
});
|
|
|
await loading.present();
|
|
|
|
|
|
+ let oAuthUrl_redirectUrl = "";
|
|
|
+ await getConfig().then((data: any) => {
|
|
|
+ oAuthUrl_redirectUrl = data.webSiteUrl + "?routePath=" + encodeURIComponent(routePath); //www.aa.com/mobile?routePath=xxxxx
|
|
|
+ })
|
|
|
+
|
|
|
getOAuthUrl(encodeURIComponent(oAuthUrl_redirectUrl)).then((res: any) => {
|
|
|
if (res) {
|
|
|
window.location.replace(res);
|
|
@@ -56,36 +52,14 @@ export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
|
|
|
await getWxOpenId(code).then((res: any) => {
|
|
|
userStore.setOpenId(res);
|
|
|
|
|
|
- const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
|
|
|
-
|
|
|
- alert("currentUrl:" + currentUrl);
|
|
|
+ const currentUrl = routePath + (routePath.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
|
|
|
|
|
|
router.push(currentUrl);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- router.push(decodeURIComponent(redirectUrl));
|
|
|
-
|
|
|
- } /* const router = useRouter();
|
|
|
- await getWxOpenId("").then((res: any) => {
|
|
|
- userStore.setOpenId(res);
|
|
|
-
|
|
|
- const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
|
|
|
-
|
|
|
- alert("currentUrl:" + currentUrl);
|
|
|
-
|
|
|
- router.push(currentUrl);
|
|
|
- },()=>{
|
|
|
- userStore.setOpenId("2222");
|
|
|
-
|
|
|
-
|
|
|
- const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=2222";
|
|
|
-
|
|
|
- alert("currentUrl222:" + currentUrl);
|
|
|
+ }
|
|
|
|
|
|
- router.push(currentUrl);
|
|
|
- });*/
|
|
|
return "";
|
|
|
} catch (e) {
|
|
|
return Promise.reject(null);
|