diff --git a/src/platforms/app-plus/service/api/device/system.js b/src/platforms/app-plus/service/api/device/system.js index 0941fb848d9d5a8914385114354d5f9025730816..03d5103f94c0e3dfb1a3f5f7ec7ce2a7457d9fa0 100644 --- a/src/platforms/app-plus/service/api/device/system.js +++ b/src/platforms/app-plus/service/api/device/system.js @@ -41,7 +41,7 @@ export function getDeviceInfo () { export function getAppBaseInfo () { weexGetSystemInfoSync() const { - hostPackageName, hostName, osLanguage, + hostPackageName, hostName, hostVersion, hostLanguage, hostTheme, appId, appName, appVersion, appVersionCode } = systemInfo @@ -56,7 +56,7 @@ export function getAppBaseInfo () { appVersionCode, appLanguage: uni.getLocale(), version: plus.runtime.innerVersion, - language: osLanguage, + language: hostLanguage, theme: '', hostPackageName, hostName, diff --git a/src/platforms/mp-weixin/helpers/enhance-system-info.js b/src/platforms/mp-weixin/helpers/enhance-system-info.js index 7b7e43bae5bfdf3cde7040a93f6f8210fea49701..aad2479bee8fb39589d46cb6dec9c7e6626eed28 100644 --- a/src/platforms/mp-weixin/helpers/enhance-system-info.js +++ b/src/platforms/mp-weixin/helpers/enhance-system-info.js @@ -1,11 +1,12 @@ -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' let deviceId -export function useDeviceId (result) { +export function useDeviceId(result) { deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY) if (!deviceId) { deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7) @@ -17,7 +18,7 @@ export function useDeviceId (result) { result.deviceId = deviceId } -export function addSafeAreaInsets (result) { +export function addSafeAreaInsets(result) { if (result.safeArea) { const safeArea = result.safeArea result.safeAreaInsets = { @@ -29,7 +30,7 @@ export function addSafeAreaInsets (result) { } } -export function populateParameters (result) { +export function populateParameters(result) { const { brand, model, system, language, theme, version, @@ -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 - } - } - } + let 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) - } + let 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 && fromRes.host.env) { _hostName = result.host.env } } @@ -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 +} \ No newline at end of file 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..da507ed5b37669d70273499e9718d9ff0662bb8b --- /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..efdc5f70e75a18ecce348f60e3e7d2baca7fb953 --- /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 + let deviceType = getGetDeviceType(result, model) + let 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..9c850d1761dd64ee84e912432187861852efba96 --- /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',