Quellcode durchsuchen

Update login.tsx

lex vor 2 Jahren
Ursprung
Commit
aebe5797ca
1 geänderte Dateien mit 23 neuen und 13 gelöschten Zeilen
  1. 23 13
      src/student/music-group/layout/login.tsx

+ 23 - 13
src/student/music-group/layout/login.tsx

@@ -58,17 +58,27 @@ export default defineComponent({
     // }
   },
   methods: {
-    // async getAppIdAndCode() {
-    //   try {
-    //     const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
-    //     // 判断是否有微信appId
-    //     if (data) {
-    //       this.wxAppId = data
-    //     }
-    //   } catch {
-    //     //
-    //   }
-    // },
+    async getAppIdAndCode(url?: string) {
+      try {
+        const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
+        // 判断是否有微信appId
+        if (data) {
+          this.goAuth(data, url)
+        }
+      } catch {
+        //
+      }
+    },
+    goAuth(wxAppId: string, urlString?: string) {
+      // 用户授权
+      console.log(urlString || window.location.href, 'urlString || window.location.href')
+      const urlNow = encodeURIComponent(urlString || window.location.href)
+      console.log(urlNow, 'urlNow')
+      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+      const appid = wxAppId || 'wx8654c671631cfade'
+      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+      window.location.replace(url)
+    },
     directNext() {
       if (state.user.status === 'login' || state.user.status === 'error') {
         const { returnUrl, isRegister, ...rest } = this.$route.query
@@ -97,9 +107,9 @@ export default defineComponent({
           '?' +
           qs.stringify({
             ...rest
-            // wxAppId: this.wxAppId
           })
-        this.locationReplace(newUrl)
+        this.getAppIdAndCode(newUrl)
+        // this.locationReplace(newUrl)
       }
     },
     locationReplace(url: any) {