weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
104 lines (97 loc) • 3.01 kB
JavaScript
;
import { isWeex, isWeb, appInfo } from 'nuke-env';
let expressionBinding;
try {
expressionBinding = require('@weex-module/expressionBinding');
} catch (err) {
if (isWeex) {
console.warn('[Warning] current env not support expressionBinding');
}
}
// eslint-disable-next-line
let Detection = { ...appInfo };
Detection.isWeex = isWeex;
Detection.isWeb = isWeb;
const appName = appInfo.appName && appInfo.appName.toUpperCase();
if (isWeex) {
const deviceInfo = typeof WXEnvironment !== 'undefined' ? WXEnvironment : {}; // eslint-disable-line
Detection = Object.assign(Detection, {
Android: appInfo.platform === 'android',
iOS: appInfo.platform === 'iOS',
isAliApp: true,
isTB: appName === 'TB',
isTM: appName === 'TM' || appName === 'TMALL', // 猫客中,appName是tmall
isQN: appName === 'QN',
isLZD: appName === 'LA' || appName === 'LA-ANDROID' || appName === 'LAZADA',
appVersion: appInfo.appVersion,
weexVersion: appInfo.weexVersion,
osVersion: appInfo.osVersion,
});
} else {
const ua = window.navigator.userAgent;
Detection = Object.assign(Detection, {
Android: /Android/gi.test(ua),
iOS: /iPhone|iPad|iPod/gi.test(ua),
isAliApp: /AliApp\([A-Z-_]+\/[0-9.]+\)/gi.test(ua),
isTB: appName === 'TB',
isTM: appName === 'TM' || appName === 'TMALL', // 猫客中,appName是tmall
isQN: appName === 'QN',
isLZD: appName === 'LA' || appName === 'LA-ANDROID' || appName === 'LAZADA',
appVersion: appInfo.appVersion,
});
}
/**
* @param {object} params params.iosVer params.andVer params.isCheckOS
* isCheckOS 是否判断系统版本。默认为false,判断app版本
* iosVer iOS判断基础版本
* andVer android判断基础版本
*/
Detection.gt = (version, isCheckOS) => {
if (!isCheckOS && !Detection.appVersion) {
return false;
}
let checkVer = isCheckOS ? Detection.osVersion : Detection.appVersion;
if (checkVer === version) {
return true;
}
if (!version) {
version = '0.0';
}
checkVer = checkVer.split('.');
version = version.split('.');
for (let i = 0; i < checkVer.length; i += 1) {
const len = i + 1;
for (let j = 0; j < len; j += 1) {
const ver1 = +checkVer[j];
const ver2 = version[j];
if (ver1 > ver2) {
return true;
} else if (ver1 < ver2) {
return false;
} else if (
ver1 === ver2 &&
checkVer.length === version.length &&
j === 3
) {
return true;
}
}
}
return false;
};
if (Detection.isWeex) {
// 判断系统版本,用于探测动画
if (Detection.Android) {
// 针对4.3以下版本的android,不使用expressionBinding
Detection.isHighOS = Detection.gt('4.3', true);
}
if (expressionBinding && expressionBinding.enableBinding) {
if (Detection.Android && Detection.isHighOS) {
Detection.epEnable = true;
}
if (Detection.iOS) {
Detection.epEnable = true;
}
}
}
export default Detection;