提交 35158472 编写于 作者: D DCloud_LXH

chore: systemInfo

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