Skip to content

Commit fa347d0

Browse files
JingyuanZhangallen-zh
authored andcommitted
fix(systeminfo): fix UC bug becauseOf its unusual userAgent
1 parent 533343e commit fa347d0

File tree

1 file changed

+19
-15
lines changed
  • packages/mars-api/api/system

1 file changed

+19
-15
lines changed

packages/mars-api/api/system/info.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,52 @@ function getSystemInfoSync() {
1212
const ua = userAgent.toLowerCase();
1313
let isIos = false;
1414
let isAndroid = false;
15-
let system = undefined;
16-
let platform = undefined;
17-
let model = undefined;
18-
const screenHeight = document.documentElement.clientHeight;
19-
const screenWidth = document.documentElement.clientWidth;
20-
const windowWidth = screenWidth;
21-
const windowHeight = screenHeight - NAVIGATION_BAR_HEIGHT;
15+
let system = '';
16+
let platform = '';
17+
let model = '';
18+
const screenHeight = window.screen.height;
19+
const screenWidth = window.screen.width;
20+
const windowWidth = document.documentElement.clientWidth;
21+
const windowHeight = document.documentElement.clientHeight - NAVIGATION_BAR_HEIGHT;
2222

2323
if (userAgent.indexOf('Mac OS') > -1 || userAgent.indexOf('iPhone OS') > -1) {
2424
isIos = true;
2525
}
2626
else if (userAgent.indexOf('Android') > -1) {
2727
isAndroid = true;
2828
}
29+
// 兼容UC浏览器 UA
30+
else if (userAgent.indexOf('iPhone') === -1 && userAgent.indexOf('UCBrowser') > -1) {
31+
isAndroid = true;
32+
}
2933

3034
if (isIos) {
3135
let match = userAgent.match('iPhone OS ([0-9,_]*) ');
3236
system = match && match[1] && `iOS ${match[1].replace(/_/g, '.')}` || undefined;
3337
platform = 'ios';
3438

3539
if (screenHeight === 736 && screenWidth === 414) {
36-
model = 'iPhone6P, iPhone7P, iPhone8P';
37-
}
38-
else if (screenHeight === 812 && screenWidth === 375) {
39-
model = 'iPhoneX';
40+
model = 'iPhone 6 Plus, iPhone 7 Plus, iPhone 8 Plus';
4041
}
4142
else if (screenHeight === 667 && screenWidth === 375) {
42-
model = 'iPhone6, iPhone7, iPhone8';
43+
model = 'iPhone 6, iPhone 7, iPhone 8';
44+
}
45+
else if (screenHeight >= 812 && screenWidth >= 375) {
46+
model = 'iPhone X';
4347
}
4448
else if (screenWidth > 320) {
4549
model = 'iPhone';
4650
}
4751
else if (screenHeight === 568 && screenWidth === 320) {
48-
model = 'iPhone5, iPhoneSE, iPhone5s';
52+
model = 'iPhone 5, iPhone SE, iPhone 5s';
4953
}
5054
else {
51-
model = 'iPhone4s, iPhone4';
55+
model = 'iPhone 4s, iPhone 4';
5256
}
5357
}
5458
else if (isAndroid) {
5559
let match = userAgent.match('Android ([0-9,.]*)');
56-
system = match && match[0] || undefined;
60+
system = match && match[0] || 'Android';
5761
platform = 'android';
5862
const buildIndex = ua.indexOf('build');
5963
const fullResult = userAgent.substring(0, buildIndex);

0 commit comments

Comments
 (0)