Procházet zdrojové kódy

多种认证方式并存

Joe před 4 roky
rodič
revize
2d4b844fe8
6 změnil soubory, kde provedl 41 přidání a 14 odebrání
  1. 33 6
      assets/util/index.js
  2. 2 2
      nuxt.config.js
  3. 5 1
      pages/authen.vue
  4. 0 1
      pages/point/list.vue
  5. 0 1
      pages/point/success.vue
  6. 1 3
      settings.js

+ 33 - 6
assets/util/index.js

@@ -1,8 +1,35 @@
-import settings from "../../settings"
-export const getAuthen = () =>{
-  console.log(this)
-  const path = window.location.pathname === "/authen" ? "/" : window.location.pathname
-  const search = window.location.search.replace("?",".").replace(/&/g,"-").replace(/=/g,"_")
+import querystring from "querystring";
+import settings from "@/settings"
 
-  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"
+export const getAuthen = function () {
+  const search = window.location.search
+ /**
+ * 这一段作用是先挑战网页后再跳转
+ **/
+  if (search !== '') {
+    const search = querystring.parse(window.location.search.replace("?", ''))
+    let appIdPromise
+    if (!!search.stationId) {
+      $nuxt.$store.commit("authen/setStationId", search.stationId)
+    } else {
+      alert('你没有传递站点参数');
+    }
+
+    if (!!search.appId) {
+      $nuxt.$store.commit("authen/setAppId", search.appId)
+      appIdPromise = Promise.resolve();
+    } else {
+      appIdPromise = $nuxt.$store.dispatch('authen/getAppId', search.stationId).then((res) => {
+        $nuxt.$store.commit("authen/setStationId", res.stationId)
+      })
+    }
+
+    const path = window.location.pathname === "/authen" ? "/" : window.location.pathname
+    const searchStr = window.location.search.replace("?", ".").replace(/&/g, "-").replace(/=/g, "_")
+    appIdPromise.then(() => {
+      window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + $nuxt.$store.getters["authen/appId"] + "&redirect_uri=" + settings.url + "%2fauthen&response_type=code&scope=snsapi_userinfo&state=" + path + searchStr + "#wechat_redirect"
+    })
+  } else {
+    alert("请传递站点参数")
+  }
 }

+ 2 - 2
nuxt.config.js

@@ -3,8 +3,8 @@ export default {
   server: {
     port: 8081, // default: 3000
     // host: '192.168.3.14' // default: localhost
-    host:"localhost",
-    // host:"192.168.0.105",
+    // host:"localhost",
+    host:"192.168.0.106",
   },
   // disableHostCheck: true,
   modules: [

+ 5 - 1
pages/authen.vue

@@ -22,6 +22,9 @@ export default Vue.extend({
   created() {
     const [url, str] = this.$route.query.state.split(".");
     this.redirect = url;
+    /**
+     * 这一段作用是直接微信接口跳转
+     **/
     if (str !== undefined) {
       const search = querystring.parse(
         str.replace(/-/g, "&").replace(/_/g, "=")
@@ -35,7 +38,8 @@ export default Vue.extend({
         this.setAppId(search.appId);
         this.havingAuthen();
       } else {
-        this.getAppId(search.stationId).then(() => {
+        this.getAppId(search.stationId).then((res) => {
+          this.setStationId(res.stationId)
           this.havingAuthen();
         });
       }

+ 0 - 1
pages/point/list.vue

@@ -161,7 +161,6 @@ export default {
   left: 0.3rem;
 }
 .point-list .order .top .status {
-  width: 0.84rem;
   height: 0.4rem;
   font-size: 0.28rem;
   font-family: PingFangSC-Regular, PingFang SC;

+ 0 - 1
pages/point/success.vue

@@ -60,7 +60,6 @@ export default {
 }
 
 .point-success .text {
-  width: 1.6rem;
   height: 0.56rem;
   font-size: 0.4rem;
   font-family: PingFangSC-Regular, PingFang SC;

+ 1 - 3
settings.js

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