浏览代码

完善登录

seimin 3 年之前
父节点
当前提交
15a0d0fbf4
共有 1 个文件被更改,包括 82 次插入3 次删除
  1. 82 3
      src/views/Login.vue

+ 82 - 3
src/views/Login.vue

@@ -71,7 +71,7 @@ export default {
71 71
             this.requesterLgoinType
72 72
           );
73 73
           if (this.requesterLgoinType == "wechat") {
74
-            //没有微信端
74
+            this.getCode();
75 75
           } else if (this.requesterLgoinType == "web") {
76 76
             // this.$router.push({ path: "/login" });
77 77
           }
@@ -117,10 +117,89 @@ export default {
117 117
             .show();
118 118
         }
119 119
       });
120
-    }
120
+    },
121
+    // 登陆
122
+    login() {
123
+      var that = this;
124
+      that.$http.post("service/auth/wechatAuth", {}).then(function(res) {
125
+        if (res.data.url) {
126
+          window.location.href = res.data.url;
127
+        } else {
128
+          if (res.data.user) {
129
+            that.getConfig();
130
+            localStorage.setItem(
131
+              "loginUser",
132
+              JSON.stringify(res.data.user.user)
133
+            );
134
+            localStorage.setItem(
135
+              "login_requester",
136
+              JSON.stringify(res.data.user.requester)
137
+            );
138
+            this.$router.push({ path: "/main" });
139
+          }
140
+        }
141
+      });
142
+    },
143
+    // 获取code
144
+    getCode() {
145
+      var that = this;
146
+      var url = window.location.href.split("?");
147
+      if (!url[1]) {
148
+        that.login();
149
+      } else {
150
+        var code = {
151
+          code: url[1],
152
+        };
153
+        that.$http.post("service/auth/wechatLoginEncrypt", code).then((res) => {
154
+          if (res.data.state == 200) {
155
+            if (res.data.user) {
156
+              that.getConfig();
157
+              localStorage.setItem(
158
+                "loginUser",
159
+                JSON.stringify(res.data.user.user)
160
+              );
161
+              localStorage.setItem(
162
+                "login_requester",
163
+                JSON.stringify(res.data.user.requester)
164
+              );
165
+              this.$router.push({ path: "/main" });
166
+            }
167
+          } else if (res.data.state == 501) {
168
+            that
169
+              .$createDialog({
170
+                type: "alert",
171
+                title: "您的账号被删除,请联系管理员",
172
+                icon: "cubeic-alert"
173
+              })
174
+              .show();
175
+          } else {
176
+            that
177
+              .$createDialog({
178
+                type: "alert",
179
+                title: res.data.remarks,
180
+                icon: "cubeic-alert"
181
+              })
182
+              .show();
183
+          }
184
+        });
185
+      }
186
+    },
187
+    // 获取查询参数
188
+    getQueryString(name) {
189
+    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
190
+    var r = window.location.search.substr(1).match(reg);
191
+    if (r != null){
192
+        return unescape(r[2]);
193
+      }
194
+      return null;
195
+    },
121 196
   },
122 197
   created() {
123
-    this.isSSo = location.search.length > 0;
198
+    if(location.search.length > 0){
199
+      this.isSSo = Boolean(this.getQueryString('t'));
200
+    }else{
201
+      this.isSSo = false;
202
+    }
124 203
     if (this.isSSo) {
125 204
       this.zlogin();
126 205
     }