login.vue
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<template>
<div class="containerbox"></div>
</template>
<script>
import Vue from "vue";
import { getUrlKey } from "../../utils/utils.js";
const murl = "http://tangyuan.h.brofirst.cn";
const now_url = sessionStorage.getItem("now_url");
console.log('页面路径', now_url)
export default {
//生命周期函数
created() {
const code = this.GetUrlParame("code"); // 截取code
console.log('9999', code)
if (!code) {
let urlk = window.location.href
console.log(urlk, 34893488493)
let that = this;
var url = "/api/user/authorize";
let param = {
redirect_uri: urlk
};
that.$axios
.post(url, param)
.then(function (res) {
console.log(res);
window.location.href = res.data.wechat_url
})
.catch(function (error) {
console.log(error);
});
} else {
let param = {
platform: 'wechat',
code: code
}
console.log(param);
this.$axios
.get("/api/user/third?code=" + code) //如果有code,说明用户点击了授权 将获取到的code传递给后台
.then(res => {
// 返回状态和UId
console.log(res, '返回的数据')
if (res.data) {
sessionStorage.setItem("token", res.data.token);
}
console.log(now_url, 99999)
if (now_url) {
window.location.replace(murl + now_url);
} else {
window.location.replace(murl);
}
});
}
},
data() {
return {};
},
methods: {
// 截取code
GetUrlParame(parameName) {
/// 获取地址栏指定参数的值
/// <param name="parameName">参数名</param>
// 获取url中跟在问号后面的部分
var parames = window.location.search;
// 检测参数是否存在
if (parames.indexOf(parameName) > -1) {
var parameValue = "";
parameValue = parames.substring(
parames.indexOf(parameName),
parames.length
);
// 检测后面是否还有参数
if (parameValue.indexOf("&") > -1) {
// 去除后面多余的参数, 得到最终 parameName=parameValue 形式的值
parameValue = parameValue.substring(0, parameValue.indexOf("&"));
// 去掉参数名, 得到最终纯值字符串
parameValue = parameValue.replace(parameName + "=", "");
return parameValue;
}
return "";
}
}
}
};
</script>
<style></style>