diff --git a/src/platforms/app-plus/service/api/device/system.js b/src/platforms/app-plus/service/api/device/system.js index 5938c6538fdaaff3b071c354892a1a461bf1fb71..03d5103f94c0e3dfb1a3f5f7ec7ce2a7457d9fa0 100644 --- a/src/platforms/app-plus/service/api/device/system.js +++ b/src/platforms/app-plus/service/api/device/system.js @@ -19,7 +19,7 @@ export function getDeviceInfo () { weexGetSystemInfoSync() const { deviceBrand, deviceModel, osName, - osVersion + osVersion, deviceOrientation, deviceType } = systemInfo const brand = deviceBrand.toLowerCase() @@ -27,6 +27,10 @@ export function getDeviceInfo () { return { deviceBrand: brand, deviceModel, + devicePixelRatio: plus.screen.scale, + deviceId: deviceId(), + deviceOrientation, + deviceType, brand, model: deviceModel, system: `${osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`, @@ -37,7 +41,7 @@ export function getDeviceInfo () { export function getAppBaseInfo () { weexGetSystemInfoSync() const { - hostPackageName, hostName, osLanguage, + hostPackageName, hostName, hostVersion, hostLanguage, hostTheme, appId, appName, appVersion, appVersionCode } = systemInfo @@ -52,7 +56,7 @@ export function getAppBaseInfo () { appVersionCode, appLanguage: uni.getLocale(), version: plus.runtime.innerVersion, - language: osLanguage, + language: hostLanguage, theme: '', hostPackageName, hostName, @@ -71,11 +75,12 @@ export function getSystemInfo () { _initSystemInfo = true weexGetSystemInfoSync() _initSystemInfo = false + const windowInfo = getWindowInfo() const deviceInfo = getDeviceInfo() const appBaseInfo = getAppBaseInfo() _initSystemInfo = true - const { osName, osLanguage, osVersion, pixelRatio } = systemInfo + const { osName, osLanguage, osVersion } = systemInfo const osLanguageSplit = osLanguage.split('-') const osLanguageSplitLast = osLanguageSplit[osLanguageSplit.length - 1] const _osLanguage = `${osLanguageSplit[0]}${osLanguageSplitLast ? '-' + osLanguageSplitLast : ''}` @@ -83,8 +88,6 @@ export function getSystemInfo () { const extraData = { errMsg: 'getSystemInfo:ok', fontSizeSetting: appBaseInfo.hostFontSizeSetting, - devicePixelRatio: pixelRatio, - deviceId: deviceId(), uniCompileVersion: __uniConfig.compilerVersion, uniRuntimeVersion: __uniConfig.compilerVersion, osLanguage: _osLanguage @@ -98,7 +101,7 @@ export function getSystemInfo () { const _systemInfo = Object.assign( {}, systemInfo, - getWindowInfo(), + windowInfo, deviceInfo, appBaseInfo, extraData diff --git a/src/platforms/h5/service/api/device/get-system-info.js b/src/platforms/h5/service/api/device/get-system-info.js index f2fa6b1c571f6c44b5ee3653579dc6fd45a52b81..19e72127ca1c4028b8f8f816cade96dfa87fddfb 100644 --- a/src/platforms/h5/service/api/device/get-system-info.js +++ b/src/platforms/h5/service/api/device/get-system-info.js @@ -18,12 +18,18 @@ export function getDeviceInfo () { brand, model, platform, - system + system, + deviceOrientation, + deviceType } = browserInfo return { deviceBrand, deviceModel, + devicePixelRatio: window.devicePixelRatio, + deviceId: deviceId(), + deviceOrientation, + deviceType, brand, model, system, @@ -73,8 +79,7 @@ export function getSystemInfoSync () { const appBaseInfo = getAppBaseInfo() _initBrowserInfo = true - const { ua, deviceType, browserName, browseVersion, osname, osversion, deviceOrientation } = browserInfo - const { pixelRatio } = windowInfo + const { ua, browserName, browseVersion, osname, osversion } = browserInfo const systemInfo = Object.assign( {}, @@ -83,12 +88,8 @@ export function getSystemInfoSync () { appBaseInfo, { ua, - deviceType, browserName, browseVersion, - deviceId: deviceId(), - devicePixelRatio: pixelRatio, - deviceOrientation, uniPlatform: 'web', uniCompileVersion: __uniConfig.compilerVersion, uniRuntimeVersion: __uniConfig.compilerVersion, diff --git a/src/platforms/mp-weixin/helpers/enhance-system-info.js b/src/platforms/mp-weixin/helpers/enhance-system-info.js index d85000eb50caa27471bdf889123b0e21d7611413..8fb388ac18a770e3a4d23378f56fe0f454713540 100644 --- a/src/platforms/mp-weixin/helpers/enhance-system-info.js +++ b/src/platforms/mp-weixin/helpers/enhance-system-info.js @@ -1,6 +1,7 @@ -function getDeviceBrand (model) { +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 '' } const UUID_KEY = '__DC_STAT_UUID' @@ -31,8 +32,8 @@ export function addSafeAreaInsets (result) { export function populateParameters (result) { const { - brand, model, system, - language, theme, version, + brand = '', model = '', system = '', + language = '', theme, version, hostName, platform, fontSizeSetting, SDKVersion, pixelRatio, deviceOrientation, environment @@ -59,38 +60,17 @@ export function populateParameters (result) { } // deviceType - let deviceType = result.deviceType || 'phone' - if (__PLATFORM__ !== 'mp-baidu') { - const deviceTypeMaps = { - ipad: 'pad', - windows: 'pc', - mac: 'pc' - } - const deviceTypeMapsKeys = Object.keys(deviceTypeMaps) - const _model = model.toLocaleLowerCase() - for (let index = 0; index < deviceTypeMapsKeys.length; index++) { - const _m = deviceTypeMapsKeys[index] - if (_model.indexOf(_m) !== -1) { - deviceType = deviceTypeMaps[_m] - break - } - } - } + const deviceType = getGetDeviceType(result, model) // deviceModel - let deviceBrand = model.split(' ')[0].toLocaleLowerCase() - if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark' || isQuickApp) { - deviceBrand = brand.toLocaleLowerCase() - } else { - deviceBrand = getDeviceBrand(deviceBrand) - } + const deviceBrand = getDeviceBrand(brand, model, isQuickApp) // hostName let _hostName = hostName || __PLATFORM__.split('-')[1] // mp-jd if (__PLATFORM__ === 'mp-weixin') { if (environment) { _hostName = environment - } else if (result.host) { + } else if (result.host && result.host.env) { _hostName = result.host.env } } @@ -130,7 +110,7 @@ export function populateParameters (result) { osVersion, hostTheme: theme, hostVersion, - hostLanguage: language.split('_', '-'), + hostLanguage: language.replace('_', '-'), hostName: _hostName, hostSDKVersion: _SDKVersion, hostFontSizeSetting: fontSizeSetting, @@ -147,3 +127,42 @@ export function populateParameters (result) { Object.assign(result, parameters) } + +export function getGetDeviceType (result, model) { + let deviceType = result.deviceType || 'phone' + if (__PLATFORM__ !== 'mp-baidu') { + const deviceTypeMaps = { + ipad: 'pad', + windows: 'pc', + mac: 'pc' + } + const deviceTypeMapsKeys = Object.keys(deviceTypeMaps) + const _model = model.toLocaleLowerCase() + for (let index = 0; index < deviceTypeMapsKeys.length; index++) { + const _m = deviceTypeMapsKeys[index] + if (_model.indexOf(_m) !== -1) { + deviceType = deviceTypeMaps[_m] + break + } + } + } + return deviceType +} + +export function getDeviceBrand ( + brand, + model, + isQuickApp = false +) { + let deviceBrand = model.split(' ')[0].toLocaleLowerCase() + if ( + __PLATFORM__ === 'mp-toutiao' || + __PLATFORM__ === 'mp-lark' || + isQuickApp + ) { + deviceBrand = brand.toLocaleLowerCase() + } else { + deviceBrand = _getDeviceBrand(deviceBrand) + } + return deviceBrand +} diff --git a/src/platforms/mp-weixin/helpers/get-app-base-info.js b/src/platforms/mp-weixin/helpers/get-app-base-info.js new file mode 100644 index 0000000000000000000000000000000000000000..cc3abbdec9c2f345f5da4ec393138c975beb30d8 --- /dev/null +++ b/src/platforms/mp-weixin/helpers/get-app-base-info.js @@ -0,0 +1,24 @@ +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 + } + } + + Object.assign(result, { + hostVersion: version, + hostLanguage: language.replace('_', '-'), + hostName: _hostName, + hostSDKVersion: SDKVersion, + hostTheme: theme, + 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 + }) + } +} diff --git a/src/platforms/mp-weixin/helpers/get-device-info.js b/src/platforms/mp-weixin/helpers/get-device-info.js new file mode 100644 index 0000000000000000000000000000000000000000..96ee3b92bf48b9623af6efd3a1576b1be1d86c95 --- /dev/null +++ b/src/platforms/mp-weixin/helpers/get-device-info.js @@ -0,0 +1,16 @@ +import { useDeviceId, getGetDeviceType, getDeviceBrand } from './enhance-system-info' + +export default { + returnValue: function (result) { + const { brand, model } = result + const deviceType = getGetDeviceType(result, model) + const deviceBrand = getDeviceBrand(brand, model) + useDeviceId(result) + + Object.assign(result, { + deviceType, + deviceBrand, + deviceModel: model + }) + } +} diff --git a/src/platforms/mp-weixin/helpers/get-window-info.js b/src/platforms/mp-weixin/helpers/get-window-info.js new file mode 100644 index 0000000000000000000000000000000000000000..bda0ccb1c1515212598f59f689dbedbc91c5ad58 --- /dev/null +++ b/src/platforms/mp-weixin/helpers/get-window-info.js @@ -0,0 +1,12 @@ +import { addSafeAreaInsets } from './enhance-system-info' + +export default { + returnValue: function (result) { + addSafeAreaInsets(result) + + Object.assign(result, { + windowTop: 0, + windowBottom: 0 + }) + } +} diff --git a/src/platforms/mp-weixin/runtime/api/protocols.js b/src/platforms/mp-weixin/runtime/api/protocols.js index b9de8c7227368440c3079d992b0699959d106979..c610422607eff5934ea4817c985d5c3678851311 100644 --- a/src/platforms/mp-weixin/runtime/api/protocols.js +++ b/src/platforms/mp-weixin/runtime/api/protocols.js @@ -3,6 +3,9 @@ import redirectTo from '../../helpers/redirect-to' import previewImage from '../../helpers/normalize-preview-image' import getSystemInfo from '../../helpers/system-info' import showActionSheet from '../../helpers/show-action-sheet' +import getAppBaseInfo from '../../helpers/get-app-base-info' +import getDeviceInfo from '../../helpers/get-device-info' +import getWindowInfo from '../../helpers/get-window-info' export const protocols = { redirectTo, @@ -10,7 +13,10 @@ export const protocols = { previewImage, getSystemInfo, getSystemInfoSync: getSystemInfo, - showActionSheet + showActionSheet, + getAppBaseInfo, + getDeviceInfo, + getWindowInfo } export const todos = [ 'vibrate',