lsc 5 days ago
parent
commit
4f09c3aafd
1 changed files with 19 additions and 2 deletions
  1. 19 2
      src/views/wechatAuth/index.vue

+ 19 - 2
src/views/wechatAuth/index.vue

@@ -55,6 +55,8 @@ export default {
     wechatConfig() {
       // 直接返回对象,不需要再返回函数
       const redirectUri = this.$route.query.url ? decodeURIComponent(this.$route.query.url) : null
+      const isApp = this.$route.query.isApp ? this.$route.query.isApp : '2'
+      Cookies.set('isApp', isApp)
       console.log('redirectUri from query:', redirectUri)
       if (redirectUri && redirectUri !== 'undefined') {
         Cookies.set('redirectUri', redirectUri)
@@ -158,6 +160,8 @@ export default {
               // this.$router.replace('/login')
               await this.login()
               let redirect_uri = Cookies.get('redirectUri')
+              const isApp = Cookies.get('isApp')
+
               if (!redirect_uri || redirect_uri === 'undefined') {
                 redirect_uri = ''
               }
@@ -165,7 +169,13 @@ export default {
               console.log(redirect_uri)
               if (redirect_uri) {
                 // Cookies.remove('redirectUri')
-                window.location.href = redirect_uri
+                if (isApp === '2') {
+                  window.location.href = `weixin://dl/business/?appid=${
+                    this.wechatConfig.appId
+                  }&path=pages/index/index&query=${encodeURIComponent(redirect_uri)}`
+                } else {
+                  window.location.href = redirect_uri
+                }
               } else {
                 this.$router.replace('/appStoreCopy')
               }
@@ -267,6 +277,7 @@ export default {
       try {
         const userid = await this.login()
         let redirect_uri = Cookies.get('redirectUri')
+        const isApp = Cookies.get('isApp')
         if (!redirect_uri || redirect_uri === 'undefined') {
           redirect_uri = ''
         }
@@ -279,7 +290,13 @@ export default {
         if (userid) {
           if (redirect_uri) {
             // Cookies.remove('redirectUri')
-            window.location.href = redirect_uri
+            if (isApp === '2') {
+              window.location.href = `weixin://dl/business/?appid=${
+                this.wechatConfig.appId
+              }&path=pages/index/index&query=${encodeURIComponent(redirect_uri)}`
+            } else {
+              window.location.href = redirect_uri
+            }
           } else if (courseId) {
             this.$router.replace({
               path: '/courseDetail',