SystemConfig.js 3.2 KB
/*
 * 全局数据管理
 * */
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("当前设备是移动设备");
    } else {
      loger.warn("当前设备是PC");
    }
    if(mdetect.isIOS()){
      GlobalConfig.deviceType=1;//"ios";
    } if(mdetect.isAndroid()){
      GlobalConfig.platform=2;//"android";
    }else {
      GlobalConfig.platform=0;//"pc";
    }

    //语言
    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);
    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;