-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgob.js
71 lines (70 loc) · 2.09 KB
/
gob.js
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
import axios from 'axios'
import qs from 'qs'
// 176.166.1.47
let gob = {
getWebUrl:function(){
if(window.location.href.indexOf("http://localhost")>-1){
return "/api"
}
if(window.location.href.indexOf("youhuiduo.cn")>-1){
return "https://xxxx/"
}
if(window.location.href.indexOf("ujinbi.com")>-1){
return "https://xxxxxxxxx/"
}
},
webUrl:function(){
if(window.location.href.indexOf("http://localhost")>-1){
return "http://192.168.18.54:11015/"
}
if(window.location.href.indexOf("youhuiduo.cn")>-1){
return "https://xxxx/"
}
if(window.location.href.indexOf("ujinbi.com")>-1){
return "https://xxxxx"
}
},
post:function(url,data){
var _this = this;
return new Promise(function(resolve, reject){
axios.post(_this.getWebUrl()+url,
qs.stringify(data),
)
.then(function(res){
resolve(res);
})
})
},
get:function(url,data){
var _this = this;
return new Promise(function(resolve, reject) {
axios.get(_this.getWebUrl()+url,
{
params:data
}
)
.then(function(res){
resolve(res);
})
})
},
getCookie: function(name) {
var strcookie = document.cookie;//获取cookie字符串
var arrcookie = strcookie.split("; ");//分割
//遍历匹配
for ( var i = 0; i < arrcookie.length; i++) {
var arr = arrcookie[i].split("=");
if (arr[0] == name){
return arr[1];
}
}
return "";
},
setCookie: function(name,value){
var exp = new Date();
exp.setTime(exp.getTime() + 3600 * 60 * 24 *10);//过期时间6分钟
// document.cookie = 'openid=' + openid + ";expires=" + exp.toGMTString();
document.cookie = `${name}=${value};expires=${exp.toGMTString()}`
},
}
export default gob