SystemConfig.js
3.6 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
/*
* 全局数据管理
* */
import Loger from 'Loger';
import mdetect from "mdetect";
import GlobalConfig from 'GlobalConfig';
let loger = Loger.getLoger('SystemConfig');
class SystemConfig {
constructor() {
}
//获取系统信息
static getSystemInfo() {
//检查是否是移动端
GlobalConfig.isMobile = mdetect.isMobileUA();
if (GlobalConfig.isMobile) {
loger.warn("当前设备是移动设备");
GlobalConfig.platform = 3;//移动设备,不是ios和安卓就当H5处理
GlobalConfig.deviceType = 3;
} else {
loger.warn("当前设备是PC");
GlobalConfig.platform = 0
GlobalConfig.deviceType = 0;
}
if (mdetect.isIOS()) {
GlobalConfig.deviceType = 1; //"ios";
}
if (mdetect.isAndroid()) {
GlobalConfig.platform = 2; //"android";
GlobalConfig.deviceType = 2; //"ios";
}
//语言
GlobalConfig.language = "unknown";
if (navigator) {
let language = navigator.language || navigator.browserLanguage;
GlobalConfig.language = language.toLocaleLowerCase();
}
let browserInfo = this.getBrowserInfo();
GlobalConfig.explorer = browserInfo.explorer || "未知";
GlobalConfig.explorerVersion = browserInfo.explorerVersion || "未知";
GlobalConfig.os = this.detectOS();
loger.log("deviceType:" + GlobalConfig.deviceType);
loger.log("language:" + GlobalConfig.language);
loger.log("explorer:" + GlobalConfig.explorer);
loger.log("explorerVersion:" + GlobalConfig.explorerVersion);
loger.log("os:" + GlobalConfig.os);
}
//获取浏览器和信息
static getBrowserInfo() {
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var re = /(trident|msie|firefox|chrome|opera|version).*?([\d.]+)/;
var m = ua.match(re);
if (!m) m = ["version/1.0.0", "version", "1.0.0"];
Sys.explorer = m[1].replace(/version/, "'safari");
//判断是否是IE11
if (Sys.explorer == "trident") {
Sys.explorer = "IE11"
Sys.explorerVersion = "11.0";
} else if (Sys.explorer == "msie") {
//IE
Sys.explorer = "IE"
Sys.explorerVersion = m[2];
} else {
//非IE
Sys.explorerVersion = m[2];
}
return Sys;
}
//系统信息
static detectOS() {
var sUserAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if (isLinux) return "Linux";
if (isWin) {
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Win2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "WinXP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Win2003";
var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "WinVista";
var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Win7";
}
return "other";
}
}
export default SystemConfig;