判断设备类型
// 这里的判断类型是自己整理的,覆盖面只涵盖我工作领域的
// 可以按需追加
/**
*
* @param {*} UA ,就是userAgent
* @returns type: 设备类型
* env: 访问环境(微信/微博/qq)
* masklayer: 就是给外部拿到判断是否显示遮罩层的,一些特殊环境要引导用户到外部去打开访问
*/
function isWechat (UA) {
return !!/MicroMessenger/i.test(UA)
}
function isWeibo (UA) {
return !!/Weibo/i.test(UA)
}
function isQQ (UA) {
return !!/QQ/i.test(UA)
}
function isMoible (UA) {
return !!/(Android|webOS|iPhone|iPod|tablet|BlackBerry|Mobile)/i.test(UA)
}
function isIOS (UA) {
return !!/iPhone|iPad|iPod/i.test(UA)
}
function isAndroid (UA) {
return !!/Android/i.test(UA)
}
export function deviceType (UA) {
if (isMoible(UA)) {
if (isIOS(UA)) {
if (isWechat(UA)) {
return {
type: 'ios',
env: 'wechat',
masklayer: true
}
}
if (isWeibo(UA)) {
return {
type: 'ios',
env: 'weibo',
masklayer: true
}
}
if (isQQ(UA)) {
return {
type: 'ios',
env: 'qq',
masklayer: true
}
}
return {
type: 'ios'
}
}
if (isAndroid(UA)) {
if (isWechat(UA)) {
return {
type: 'android',
env: 'wechat',
masklayer: true
}
}
if (isWeibo(UA)) {
return {
type: 'android',
env: 'weibo',
masklayer: true
}
}
if (isQQ(UA)) {
return {
type: 'android',
env: 'qq',
masklayer: true
}
}
return {
type: 'android'
}
}
return {
type: 'mobile'
}
} else {
return {
type: 'pc'
}
}
}
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
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
上次更新: 2024/08/17, 20:43:29