|
5 | 5 |
|
6 | 6 | import {callback} from '../utils';
|
7 | 7 |
|
| 8 | +const NAVIGATION_BAR_HEIGHT = 38; |
| 9 | + |
8 | 10 | function getSystemInfoSync() {
|
| 11 | + const userAgent = window.navigator.userAgent; |
| 12 | + const ua = userAgent.toLowerCase(); |
| 13 | + let isIos = false; |
| 14 | + 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; |
| 22 | + |
| 23 | + if (userAgent.indexOf('Mac OS') > -1 || userAgent.indexOf('iPhone OS') > -1) { |
| 24 | + isIos = true; |
| 25 | + } |
| 26 | + else if (userAgent.indexOf('Android') > -1) { |
| 27 | + isAndroid = true; |
| 28 | + } |
| 29 | + |
| 30 | + if (isIos) { |
| 31 | + let match = userAgent.match('iPhone OS ([0-9,_]*) '); |
| 32 | + system = match && match[1] && `iOS ${match[1].replace(/_/g, '.')}` || undefined; |
| 33 | + platform = 'ios'; |
| 34 | + |
| 35 | + if (screenHeight === 736 && screenWidth === 414) { |
| 36 | + model = 'iPhone6P, iPhone7P, iPhone8P'; |
| 37 | + } |
| 38 | + else if (screenHeight === 812 && screenWidth === 375) { |
| 39 | + model = 'iPhoneX'; |
| 40 | + } |
| 41 | + else if (screenHeight === 667 && screenWidth === 375) { |
| 42 | + model = 'iPhone6, iPhone7, iPhone8'; |
| 43 | + } |
| 44 | + else if (screenWidth > 320) { |
| 45 | + model = 'iPhone'; |
| 46 | + } |
| 47 | + else if (screenHeight === 568 && screenWidth === 320) { |
| 48 | + model = 'iPhone5, iPhoneSE, iPhone5s'; |
| 49 | + } |
| 50 | + else { |
| 51 | + model = 'iPhone4s, iPhone4'; |
| 52 | + } |
| 53 | + } |
| 54 | + else if (isAndroid) { |
| 55 | + let match = userAgent.match('Android ([0-9,.]*)'); |
| 56 | + system = match && match[0] || undefined; |
| 57 | + platform = 'android'; |
| 58 | + const buildIndex = ua.indexOf('build'); |
| 59 | + const fullResult = userAgent.substring(0, buildIndex); |
| 60 | + const fullArr = fullResult.split(';'); |
| 61 | + model = fullArr[fullArr.length - 1].trim(); |
| 62 | + } |
9 | 63 |
|
10 | 64 | const info = {
|
11 |
| - system: navigator.userAgent, |
12 |
| - screenWidth: document.body.clientWidth, |
13 |
| - windowWidth: document.body.clientWidth |
| 65 | + system, |
| 66 | + platform, |
| 67 | + model, |
| 68 | + screenWidth, |
| 69 | + screenHeight, |
| 70 | + windowWidth, |
| 71 | + windowHeight, |
| 72 | + pixelRatio: window.devicePixelRatio, |
| 73 | + language: navigator.language |
14 | 74 | };
|
15 | 75 |
|
16 | 76 | return info;
|
|
0 commit comments