提交 35158472 编写于 作者: D DCloud_LXH

chore: systemInfo

上级 312eb5a7
import {
callApiSync
} from '../util'
import { callApiSync } from '../util'
import { getWindowInfo } from './get-window-info'
import deviceId from 'uni-platform/helpers/uuid'
import { sortObject } from 'uni-shared'
let systemInfo = {}
let _initSystemInfo = true
......@@ -26,16 +23,16 @@ export function getDeviceInfo () {
const _osName = osName.toLowerCase()
return {
brand,
deviceBrand: brand,
deviceModel,
devicePixelRatio: plus.screen.scale,
deviceId: deviceId(),
deviceOrientation,
deviceType,
brand,
model: deviceModel,
system: `${_osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`,
platform: _osName
platform: _osName,
system: `${_osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`
}
}
......@@ -54,23 +51,23 @@ export function getAppBaseInfo () {
: hostLanguage
return {
SDKVersion: '',
hostSDKVersion: '',
enableDebug: false,
appId,
appName,
appVersion,
appVersionCode,
appLanguage,
version: plus.runtime.innerVersion,
language: osLanguage,
theme: '',
enableDebug: false,
hostSDKVersion: undefined,
hostPackageName,
hostName,
hostVersion,
hostLanguage,
hostTheme,
hostFontSizeSetting: undefined
hostFontSizeSetting: undefined,
language: osLanguage,
SDKVersion: '',
theme: undefined,
version: plus.runtime.innerVersion
}
}
......@@ -87,24 +84,14 @@ export function getSystemInfo () {
const appBaseInfo = getAppBaseInfo()
_initSystemInfo = true
const { osName, osLanguage, osVersion } = systemInfo
const _osName = osName.toLowerCase()
const osLanguageSplit = osLanguage.split('-')
const osLanguageSplitLast = osLanguageSplit[osLanguageSplit.length - 1]
const _osLanguage = `${osLanguageSplit[0]}${osLanguageSplitLast ? '-' + osLanguageSplitLast : ''}`
const extraData = {
errMsg: 'getSystemInfo:ok',
fontSizeSetting: appBaseInfo.hostFontSizeSetting,
uniCompileVersion: __uniConfig.compilerVersion,
uniRuntimeVersion: __uniConfig.compilerVersion,
osLanguage: _osLanguage,
osName: _osName
osName: systemInfo.osName.toLowerCase()
}
if (_osName === 'ios') {
extraData.romName = _osName
extraData.romVersion = osVersion
if (systemInfo.hostName) {
extraData.hostSDKVersion = systemInfo.uniRuntimeVersion
}
const _systemInfo = Object.assign(
......@@ -120,5 +107,5 @@ export function getSystemInfo () {
delete _systemInfo.enableDebug
delete _systemInfo.theme
return _systemInfo
return sortObject(_systemInfo)
}
......@@ -21,11 +21,6 @@ function IEVersion () {
}
}
function getDeviceBrand (model) {
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' }
if (/windows/gi.test(model)) { return 'microsoft' }
}
const ua = navigator.userAgent
/**
* 是否安卓设备
......@@ -165,15 +160,15 @@ export function getBrowserInfo () {
} else {
osname = 'Other'
osversion = '0'
deviceType = 'other'
deviceType = 'unknown'
}
var system = `${osname} ${osversion}`
var platform = osname.toLocaleLowerCase()
let browserName = ''
let browseVersion = String(IEVersion())
if (browseVersion !== '-1') { browserName = 'IE' } else {
let browserVersion = String(IEVersion())
if (browserVersion !== '-1') { browserName = 'IE' } else {
const browseVendors = ['Version', 'Firefox', 'Chrome', 'Edge{0,1}']
const vendors = ['Safari', 'Firefox', 'Chrome', 'Edge']
for (let index = 0; index < browseVendors.length; index++) {
......@@ -181,40 +176,31 @@ export function getBrowserInfo () {
const reg = new RegExp(`(${vendor})/(\\S*)\\b`)
if (reg.test(ua)) {
browserName = vendors[index]
browseVersion = ua.match(reg)[2]
browserVersion = ua.match(reg)[2]
}
}
}
// deviceBrand
let deviceBrand = ''
if (model) {
const _model = model.toLocaleLowerCase()
deviceBrand = getDeviceBrand(_model) ||
getDeviceBrand(osname.toLocaleLowerCase()) ||
_model.split(' ')[0]
}
// deviceOrientation
let deviceOrientation = 'portrait'
const orientation = typeof window.screen.orientation === 'undefined' ? window.orientation : window.screen.orientation.angle
deviceOrientation = Math.abs(orientation) === 90 ? 'landscape' : 'portrait'
return {
deviceBrand,
deviceBrand: undefined,
brand: undefined,
deviceModel: model,
deviceOrientation,
brand: deviceBrand,
model,
system,
platform,
browserName: browserName.toLocaleLowerCase(),
browseVersion,
browserVersion,
language,
deviceType,
ua,
osname,
osversion,
theme: ''
theme: undefined
}
}
import { getWindowInfo } from './get-window-info'
import deviceId from 'uni-platform/helpers/uuid'
import { getBrowserInfo } from '../base/get-browser-info'
import { sortObject } from 'uni-shared'
let browserInfo = {}
let _initBrowserInfo = true
......@@ -24,27 +25,22 @@ export function getDeviceInfo () {
} = browserInfo
return {
brand,
deviceBrand,
deviceModel,
devicePixelRatio: window.devicePixelRatio,
deviceId: deviceId(),
deviceOrientation,
deviceType,
brand,
model,
system,
platform
platform,
system
}
}
export function getAppBaseInfo () {
initBrowserInfo()
const {
theme,
browserName,
browseVersion,
language
} = browserInfo
const { theme, language } = browserInfo
const appLanguage = uni
? uni.getLocale
......@@ -53,23 +49,23 @@ export function getAppBaseInfo () {
: language
return {
SDKVersion: '',
hostSDKVersion: '',
enableDebug: false,
hostPackageName: '',
hostFontSizeSetting: undefined,
language,
hostName: browserName,
hostVersion: browseVersion,
hostTheme: theme,
hostLanguage: language,
theme,
appId: __uniConfig.appId,
appName: __uniConfig.appName,
appVersion: __uniConfig.appVersion,
appVersionCode: __uniConfig.appVersionCode,
appLanguage,
version: __uniConfig.appVersion
enableDebug: false,
hostSDKVersion: undefined,
hostPackageName: undefined,
hostFontSizeSetting: undefined,
hostName: undefined,
hostVersion: undefined,
hostTheme: undefined,
hostLanguage: undefined,
language,
SDKVersion: '',
theme,
version: ''
}
}
......@@ -85,7 +81,7 @@ export function getSystemInfoSync () {
const appBaseInfo = getAppBaseInfo()
_initBrowserInfo = true
const { ua, browserName, browseVersion, osname, osversion } = browserInfo
const { ua, browserName, browserVersion, osname, osversion } = browserInfo
const systemInfo = Object.assign(
{},
......@@ -93,17 +89,17 @@ export function getSystemInfoSync () {
deviceInfo,
appBaseInfo,
{
ua,
browserName,
browseVersion,
uniPlatform: 'web',
uniCompileVersion: __uniConfig.compilerVersion,
uniRuntimeVersion: __uniConfig.compilerVersion,
browserVersion,
fontSizeSetting: appBaseInfo.hostFontSizeSetting,
osName: osname.toLocaleLowerCase(),
osVersion: osversion,
osLanguage: undefined,
osTheme: undefined
osTheme: undefined,
uniPlatform: 'web',
uniCompileVersion: __uniConfig.compilerVersion,
uniRuntimeVersion: __uniConfig.compilerVersion,
ua
}
)
......@@ -111,7 +107,7 @@ export function getSystemInfoSync () {
delete systemInfo.enableDebug
delete systemInfo.theme
return systemInfo
return sortObject(systemInfo)
}
/**
* 获取系统信息-异步
......
function _getDeviceBrand (model) {
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' }
if (/windows/gi.test(model)) { return 'microsoft' }
return ''
}
import { getLocale } from 'uni-core/runtime/locale'
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
......@@ -34,11 +30,10 @@ export function populateParameters (result) {
const {
brand = '', model = '', system = '',
language = '', theme, version,
hostName, platform, fontSizeSetting,
SDKVersion, pixelRatio, deviceOrientation,
environment
platform, fontSizeSetting,
SDKVersion, pixelRatio, deviceOrientation
} = result
const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1
// const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1
// osName osVersion
let osName = ''
......@@ -63,22 +58,10 @@ export function populateParameters (result) {
const deviceType = getGetDeviceType(result, model)
// deviceModel
const deviceBrand = getDeviceBrand(brand, model, isQuickApp)
const deviceBrand = getDeviceBrand(brand)
// hostName
const _platform = __PLATFORM__ === 'mp-weixin' ? 'WeChat' : __PLATFORM__.split('-')[1]
let _hostName = hostName || _platform // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (environment) {
_hostName = environment
} else if (result.host && result.host.env) {
_hostName = result.host.env
}
}
if (__PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-kuaishou') { _hostName = result.host }
if (__PLATFORM__ === 'mp-qq') _hostName = result.AppPlatform
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') { _hostName = result.appName }
if (__PLATFORM__ === 'mp-alipay') _hostName = result.app
const _hostName = getHostName(result)
// deviceOrientation
let _deviceOrientation = deviceOrientation // 仅 微信 百度 支持
......@@ -92,6 +75,9 @@ export function populateParameters (result) {
let _SDKVersion = SDKVersion
if (__PLATFORM__ === 'mp-alipay') { _SDKVersion = my.SDKVersion }
// hostLanguage
const hostLanguage = language.replace(/_/g, '-')
// wx.getAccountInfoSync
const parameters = {
......@@ -99,6 +85,7 @@ export function populateParameters (result) {
appName: process.env.UNI_APP_NAME,
appVersion: process.env.UNI_APP_VERSION_NAME,
appVersionCode: process.env.UNI_APP_VERSION_CODE,
appLanguage: getAppLanguage(hostLanguage),
uniCompileVersion: process.env.UNI_COMPILER_VERSION,
uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
uniPlatform: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM,
......@@ -111,7 +98,7 @@ export function populateParameters (result) {
osVersion,
hostTheme: theme,
hostVersion,
hostLanguage: language.replace('_', '-'),
hostLanguage,
hostName: _hostName,
hostSDKVersion: _SDKVersion,
hostFontSizeSetting: fontSizeSetting,
......@@ -123,7 +110,7 @@ export function populateParameters (result) {
ua: undefined,
hostPackageName: undefined,
browserName: undefined,
browseVersion: undefined
browserVersion: undefined
}
Object.assign(result, parameters)
......@@ -150,20 +137,34 @@ export function getGetDeviceType (result, model) {
return deviceType
}
export function getDeviceBrand (
brand,
model,
isQuickApp = false
) {
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (
__PLATFORM__ === 'mp-toutiao' ||
__PLATFORM__ === 'mp-lark' ||
isQuickApp
) {
export function getDeviceBrand (brand) {
let deviceBrand = brand
if (deviceBrand) {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = _getDeviceBrand(deviceBrand)
}
return deviceBrand
}
export function getAppLanguage (defaultLanguage) {
return getLocale
? getLocale()
: defaultLanguage
}
export function getHostName (result) {
const _platform = __PLATFORM__ === 'mp-weixin' ? 'WeChat' : __PLATFORM__.split('-')[1]
let _hostName = result.hostName || _platform // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (result.environment) {
_hostName = result.environment
} else if (result.host && result.host.env) {
_hostName = result.host.env
}
}
if (__PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-kuaishou') { _hostName = result.host }
if (__PLATFORM__ === 'mp-qq') _hostName = result.AppPlatform
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') { _hostName = result.appName }
if (__PLATFORM__ === 'mp-alipay') _hostName = result.app
return _hostName
}
import { getAppLanguage, getHostName } from './enhance-system-info'
import { sortObject } from 'uni-shared'
export default {
returnValue: function (result) {
const { version, language, SDKVersion, theme } = result
let _hostName = __PLATFORM__.split('-')[1] // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (result.host && result.host.env) {
_hostName = result.host.env
}
}
const _hostName = getHostName(result)
Object.assign(result, {
hostVersion: version,
hostLanguage: language.replace('_', '-'),
hostName: _hostName,
hostSDKVersion: SDKVersion,
hostTheme: theme,
const hostLanguage = language.replace('_', '-')
result = sortObject(Object.assign(result, {
appId: process.env.UNI_APP_ID,
appName: process.env.UNI_APP_NAME,
appVersion: process.env.UNI_APP_VERSION_NAME,
appVersionCode: process.env.UNI_APP_VERSION_CODE
})
appVersionCode: process.env.UNI_APP_VERSION_CODE,
appLanguage: getAppLanguage(hostLanguage),
hostVersion: version,
hostLanguage,
hostName: _hostName,
hostSDKVersion: SDKVersion,
hostTheme: theme
}))
}
}
import { useDeviceId, getGetDeviceType, getDeviceBrand } from './enhance-system-info'
import { sortObject } from 'uni-shared'
export default {
returnValue: function (result) {
const { brand, model } = result
const deviceType = getGetDeviceType(result, model)
const deviceBrand = getDeviceBrand(brand, model)
const deviceBrand = getDeviceBrand(brand)
useDeviceId(result)
Object.assign(result, {
result = sortObject(Object.assign(result, {
deviceType,
deviceBrand,
deviceModel: model
})
}))
}
}
import { addSafeAreaInsets } from './enhance-system-info'
import { sortObject } from 'uni-shared'
export default {
returnValue: function (result) {
addSafeAreaInsets(result)
Object.assign(result, {
result = sortObject(Object.assign(result, {
windowTop: 0,
windowBottom: 0
})
}))
}
}
......@@ -25,7 +25,7 @@ export function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
export function noop () {}
export function noop () { }
export function toRawType (val) {
return _toString.call(val).slice(8, -1)
......@@ -195,3 +195,13 @@ export function deepClone (vnodes, createElement) {
}
export * from './uni-id-mixin'
export function sortObject (obj) {
const sortObj = {}
if (isPlainObject(obj)) {
Object.keys(obj).sort().forEach(key => {
sortObj[key] = obj[key]
})
}
return !Object.keys(sortObj) ? obj : sortObj
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册