Forráskód Böngészése

登录操作时实现url参数解析

Joe 4 éve
szülő
commit
fc032c9fe3
5 módosított fájl, 29 hozzáadás és 7 törlés
  1. 3 1
      assets/util/index.js
  2. 8 3
      package-lock.json
  3. 1 0
      package.json
  4. 16 2
      pages/authen.vue
  5. 1 1
      settings.js

+ 3 - 1
assets/util/index.js

@@ -1,5 +1,7 @@
 import settings from "../../settings"
 export const getAuthen = () =>{
   const path = window.location.pathname === "/authen" ? "/" : window.location.pathname
-  window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + settings.appId + "&redirect_uri=" + settings.url + "%2fauthen&response_type=code&scope=snsapi_userinfo&state="+ path +"#wechat_redirect"
+  const search = window.location.search.replace("?","abc").replace(/&/g,"def").replace(/=/g,"ghi")
+
+  window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + settings.appId + "&redirect_uri=" + settings.url + "%2fauthen&response_type=code&scope=snsapi_userinfo&state="+ path + search  +"#wechat_redirect"
 }

+ 8 - 3
package-lock.json

@@ -8066,9 +8066,9 @@
       }
     },
     "querystring": {
-      "version": "0.2.0",
-      "resolved": "https://registry.npm.taobao.org/querystring/download/querystring-0.2.0.tgz",
-      "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
+      "version": "0.2.1",
+      "resolved": "https://registry.npm.taobao.org/querystring/download/querystring-0.2.1.tgz?cache=0&sync_timestamp=1613400038316&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fquerystring%2Fdownload%2Fquerystring-0.2.1.tgz",
+      "integrity": "sha1-QNd2FbsJ0WkCqFw+OKqLXtdhwt0="
     },
     "querystring-es3": {
       "version": "0.2.1",
@@ -9574,6 +9574,11 @@
           "version": "1.3.2",
           "resolved": "https://registry.npm.taobao.org/punycode/download/punycode-1.3.2.tgz",
           "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
+        },
+        "querystring": {
+          "version": "0.2.0",
+          "resolved": "https://registry.npm.taobao.org/querystring/download/querystring-0.2.0.tgz?cache=0&sync_timestamp=1613400038316&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fquerystring%2Fdownload%2Fquerystring-0.2.0.tgz",
+          "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
         }
       }
     },

+ 1 - 0
package.json

@@ -15,6 +15,7 @@
     "crypto-js": "^4.0.0",
     "moment": "^2.29.1",
     "nuxt": "^2.0.0",
+    "querystring": "^0.2.1",
     "vant": "^2.4.0",
     "vue-amap": "^0.5.10",
     "weixin-js-sdk": "^1.6.0",

+ 16 - 2
pages/authen.vue

@@ -5,6 +5,8 @@
 <script>
 import Vue from "vue";
 import { getAuthen } from "../assets/util";
+import querystring from "querystring";
+
 export default Vue.extend({
   head() {
     return {
@@ -16,12 +18,22 @@ export default Vue.extend({
       redirect: "",
     };
   },
-  mounted() {
-    this.redirect = this.$route.query.state;
+  created() {
+    console.log(this.$route);
+    const [url, str] = this.$route.query.state.split("abc")
+    this.redirect = url;
+    if(str!==undefined){
+      const search = querystring.parse(str.replace(/def/g,"&").replace(/ghi/g,"="));
+      console.log(search)
+    }
+    
     if (!this.$route.query.code) {
       getAuthen();
     } else {
+      console.log("-----");
+      console.log(this.$route);
       this.$store.dispatch("authen/login",this.$route.query.code).then((res)=>{
+        console.log(this.$route.query);
         this.handleGoto();
       }).catch((res)=>{
         alert(res);
@@ -31,6 +43,8 @@ export default Vue.extend({
   },
   methods: {
     handleGoto() {
+      console.log("goto")
+      console.log(this.redirect);
       this.$router.replace({
         path: this.redirect,
       });

+ 1 - 1
settings.js

@@ -2,6 +2,6 @@ export default {
   appId:"wxc8189d3b3a7283e0",
   stationId:1,
   // url:"http://www.onlyfido.top"
-  url:"http://www.huijy.net/",
+  url:"http://www.huijy.net",
   debug: true
 }