ann0707
2018-08-16 c9bc8ec61cff4076132f6396d99d383a2cdf5a03
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
/**
 * Created by c.k on 2017/11/10.
 *  获取客户端本地设备信息和渠道编号
 */
 
 
export default {
  saveDeviceInfo (deviceInfo) {
    // 外链默认解析地址里面的chanNo,app时解析原生回传的chanNo
    //   alert(deviceInfo);
    deviceInfo = JSON.parse(deviceInfo) ;
    if (deviceInfo && deviceInfo.childChan) {
      deviceInfo.isApp = "1";
    }
      let configInfo = window.localStorage.getItem('newClientInfo');
      if(configInfo){
          configInfo = JSON.parse(configInfo);
          for (let key in deviceInfo) {
              configInfo[key] = deviceInfo[key];
          }
          configInfo.ostype = '03';
 
          window.localStorage.setItem ('newClientInfo', JSON.stringify (configInfo));
      }
    deviceInfo = JSON.stringify(deviceInfo);
    window.localStorage.setItem('deviceInfo', deviceInfo);
  },
  // 获取本地存储的设备信息
  fetchDeviceInfo() {
    return window.localStorage.getItem('deviceInfo');
  },
  // 获取设备类型
  getDeviceType() {
    let browser = {
      versions() {
        let u = navigator.userAgent;
        return {
          trident: u.indexOf('Trident') > -1, // IE内核
          presto: u.indexOf('Presto') > -1, // opera内核
          webKit: u.indexOf('AppleWebKit') > -1, // 苹果、谷歌内核
          gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') === -1, // 火狐内核
          mobile: !!u.match(/AppleWebKit.*Mobile.*/), // 是否为移动终端
          ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), // ios终端
          android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, // android终端或者uc浏览器
          iPhone: u.indexOf('iPhone') > -1, // 是否为iPhone或者QQHD浏览器
          iPad: u.indexOf('iPad') > -1, // 是否iPad
          webApp: u.indexOf('Safari') === -1, // 是否web应该程序,没有头部与底部
          weixin: u.indexOf('MicroMessenger') > -1, // 是否微信 (2015-01-22新增)
          qq: u.match(/\sQQ/i) === 'qq' // 是否QQ
        }
      },
      language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };
      var u = navigator.userAgent;
      var device =""; //当前设备信息
      if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
          device = "Android";
          return 'Android';
      } else if (u.indexOf('iPhone') > -1) {//苹果手机
          device = "IOS";
          return 'IOS';
      } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
          device = "WindowsPhone";
          return 'WindowsPhone';
      }else if(u.indexOf('MicroMessenger') > -1){
          device = "weixin";
          return 'weixin';
      }
//    let type = browser.versions();
//    if (type.android) {
//      return 'Android'
//    } else if (type.ios || type.iPhone || type.iPad) {
//      return 'IOS'
//    } else if (type.weixin) {
//      return 'weixin'
//    } else {
//      return 'other'
//    }
  }
}