/**
|
* 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'
|
// }
|
}
|
}
|