os.js
1.44 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
/**
* 加入系统判断功能
*/
export default function osMixin(hybrid) {
const hybridJs = hybrid;
const detect = function detect(ua) {
this.os = {};
const android = ua.match(/(Android);?[\s/]+([\d.]+)?/);
if (android) {
this.os.android = true;
this.os.version = android[2];
this.os.isBadAndroid = !(/Chrome\/\d/.test(window.navigator.appVersion));
}
const iphone = ua.match(/(iPhone\sOS)\s([\d_]+)/);
if (iphone) {
this.os.ios = true;
this.os.iphone = true;
this.os.version = iphone[2].replace(/_/g, '.');
}
const ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
if (ipad) {
this.os.ios = true;
this.os.ipad = true;
this.os.version = ipad[2].replace(/_/g, '.');
}
// quickhybrid的容器
const quick = ua.match(/QuickHybrid/i);
if (quick) {
this.os.quick = true;
}
// epoint的容器
const ejs = ua.match(/EpointEJS/i);
if (ejs) {
this.os.ejs = true;
}
const dd = ua.match(/DingTalk/i);
if (dd) {
this.os.dd = true;
}
// 如果ejs和钉钉以及quick都不是,则默认为h5
if (!ejs && !dd && !quick) {
this.os.h5 = true;
}
};
detect.call(hybridJs, navigator.userAgent);
}