|
@@ -323,33 +323,54 @@ export default {
|
|
|
}, 0);
|
|
|
},0);
|
|
|
},
|
|
|
- async getOpenId(code) {
|
|
|
- if (this.oloading) return;
|
|
|
-
|
|
|
- this.oloading = true;
|
|
|
-
|
|
|
- try {
|
|
|
- const res = await axios.get(`//weixin.cocorobo.cn/login.php?code=${code}&time=${Date.now()}`); // 将params作为请求参数,并禁用预加载
|
|
|
- const data = res.data[0];
|
|
|
- console.log("data", data);
|
|
|
- // this.loginType = 'bind';
|
|
|
- } catch (err) {
|
|
|
- console.error("请求失败,错误信息:", err);
|
|
|
- } finally {
|
|
|
- this.oloading = false;
|
|
|
+ async getOpenId(openid) {
|
|
|
+
|
|
|
+ // oiztX1dwR-W2mBJ5HcvaSEB8yKGY
|
|
|
+ axios.defaults.withCredentials = false;
|
|
|
+ let params = {
|
|
|
+ openid: openid
|
|
|
}
|
|
|
+ axios.defaults.withCredentials = true;
|
|
|
+ axios.post(`https://beta.api.cocorobo.cn/api/user`, qs.stringify(params)).then(async res => {
|
|
|
+ console.log("res", res);
|
|
|
+ let _data = res.data[0][0];
|
|
|
+ if (_data.active === 1) {
|
|
|
+ window.localStorage["identity"] = JSON.stringify(_data.identity);
|
|
|
+ this.$message.success("登录成功");
|
|
|
+ await this.login();
|
|
|
+ this.$router.push({ path: this.redirect || "/" });
|
|
|
+ } else {
|
|
|
+ this.$message.error("登录失败");
|
|
|
+ }
|
|
|
+ this.loading = false;
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err.response)
|
|
|
+ if (err && err.response && err.response.status === 401) {
|
|
|
+ this.loginType = 'bind';
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
},
|
|
|
},
|
|
|
mounted() {
|
|
|
let _this = this
|
|
|
window.addEventListener('message', function (e) { // 监听 message 事件
|
|
|
console.log(e);
|
|
|
- if(e.data && e.data.code){
|
|
|
- console.log(e);
|
|
|
- console.log(e.data.code);
|
|
|
- console.log(_this.loginType);
|
|
|
- _this.getOpenId(e.data.code)
|
|
|
- }
|
|
|
+ if(e.data && e.data.method == "getOpenId"){
|
|
|
+ console.log(e);
|
|
|
+ console.log(e.data.code);
|
|
|
+ console.log(_this.loginType);
|
|
|
+
|
|
|
+ if(e.data.code == 200){
|
|
|
+ _this.getOpenId(e.data.data.openid)
|
|
|
+ }else {
|
|
|
+ _this.$message.error('扫码登录失败请重新扫码')
|
|
|
+ _this.wechatLogin()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
});
|
|
|
// this.getLoading();
|
|
|
this.getOrdOidData();
|