util.js
3.54 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
95
96
97
98
99
100
101
102
(function(){
'use strict';
let utils=function(){}
let blackId = ''
let origin = window.location.origin
if(origin.includes('localhost')>0 || origin=='null' || origin.includes('file:')>0){
origin = 'https://testznzl.lgyzpt.com'
}
utils.prototype={
/**
* 获取地址栏后边的参数
*/
getUrlParam:function(m) {
let reg = new RegExp('(^|&)' + m + '=([^&]*)(&|$)')
let r = window.location.href.split('?')
r = r.length === 1 ? null : r[1].match(reg)
if (r == null) return ''
return decodeURIComponent(r[2]).replace(/(#|wechat_redirect|\/[0-9a-zA-Z]*)*/g, '')
},
/**
* 判断设备是Android还是iPhone
*/
androidOrIphone: function () {
var system = window.navigator.userAgent.toLowerCase();
if (system.indexOf("iphone") >= 0 || system.indexOf("ipad") >= 0 || system.indexOf("mac") >= 0 || system.indexOf("ipod") >= 0) {
return false;
}
return true;
},
/**
* 黑框提示
*/
toast: function (str) {
if (document.getElementById("blackDiv")) {
document.getElementById("blackSpan").innerHTML = str;
} else {
var blackDiv = document.createElement("div");
blackDiv.id = "blackDiv";
blackDiv.className = "blackts";
blackDiv.style.position = "fixed";
blackDiv.style.left = "0";
blackDiv.style.bottom = "20%";
blackDiv.style.width = "100%";
blackDiv.style.textAlign = "center";
blackDiv.style.zIndex = "999999";
blackDiv.style.display = 'flex'
blackDiv.style.justifyContent = 'center'
var html = '<div id="blackSpan" style="background: rgba(42,45,50,.94);color: white;';
html += 'border-radius: .1rem;font-size: 0.32rem;padding: .2rem .6rem;max-width: 80%;line-height: 1.5;">';
html += str + '</div>';
blackDiv.innerHTML = html;
document.getElementsByTagName("body")[0].appendChild(blackDiv);
}
if (blackId && blackId != "") {
clearTimeout(blackId);
}
blackId = setTimeout(function () {
if (document.getElementById("blackDiv")) {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("blackDiv"));
}
}, 3000);
},
/**
* zhijian/ha
*
*/
httpRequest:function(param){
let middle = param.middleUrl || '/zhijian-trial/ha'
let pa = localStorage.getItem('appLoginInfo')
if(pa){
pa = JSON.parse(pa)
}else{
pa = {}
}
return new Promise(function(resolve, reject){
axios ({
method: 'post',
url: origin + middle + param.url,
timeout: param.time||15000,
data:param.data,
headers: {
'Content-Type': 'application/json',
'x-access-token': pa.tokenValue
}
}).then((res) => {
resolve(res.data)
}).catch(res => {
reject(res)
})
})
},
}
window.publicMethod = utils
})()